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-292]-Implementing doGetIdentity for LdapIdentityBackend. Contributed by Yaning.
Date Fri, 19 Jun 2015 08:12:59 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master dc79c2bb1 -> 027479c28


[DIRKRB-292]-Implementing doGetIdentity for LdapIdentityBackend. 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/027479c2
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/027479c2
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/027479c2

Branch: refs/heads/master
Commit: 027479c28b1dfc7755b341c208dc053b0b673c05
Parents: dc79c2b
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Fri Jun 19 16:16:57 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Fri Jun 19 16:16:57 2015 +0800

----------------------------------------------------------------------
 .../identitybackend/LdapIdentityBackend.java    | 32 +++++++++-
 .../identitybackend/LdapIdentityGetHelper.java  | 63 +++++++++++++++++++-
 .../backend/LdapIdentityBackendTest.java        | 13 +++-
 3 files changed, 104 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/027479c2/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 76cc5c0..013d564 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
@@ -34,8 +34,10 @@ import org.apache.kerby.kerberos.kerb.identity.backend.AbstractIdentityBackend;
 import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
 import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
 import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
+import sun.security.krb5.Asn1Exception;
 
 import java.io.IOException;
+import java.text.ParseException;
 import java.util.List;
 import java.util.Map;
 
@@ -95,7 +97,6 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
         }
     }
 
-
     private String toGeneralizedTime(KerberosTime kerberosTime) {
         GeneralizedTime generalizedTime = new GeneralizedTime(kerberosTime.getValue());
         return generalizedTime.toString();
@@ -170,7 +171,34 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
 
     @Override
     protected KrbIdentity doGetIdentity(String principalName) {
-        return null;
+        String[] names = principalName.split("@");
+        String uid = names[0];
+        KrbIdentity krbIdentity = new KrbIdentity(principalName);
+        try {
+            Dn dn = new Dn(new Rdn("uid", uid), new Dn(BASE_DN));
+            Entry entry = connection.lookup(dn, "*", "+");
+            if (entry == null) {
+                return null;
+            }
+            LdapIdentityGetHelper getHelper = new LdapIdentityGetHelper(entry);
+            krbIdentity.setPrincipal(getHelper.getPrincipalName());
+            krbIdentity.setKeyVersion(getHelper.getKeyVersion());
+            krbIdentity.addKeys(getHelper.getKeys());
+            krbIdentity.setCreatedTime(getHelper.getCreatedTime());
+            krbIdentity.setExpireTime(getHelper.getExpireTime());
+            krbIdentity.setDisabled(getHelper.getDisabled());
+            krbIdentity.setKdcFlags(getHelper.getKdcFlags());
+            krbIdentity.setLocked(getHelper.getLocked());
+        } catch (LdapException e) {
+            e.printStackTrace();
+        } catch (Asn1Exception e) {
+            e.printStackTrace();
+        } catch (ParseException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return krbIdentity;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/027479c2/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityGetHelper.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityGetHelper.java
b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityGetHelper.java
index 89664c3..ad50769 100644
--- a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityGetHelper.java
+++ b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityGetHelper.java
@@ -20,10 +20,20 @@
 package org.apache.kerby.kerberos.kdc.identitybackend;
 
 import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.entry.Value;
+import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.api.util.GeneralizedTime;
+import org.apache.directory.shared.kerberos.KerberosAttribute;
 import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.base.PrincipalName;
+import sun.security.krb5.Asn1Exception;
 
+import java.io.IOException;
 import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 public class LdapIdentityGetHelper {
     private Entry entry;
@@ -31,7 +41,58 @@ public class LdapIdentityGetHelper {
         this.entry = entry;
     }
 
-    private KerberosTime createKerberosTime(String generalizedTime)//NOPMD
+    public PrincipalName getPrincipalName() throws LdapInvalidAttributeValueException {
+        String principalNameStr = entry.get(KerberosAttribute.KRB5_PRINCIPAL_NAME_AT).getString();
+        PrincipalName principalName = new PrincipalName(principalNameStr);
+        return principalName;
+    }
+
+    public int getKeyVersion() throws LdapInvalidAttributeValueException {
+        String keyVersionStr = entry.get(KerberosAttribute.KRB5_KEY_VERSION_NUMBER_AT).getString();
+        int keyVersion = Integer.parseInt(keyVersionStr);
+        return keyVersion;
+    }
+
+    public List<EncryptionKey> getKeys() throws IOException {
+        Iterator<Value<?>> iterator1 = entry.get(KerberosAttribute.KRB5_KEY_AT).iterator();
+        List<EncryptionKey> keys= new ArrayList<>();
+        while (iterator1.hasNext()) {
+            byte[] encryKey= iterator1.next().getBytes();
+            EncryptionKey key = new EncryptionKey();
+            key.decode(encryKey);
+            keys.add(key);
+        }
+        return keys;
+    }
+
+    public KerberosTime getCreatedTime() throws LdapInvalidAttributeValueException,
+            Asn1Exception, ParseException {
+        String createTime = entry.get("createTimestamp").getString();
+        return createKerberosTime(createTime);
+    }
+
+    public KerberosTime getExpireTime() throws LdapInvalidAttributeValueException,
+            Asn1Exception, ParseException {
+        String expirationTime = entry.get(KerberosAttribute.KRB5_ACCOUNT_EXPIRATION_TIME_AT).getString();
+        return createKerberosTime(expirationTime);
+    }
+
+    public boolean getDisabled() throws LdapInvalidAttributeValueException {
+        String disabled = entry.get(KerberosAttribute.KRB5_ACCOUNT_DISABLED_AT).getString();
+        return Boolean.parseBoolean(disabled);
+    }
+
+    public int getKdcFlags() throws LdapInvalidAttributeValueException {
+        String krb5KDCFlags = entry.get("krb5KDCFlags").getString();
+        return Integer.parseInt(krb5KDCFlags);
+    }
+
+    public boolean getLocked() throws LdapInvalidAttributeValueException {
+        String lockedOut = entry.get(KerberosAttribute.KRB5_ACCOUNT_LOCKEDOUT_AT).getString();
+        return Boolean.parseBoolean(lockedOut);
+    }
+
+    private KerberosTime createKerberosTime(String generalizedTime)
             throws ParseException {
         long time = new GeneralizedTime(generalizedTime).getTime();
         return new KerberosTime(time);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/027479c2/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
index 10bf3f5..fb8146a 100644
--- 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
@@ -28,6 +28,7 @@ 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;
 
@@ -60,7 +61,7 @@ public class LdapIdentityBackendTest extends AbstractLdapIdentityBackendTest
 {
     private LdapIdentityBackend backend;
 
-    @Test
+    @Before
     public void setUp() throws Exception {
         Conf config = new Conf();
         config.setInt("port", getLdapServer().getPort());
@@ -74,4 +75,14 @@ public class LdapIdentityBackendTest extends AbstractLdapIdentityBackendTest
         backend.stop();
         backend.release();
     }
+
+    @Test
+    public void testGet() {
+        super.testGet(backend);
+    }
+
+    @Test
+    public void testStore() {
+        super.testStore(backend);
+    }
 }
\ No newline at end of file


Mime
View raw message