directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: [DIRKRB-299]-Implementing DirectoryLdapIdentityBackend. Contributed by Yaning.
Date Tue, 30 Jun 2015 02:39:17 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 24467847b -> 22d959b95


[DIRKRB-299]-Implementing DirectoryLdapIdentityBackend. Contributed by Yaning.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/22d959b9
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/22d959b9
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/22d959b9

Branch: refs/heads/master
Commit: 22d959b95cd18e2b3beddbca4da37273d033f393
Parents: 2446784
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Tue Jun 30 10:44:34 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Tue Jun 30 10:44:34 2015 +0800

----------------------------------------------------------------------
 .../identitybackend/LdapIdentityBackend.java    |  12 +-
 .../DirectoryLdapIdentityBackendTest.java       | 112 +++++++++++++++++++
 2 files changed, 121 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/22d959b9/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
index e658c16..2ac3b05 100644
--- a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
+++ b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.ldap.model.name.Rdn;
 import org.apache.directory.api.util.GeneralizedTime;
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.shared.kerberos.KerberosAttribute;
 import org.apache.kerby.config.Config;
@@ -52,7 +53,7 @@ import java.util.Map;
  *
  */
 public class LdapIdentityBackend extends AbstractIdentityBackend {
-    private LdapNetworkConnection connection;
+    private LdapConnection connection;
 
     public LdapIdentityBackend() {
 
@@ -65,11 +66,16 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
      */
     public LdapIdentityBackend(Config config) {
         setConfig(config);
+        this.connection = new LdapNetworkConnection(getConfig().getString("host"),
+                getConfig().getInt("port"));
+    }
+
+    public LdapIdentityBackend(Config config, LdapConnection connection) throws LdapException
{
+        setConfig(config);
+        this.connection = connection;
     }
 
     public void startConnection() throws LdapException {
-        this.connection = new LdapNetworkConnection(getConfig().getString("host"),
-                getConfig().getInt("port"));
         connection.bind(getConfig().getString("admin_dn"),
                 getConfig().getString("admin_pw"));
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/22d959b9/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/DirectoryLdapIdentityBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/DirectoryLdapIdentityBackendTest.java
b/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/DirectoryLdapIdentityBackendTest.java
new file mode 100644
index 0000000..786ad27
--- /dev/null
+++ b/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/DirectoryLdapIdentityBackendTest.java
@@ -0,0 +1,112 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.identity.backend;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
+import org.apache.directory.server.core.annotations.CreateDS;
+import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.api.LdapCoreSessionConnection;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.kerby.config.Conf;
+import org.apache.kerby.kerberos.kdc.identitybackend.LdapIdentityBackend;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(FrameworkRunner.class)
+@CreateDS(name = "KerberosKRBProtocolTest-class",
+        partitions =
+                {
+                        @CreatePartition(
+                                name = "example",
+                                suffix = "dc=example,dc=com")
+                })
+@CreateLdapServer(
+        transports =
+                {
+                        @CreateTransport(protocol = "LDAP")
+                })
+@ApplyLdifs(
+        {
+                "dn: dc=example,dc=com",
+                "objectClass: top",
+                "objectClass: domain",
+                "dc: example",
+                "dn: ou=users,dc=example,dc=com",
+                "objectClass: top",
+                "objectClass: organizationalUnit",
+                "ou: users"
+        }
+)
+public class DirectoryLdapIdentityBackendTest extends AbstractLdapIdentityBackendTest
+{
+    private LdapIdentityBackend backend;
+    private static final String BASE_DN = "ou=users,dc=example,dc=com";
+    private static final String ADMIN_DN = "uid=admin,ou=system";
+    private static final String ADMIN_PW = "secret";
+
+
+    @Before
+    public void setUp() throws Exception {
+        Conf config = new Conf();
+        config.setString("admin_dn", ADMIN_DN);
+        config.setString("admin_pw", ADMIN_PW);
+        config.setString("base_dn", BASE_DN);
+        LdapConnection connection = new LdapCoreSessionConnection(getService());
+        this.backend = new LdapIdentityBackend(config, connection);
+        backend.initialize();
+        backend.start();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        backend.stop();
+        backend.release();
+    }
+
+    @Test
+    public void testGet() {
+        super.testGet(backend);
+    }
+
+    @Test
+    public void testStore() {
+        super.testStore(backend);
+    }
+
+    @Test
+    public void testUpdate() {
+        super.testUpdate(backend);
+    }
+
+    @Test
+    public void testDelete() {
+        super.testDelete(backend);
+    }
+
+    @Test
+    public void testGetIdentities() {
+        super.testGetIdentities(backend);
+    }
+}
\ No newline at end of file


Mime
View raw message