From 6aa1f44575a48bdc633fdf6a3274fd6a1a4065b9 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 12 Jun 2014 19:49:01 +0200 Subject: Initial migration out of cristal-kernel --- .gitignore | 4 + pom.xml | 105 +++ .../com/c2kernel/lookup/ldap/LDAPAuthManager.java | 95 +++ .../java/com/c2kernel/lookup/ldap/LDAPLookup.java | 763 +++++++++++++++++++++ .../com/c2kernel/lookup/ldap/LDAPLookupUtils.java | 365 ++++++++++ .../c2kernel/lookup/ldap/LDAPNextKeyManager.java | 97 +++ .../java/com/c2kernel/lookup/ldap/LDAPPathSet.java | 81 +++ .../com/c2kernel/lookup/ldap/LDAPProperties.java | 38 + .../c2kernel/lookup/ldap/LDAPPropertyManager.java | 141 ++++ .../com/c2kernel/persistency/LDAPClientReader.java | 43 ++ .../c2kernel/persistency/LDAPClusterStorage.java | 176 +++++ src/main/resources/LDAPboot.txt | 4 + src/main/resources/module.xml | 11 + 13 files changed, 1923 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml 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 create mode 100644 src/main/java/com/c2kernel/persistency/LDAPClientReader.java create mode 100644 src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java create mode 100644 src/main/resources/LDAPboot.txt create mode 100644 src/main/resources/module.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1898b99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.classpath +/.project +/.settings +/target diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6853210 --- /dev/null +++ b/pom.xml @@ -0,0 +1,105 @@ + + 4.0.0 + cristal + cristal-ldap + 1.0-SNAPSHOT + cristal-ldap + CRISTAL Module + + UTF-8 + + + + + src/main/resources + META-INF/cristal + true + + module.xml + + + + src/main/resources + com/c2kernel/lookup/ldap/resources + + module.xml + + + + + + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + + + cccs.releases + http://dev.cccs.uwe.ac.uk:8081/nexus/content/repositories/releases + + + cccs.snapshots + http://dev.cccs.uwe.ac.uk:8081/nexus/content/repositories/snapshots + + + + + + cccs.releases + CCCS Nexus Release Repository + http://dev.cccs.uwe.ac.uk:8081/nexus/content/repositories/releases + + true + + + false + + + + cccs.snapshots + CCCS Nexus Snapshot Repository + http://dev.cccs.uwe.ac.uk:8081/nexus/content/repositories/snapshots + + false + + + true + + + + cccs.public + CCCS Nexus Public Repository + http://dev.cccs.uwe.ac.uk:8081/nexus/content/repositories/public + + + + + + cristal + cristal-kernel + 3.0-SNAPSHOT + + + com.novell.ldap + jldap + 4.3 + + + + + + cristal + cristal-kernel + + + com.novell.ldap + jldap + + + \ No newline at end of file diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java new file mode 100644 index 0000000..4c26de6 --- /dev/null +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java @@ -0,0 +1,95 @@ +package com.c2kernel.lookup.ldap; + +import com.c2kernel.common.InvalidDataException; +import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.process.Gateway; +import com.c2kernel.process.auth.Authenticator; +import com.c2kernel.utils.Logger; +import com.novell.ldap.LDAPConnection; +import com.novell.ldap.LDAPException; + +public class LDAPAuthManager implements Authenticator { + + private LDAPConnection mLDAPConn; + private LDAPProperties ldapProps; + + + @Override + public boolean authenticate(String agentName, + String password, String resource) throws InvalidDataException, ObjectNotFoundException { + + ldapProps = new LDAPProperties(Gateway.getProperties()); + + if (ldapProps.mHost!=null && ldapProps.mPort!= null && ldapProps.mLocalPath!=null ) + { + try { // anonymously bind to LDAP and find the agent entry for the username + ldapProps.mUser = ""; + ldapProps.mPassword = ""; + mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); + LDAPLookup anonLookup = new LDAPLookup(ldapProps); + anonLookup.open(this); + String agentDN = anonLookup.getFullDN(anonLookup.getAgentPath(agentName)); + + //found agentDN, try to log in with it + ldapProps.mUser = agentDN; + ldapProps.mPassword = password; + mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); + return true; + } catch (LDAPException e) { + return false; + } + } + else + { + throw new InvalidDataException("Cannot log in. Some connection properties are not set.", ""); + } + + } + + @Override + public boolean authenticate(String resource) throws InvalidDataException, ObjectNotFoundException { + ldapProps = new LDAPProperties(Gateway.getProperties()); + + if (ldapProps.mUser == null || ldapProps.mUser.length()==0 || + ldapProps.mPassword == null || ldapProps.mPassword.length()==0) + throw new InvalidDataException("LDAP root user properties not found in config."); + try { + mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); + return true; + } catch (LDAPException e) { + return false; + } + } + + @Override + public LDAPConnection getAuthObject() { + + if (!mLDAPConn.isConnected()) { + Logger.warning("LDAPAuthManager - lost connection to LDAP server. Attempting to reconnect."); + try { + mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); + } catch (LDAPException ex) { } + } + return mLDAPConn; + } + + @Override + public void disconnect() { + Logger.msg(1, "LDAP Lookup: Shutting down LDAP connection."); + if (mLDAPConn != null) { + try { + mLDAPConn.disconnect(); + } catch (LDAPException e) { + Logger.error(e); + } + mLDAPConn = null; + } + + } + + public LDAPAuthManager() { + // TODO Auto-generated constructor stub + } + + +} diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java new file mode 100644 index 0000000..ac36a10 --- /dev/null +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java @@ -0,0 +1,763 @@ +/* + * Directory Lookup Service * + * author: Florida Estrella +*/ + +package com.c2kernel.lookup.ldap; + +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.StringTokenizer; + +import org.omg.CORBA.Object; + +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.lookup.AgentPath; +import com.c2kernel.lookup.DomainPath; +import com.c2kernel.lookup.InvalidItemPathException; +import com.c2kernel.lookup.ItemPath; +import com.c2kernel.lookup.Lookup; +import com.c2kernel.lookup.Path; +import com.c2kernel.lookup.RolePath; +import com.c2kernel.process.Gateway; +import com.c2kernel.process.auth.Authenticator; +import com.c2kernel.property.PropertyDescription; +import com.c2kernel.property.PropertyDescriptionList; +import com.c2kernel.utils.Logger; +import com.novell.ldap.LDAPAttribute; +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: + *