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-290]-Setup Ldap service. Contributed by Yaning.
Date Mon, 15 Jun 2015 02:41:29 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 9d91e2a83 -> 74afb52ae


[DIRKRB-290]-Setup Ldap service. 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/74afb52a
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/74afb52a
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/74afb52a

Branch: refs/heads/master
Commit: 74afb52ae99f66da365f6e08089bf3f3a9717667
Parents: 9d91e2a
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Mon Jun 15 10:45:52 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Mon Jun 15 10:45:52 2015 +0800

----------------------------------------------------------------------
 kerby-backend/ldap-backend/pom.xml              | 22 +++++-
 .../identitybackend/LdapIdentityBackend.java    | 47 +++++++++---
 .../AbstractLdapIdentityBackendTest.java        | 55 ++++++++++++++
 .../kerb/identity/backend/LdapBackendTest.java  | 43 -----------
 .../backend/LdapIdentityBackendTest.java        | 79 ++++++++++++++++++++
 5 files changed, 192 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/74afb52a/kerby-backend/ldap-backend/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/pom.xml b/kerby-backend/ldap-backend/pom.xml
index 1d0aaab..110cc0b 100644
--- a/kerby-backend/ldap-backend/pom.xml
+++ b/kerby-backend/ldap-backend/pom.xml
@@ -27,7 +27,7 @@
   <description>Ldap identity backend</description>
 
   <properties>
-    <ldap.api.version>1.0.0-M28</ldap.api.version>
+    <ldap.api.version>1.0.0-M30</ldap.api.version>
   </properties>
 
   <dependencies>
@@ -47,6 +47,26 @@
       <version>${ldap.api.version}</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+      <version>2.0.0-M20</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-protocol-ldap</artifactId>
+      <version>2.0.0-M20</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-test-framework</artifactId>
+      <version>2.0.0-M20</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>ldap-client-test</artifactId>
+      <version>2.0.0-M20</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.kerby</groupId>
       <artifactId>kerb-identity-test</artifactId>
       <version>${project.version}</version>

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/74afb52a/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 ab9c398..e2d3eca 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
@@ -19,12 +19,13 @@
  */
 package org.apache.kerby.kerberos.kdc.identitybackend;
 
-import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.kerby.config.Config;
 import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
 import org.apache.kerby.kerberos.kerb.identity.backend.AbstractIdentityBackend;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -32,12 +33,13 @@ import java.util.List;
  *
  */
 public class LdapIdentityBackend extends AbstractIdentityBackend {
+    private static final String BASE_DN = "ou=users,dc=example,dc=com";//NOPMD
+    private static final String ADMIN_DN = "uid=admin,ou=system";
+    private LdapNetworkConnection connection;
 
-    // the connection to the LDAP server
-    // in case of ApacheDS this will be an instance of LdapCoreSessionConnection
-    private LdapConnection connection; //NOPMD
+    public LdapIdentityBackend() {
 
-    private Dn baseDn; //NOPMD
+    }
 
     /**
      * Constructing an instance using specified config that contains anything
@@ -48,13 +50,39 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
         setConfig(config);
     }
 
-    /*
+    public void startConnection() throws LdapException {
+        this.connection = new LdapNetworkConnection( "localhost",
+                getConfig().getInt("port") );
+        connection.bind( ADMIN_DN, "secret" );
+    }
+
+    @Override
     public void initialize() {
         super.initialize();
+        try {
+            startConnection();
+        } catch (LdapException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void stop() {
+        try {
+            closeConnection();
+        } catch (LdapException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 
-        // init Ldap connection and baseDn.
+    public void closeConnection() throws LdapException, IOException {
+        if (this.connection.connect()) {
+            this.connection.unBind();
+            this.connection.close();
+        }
     }
-    */
 
     @Override
     protected KrbIdentity doGetIdentity(String principalName) {
@@ -83,7 +111,6 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
 
     @Override
     public List<String> getIdentities() {
-        //TODO
         return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/74afb52a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractLdapIdentityBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractLdapIdentityBackendTest.java
b/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractLdapIdentityBackendTest.java
new file mode 100644
index 0000000..924dea2
--- /dev/null
+++ b/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractLdapIdentityBackendTest.java
@@ -0,0 +1,55 @@
+/**
+ *  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.server.core.api.DirectoryService;
+import org.apache.directory.server.ldap.LdapServer;
+
+public abstract class AbstractLdapIdentityBackendTest extends  BackendTest
+{
+    /** The used DirectoryService instance */
+    private static DirectoryService service;
+
+    /** The used LdapServer instance */
+    private static LdapServer ldapServer;
+
+    public static DirectoryService getService()
+    {
+        return service;
+    }
+
+
+    public static void setService( DirectoryService service )
+    {
+        AbstractLdapIdentityBackendTest.service = service;
+    }
+
+
+    public static LdapServer getLdapServer()
+    {
+        return ldapServer;
+    }
+
+    public static void setLdapServer( LdapServer ldapServer )
+    {
+        AbstractLdapIdentityBackendTest.ldapServer = ldapServer;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/74afb52a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapBackendTest.java
b/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapBackendTest.java
deleted file mode 100644
index 74ac597..0000000
--- a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapBackendTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- *  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.kerby.config.Conf;
-import org.apache.kerby.kerberos.kdc.identitybackend.LdapIdentityBackend;
-import org.junit.Before;
-
-/**
- * Ldap backend test
- */
-public class LdapBackendTest extends BackendTest {
-    private IdentityBackend backend;
-
-    @Before
-    public void setup() {
-        Conf config = new Conf();
-        backend = new LdapIdentityBackend(config);
-        backend.initialize();
-    }
-
-    //@Test
-    public void testGet() {
-        super.testGet(backend);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/74afb52a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapIdentityBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapIdentityBackendTest.java
b/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapIdentityBackendTest.java
new file mode 100644
index 0000000..6d500d3
--- /dev/null
+++ b/kerby-backend/ldap-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/LdapIdentityBackendTest.java
@@ -0,0 +1,79 @@
+/**
+ *  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.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.integ.FrameworkRunner;
+import org.apache.kerby.config.Conf;
+import org.apache.kerby.kerberos.kdc.identitybackend.LdapIdentityBackend;
+import org.junit.After;
+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 LdapIdentityBackendTest extends AbstractLdapIdentityBackendTest
+{
+    private LdapIdentityBackend backend;
+
+    @Test
+    public void setUp() throws Exception
+    {
+        Conf config = new Conf();
+        config.setInt("port", getLdapServer().getPort());
+        this.backend = new LdapIdentityBackend(config);
+        backend.initialize();
+        backend.start();
+    }
+
+    @After
+    public void tearDown() throws Exception
+    {
+        backend.stop();
+        backend.release();
+    }
+}
\ No newline at end of file


Mime
View raw message