From d4fa3bd9dd48f4d5e26850a23f5ba48a9c10ad64 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 5 Jun 2014 15:02:07 +0200 Subject: LDAP refactored behind interfaces. All functions of LDAP now hidden behind interfaces: Authenticator, Lookup and NextKeyManager (LDAP property storage was already a ClusterStorage). Gateway holds additional objects, and Fixes #26 #191. Refs #27 (needs additional work for read perms and auth tokens) --- src/main/java/com/c2kernel/lookup/AgentPath.java | 42 +- src/main/java/com/c2kernel/lookup/DomainPath.java | 21 +- .../c2kernel/lookup/InvalidItemPathException.java | 2 +- .../com/c2kernel/lookup/InvalidPathException.java | 13 + src/main/java/com/c2kernel/lookup/ItemPath.java | 16 - src/main/java/com/c2kernel/lookup/LDAPLookup.java | 496 ------------- .../java/com/c2kernel/lookup/LDAPLookupUtils.java | 340 --------- src/main/java/com/c2kernel/lookup/LDAPPathSet.java | 72 -- .../java/com/c2kernel/lookup/LDAPProperties.java | 54 -- .../com/c2kernel/lookup/LDAPPropertyManager.java | 138 ---- .../java/com/c2kernel/lookup/LDAPRoleManager.java | 224 ------ src/main/java/com/c2kernel/lookup/Lookup.java | 77 ++ .../java/com/c2kernel/lookup/NextKeyManager.java | 84 --- src/main/java/com/c2kernel/lookup/Path.java | 87 +-- src/main/java/com/c2kernel/lookup/RolePath.java | 35 +- .../com/c2kernel/lookup/ldap/LDAPAuthManager.java | 95 +++ .../java/com/c2kernel/lookup/ldap/LDAPLookup.java | 775 +++++++++++++++++++++ .../com/c2kernel/lookup/ldap/LDAPLookupUtils.java | 365 ++++++++++ .../c2kernel/lookup/ldap/LDAPNextKeyManager.java | 92 +++ .../java/com/c2kernel/lookup/ldap/LDAPPathSet.java | 81 +++ .../com/c2kernel/lookup/ldap/LDAPProperties.java | 38 + .../c2kernel/lookup/ldap/LDAPPropertyManager.java | 141 ++++ 22 files changed, 1703 insertions(+), 1585 deletions(-) create mode 100644 src/main/java/com/c2kernel/lookup/InvalidPathException.java delete mode 100644 src/main/java/com/c2kernel/lookup/LDAPLookup.java delete mode 100644 src/main/java/com/c2kernel/lookup/LDAPLookupUtils.java delete mode 100644 src/main/java/com/c2kernel/lookup/LDAPPathSet.java delete mode 100644 src/main/java/com/c2kernel/lookup/LDAPProperties.java delete mode 100644 src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java delete mode 100644 src/main/java/com/c2kernel/lookup/LDAPRoleManager.java create mode 100644 src/main/java/com/c2kernel/lookup/Lookup.java delete mode 100644 src/main/java/com/c2kernel/lookup/NextKeyManager.java create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPProperties.java create mode 100644 src/main/java/com/c2kernel/lookup/ldap/LDAPPropertyManager.java (limited to 'src/main/java/com/c2kernel/lookup') diff --git a/src/main/java/com/c2kernel/lookup/AgentPath.java b/src/main/java/com/c2kernel/lookup/AgentPath.java index a560795..a0bb7fd 100644 --- a/src/main/java/com/c2kernel/lookup/AgentPath.java +++ b/src/main/java/com/c2kernel/lookup/AgentPath.java @@ -15,12 +15,8 @@ import java.security.NoSuchAlgorithmException; import org.apache.xerces.impl.dv.util.Base64; -import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.process.Gateway; -import com.novell.ldap.LDAPAttribute; -import com.novell.ldap.LDAPAttributeSet; -import com.novell.ldap.LDAPEntry; /** @@ -70,8 +66,7 @@ public class AgentPath extends ItemPath if (mAgentName==null) { try { - LDAPEntry agentEntry = LDAPLookupUtils.getEntry(Gateway.getLDAPLookup().getConnection(), this.getDN() + mLocalPath); - mAgentName = LDAPLookupUtils.getFirstAttributeValue(agentEntry,"uid"); + mAgentName = Gateway.getLookup().getAgentName(this); } catch (ObjectNotFoundException e) { mAgentName = ""; } @@ -81,16 +76,16 @@ public class AgentPath extends ItemPath public RolePath[] getRoles() { - return Gateway.getLDAPLookup().getRoleManager().getRoles(this); + return Gateway.getLookup().getRoles(this); } public boolean hasRole(RolePath role) { - return Gateway.getLDAPLookup().getRoleManager().hasRole(this, role); + return Gateway.getLookup().hasRole(this, role); } public boolean hasRole(String role) { try { - return hasRole(Gateway.getLDAPLookup().getRoleManager().getRolePath(role)); + return hasRole(Gateway.getLookup().getRolePath(role)); } catch (ObjectNotFoundException ex) { return false; } @@ -113,7 +108,7 @@ public class AgentPath extends ItemPath mAgentName; } - static String generateUserPassword(String pass, String algo) throws NoSuchAlgorithmException { + public static String generateUserPassword(String pass, String algo) throws NoSuchAlgorithmException { MessageDigest sha = MessageDigest.getInstance(algo); sha.reset(); sha.update(pass.getBytes()); @@ -123,32 +118,5 @@ public class AgentPath extends ItemPath return digest.toString(); } - @Override - public LDAPAttributeSet createAttributeSet() throws ObjectCannotBeUpdated - { - LDAPAttributeSet attrs = new LDAPAttributeSet(); - attrs.add(new LDAPAttribute("objectclass","cristalagent")); - attrs.add(new LDAPAttribute("intsyskey",Integer.toString(mSysKey))); - attrs.add(new LDAPAttribute("cn", getPath()[getPath().length-1])); - if (mIOR != null) - attrs.add(new LDAPAttribute("ior", Gateway.getORB().object_to_string(mIOR))); - - if (mAgentName!=null && mAgentName.length()>0) - attrs.add(new LDAPAttribute("uid",mAgentName)); - else - throw new ObjectCannotBeUpdated("Cannot create agent. No userId specified", ""); - - if (mPassword!=null && mPassword.length()>0) - try { - attrs.add(new LDAPAttribute("userPassword",generateUserPassword(mPassword, "SHA"))); - } catch (NoSuchAlgorithmException ex) { - throw new ObjectCannotBeUpdated("Cryptographic libraries for password hashing not found.", ""); - } - else - throw new ObjectCannotBeUpdated("Cannot create agent. No password given", ""); - - return attrs; - } - } diff --git a/src/main/java/com/c2kernel/lookup/DomainPath.java b/src/main/java/com/c2kernel/lookup/DomainPath.java index b0784f9..706719e 100644 --- a/src/main/java/com/c2kernel/lookup/DomainPath.java +++ b/src/main/java/com/c2kernel/lookup/DomainPath.java @@ -13,8 +13,6 @@ package com.c2kernel.lookup; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; -import com.novell.ldap.LDAPAttribute; -import com.novell.ldap.LDAPAttributeSet; /** @@ -108,7 +106,7 @@ public class DomainPath extends Path public void checkType() { try { - setEntity(Gateway.getLDAPLookup().resolvePath(this)); + setEntity(Gateway.getLookup().resolvePath(this)); } catch (InvalidItemPathException ex) { Logger.error(ex); mType = CONTEXT; @@ -137,22 +135,5 @@ public class DomainPath extends Path } else return INVALID; } - - @Override - public LDAPAttributeSet createAttributeSet() { - LDAPAttributeSet attrs = new LDAPAttributeSet(); - attrs.add(new LDAPAttribute("cn",getName())); - if (getType() == ENTITY) { - String objectclass_values[] = { "alias", "aliasObject" }; - attrs.add(new LDAPAttribute("objectclass",objectclass_values)); - attrs.add(new LDAPAttribute("aliasedObjectName",target.getFullDN())); - } - - else - { - attrs.add(new LDAPAttribute("objectclass","cristalcontext")); - } - return attrs; - } } diff --git a/src/main/java/com/c2kernel/lookup/InvalidItemPathException.java b/src/main/java/com/c2kernel/lookup/InvalidItemPathException.java index 5b37cd7..58174a8 100644 --- a/src/main/java/com/c2kernel/lookup/InvalidItemPathException.java +++ b/src/main/java/com/c2kernel/lookup/InvalidItemPathException.java @@ -1,6 +1,6 @@ package com.c2kernel.lookup; -public class InvalidItemPathException extends Exception { +public class InvalidItemPathException extends InvalidPathException { public InvalidItemPathException() { super(); diff --git a/src/main/java/com/c2kernel/lookup/InvalidPathException.java b/src/main/java/com/c2kernel/lookup/InvalidPathException.java new file mode 100644 index 0000000..77887cf --- /dev/null +++ b/src/main/java/com/c2kernel/lookup/InvalidPathException.java @@ -0,0 +1,13 @@ +package com.c2kernel.lookup; + +public class InvalidPathException extends Exception { + + public InvalidPathException() { + super(); + } + + public InvalidPathException(String msg) { + super(msg); + } + +} diff --git a/src/main/java/com/c2kernel/lookup/ItemPath.java b/src/main/java/com/c2kernel/lookup/ItemPath.java index 89fe5ee..17e5659 100644 --- a/src/main/java/com/c2kernel/lookup/ItemPath.java +++ b/src/main/java/com/c2kernel/lookup/ItemPath.java @@ -12,11 +12,7 @@ package com.c2kernel.lookup; import java.util.ArrayList; -import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; -import com.c2kernel.process.Gateway; -import com.novell.ldap.LDAPAttribute; -import com.novell.ldap.LDAPAttributeSet; /** @@ -147,7 +143,6 @@ public class ItemPath extends Path mPath = (newKey.toArray(mPath)); mSysKey = sysKey; mStringPath = null; - mDN = null; mType = Path.ENTITY; checkSysPath(); } @@ -160,16 +155,5 @@ public class ItemPath extends Path else mType = Path.CONTEXT; } - - @Override - public LDAPAttributeSet createAttributeSet() throws ObjectCannotBeUpdated { - LDAPAttributeSet attrs = new LDAPAttributeSet(); - attrs.add(new LDAPAttribute("objectclass","cristalentity")); - attrs.add(new LDAPAttribute("intsyskey",Integer.toString(mSysKey))); - attrs.add(new LDAPAttribute("cn", getPath()[getPath().length-1])); - if (mIOR != null) - attrs.add(new LDAPAttribute("ior", Gateway.getORB().object_to_string(mIOR))); - return attrs; - } } diff --git a/src/main/java/com/c2kernel/lookup/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/LDAPLookup.java deleted file mode 100644 index eae803b..0000000 --- a/src/main/java/com/c2kernel/lookup/LDAPLookup.java +++ /dev/null @@ -1,496 +0,0 @@ -/* - * Directory Lookup Service * - * author: Florida Estrella -*/ - -package com.c2kernel.lookup; - -import java.util.StringTokenizer; - -import com.c2kernel.common.ObjectAlreadyExistsException; -import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; -import com.c2kernel.entity.TraceableEntity; -import com.c2kernel.entity.agent.ActiveEntity; -import com.c2kernel.entity.proxy.ProxyMessage; -import com.c2kernel.process.Gateway; -import com.c2kernel.property.PropertyDescription; -import com.c2kernel.property.PropertyDescriptionList; -import com.c2kernel.utils.Logger; -import com.novell.ldap.LDAPAttributeSet; -import com.novell.ldap.LDAPConnection; -import com.novell.ldap.LDAPDN; -import com.novell.ldap.LDAPEntry; -import com.novell.ldap.LDAPException; -import com.novell.ldap.LDAPSearchConstraints; -import com.novell.ldap.LDAPSearchResults; - -/** - * The LDAPLookup object, statically accessible through the Gateway, manages - * the LDAP connection for the cristal process. It provides: - *