From cedb32b6b7a799ef4142b418e64d3538cf604af1 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 5 Jun 2014 14:13:37 +0200 Subject: Recreate old Authenticator interface as 'ProxyLogin' Server boots with new lookup interface. --- .../java/com/c2kernel/lookup/ldap/LDAPAuthManager.java | 12 ++++++++++-- src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java | 17 +++++++++++------ .../java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java | 4 ++-- .../com/c2kernel/lookup/ldap/LDAPNextKeyManager.java | 15 ++++++++++----- src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java | 5 +++-- 5 files changed, 36 insertions(+), 17 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup') diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java index 20d16c3..4c26de6 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java @@ -26,7 +26,8 @@ public class LDAPAuthManager implements Authenticator { ldapProps.mUser = ""; ldapProps.mPassword = ""; mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); - LDAPLookup anonLookup = new LDAPLookup(ldapProps, this); + LDAPLookup anonLookup = new LDAPLookup(ldapProps); + anonLookup.open(this); String agentDN = anonLookup.getFullDN(anonLookup.getAgentPath(agentName)); //found agentDN, try to log in with it @@ -47,10 +48,17 @@ public class LDAPAuthManager implements Authenticator { @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."); - return authenticate(null, ldapProps.mUser, ldapProps.mPassword); + try { + mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); + return true; + } catch (LDAPException e) { + return false; + } } @Override diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java index a5624b1..a96a46b 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java @@ -66,7 +66,7 @@ public class LDAPLookup implements Lookup * * @param props The LDAP properties object that extracts LDAP connection properties from the global c2kprops */ - public LDAPLookup(LDAPProperties props, LDAPAuthManager auth) throws LDAPException + public LDAPLookup(LDAPProperties props) { Logger.msg(8,"LDAPLookup - initialising."); @@ -80,10 +80,15 @@ public class LDAPLookup implements Lookup } + public LDAPLookup() { + this(new LDAPProperties(Gateway.getProperties())); + } + @Override public void open(Authenticator auth) { mLDAPAuth = (LDAPAuthManager)auth; mNextKeyManager = new LDAPNextKeyManager(mLDAPAuth, "cn=last,"+mItemTypeRoot); + Gateway.getProperties().setProperty("NextKeyManager", mNextKeyManager); Logger.msg(7, "LDAP.useOldProps="+Gateway.getProperties().getBoolean("LDAP.useOldProps", false)); mPropManager = new LDAPPropertyManager(this, mLDAPAuth); } @@ -330,7 +335,7 @@ public class LDAPLookup implements Lookup { LDAPSearchResults res = mLDAPAuth.getAuthObject().search(startDN, scope, filter,attr,false,searchCons); - return new LDAPPathSet(res); + return new LDAPPathSet(res, this); } catch (LDAPException ex) { @@ -439,7 +444,7 @@ public class LDAPLookup implements Lookup (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalcontext") && dn.endsWith(mDomainTypeRoot))) { DomainPath domainPath = new DomainPath(); - domainPath.setPath(getPathComponents(dn)); + domainPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mDomainTypeRoot)))); thisPath = domainPath; } else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalentity") || @@ -451,7 +456,7 @@ public class LDAPLookup implements Lookup entityPath = new ItemPath(entityKey); else { entityPath = new ItemPath(); - entityPath.setPath(getPathComponents(dn)); + entityPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mItemTypeRoot)))); } thisPath = entityPath; } @@ -497,7 +502,7 @@ public class LDAPLookup implements Lookup @Override public Object resolve(Path path) throws ObjectNotFoundException { - return resolveObject(getDN(path)); + return resolveObject(getFullDN(path)); } @Override @@ -709,7 +714,7 @@ public class LDAPLookup implements Lookup String filter = "(&(objectclass=cristalagent)(uid="+agentName+"))"; Iterator res = search(mItemTypeRoot,LDAPConnection.SCOPE_SUB,filter,searchCons); if (!res.hasNext()) - throw new ObjectNotFoundException("Agent not found"); + throw new ObjectNotFoundException("Agent not found: "+agentName, ""); Path result = res.next(); if (result instanceof AgentPath) return (AgentPath)result; diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java index 6ff6b2f..e1c8ac4 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java @@ -39,7 +39,7 @@ final public class LDAPLookupUtils LDAPEntry thisEntry = ld.read(dn,searchCons); if (thisEntry != null) return thisEntry; } catch (LDAPException ex) { - throw new ObjectNotFoundException("LDAP Exception: "+ex.getMessage(), ""); + throw new ObjectNotFoundException("LDAP Exception for dn:"+dn+": \n"+ex.getMessage(), ""); } throw new ObjectNotFoundException(dn+" does not exist", ""); @@ -315,7 +315,7 @@ final public class LDAPLookupUtils public static String escapeDN (String name) { //From RFC 2253 and the / character for JNDI - + if (name == null) return null; String escapedStr = new String(name); //Backslash is both a Java and an LDAP escape character, so escape it first diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java index fdd565a..4db8a49 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java @@ -6,6 +6,7 @@ import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorageException; +import com.c2kernel.persistency.NextKeyManager; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; import com.novell.ldap.LDAPEntry; @@ -20,7 +21,7 @@ import com.novell.ldap.LDAPEntry; **************************************************************************/ // public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/04/27 13:47:24 $ $Author: abranson $"; -public class LDAPNextKeyManager { +public class LDAPNextKeyManager implements NextKeyManager { LDAPAuthManager ldap; String lastKeyPath; @@ -31,7 +32,8 @@ public class LDAPNextKeyManager { this.lastKeyPath = lastKeyPath; } - public synchronized ItemPath generateNextEntityKey() + @Override + public synchronized ItemPath generateNextEntityKey() throws ObjectCannotBeUpdated, ObjectNotFoundException { ItemPath lastKey = getLastEntityPath(); @@ -57,18 +59,21 @@ public class LDAPNextKeyManager { return lastKey; } - public synchronized AgentPath generateNextAgentKey() + @Override + public synchronized AgentPath generateNextAgentKey() throws ObjectCannotBeUpdated, ObjectNotFoundException { ItemPath newEntity = generateNextEntityKey(); return new AgentPath(newEntity); } - public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException { + @Override + public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException { LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getAuthObject(),lastKeyPath); LDAPLookupUtils.setAttributeValue(ldap.getAuthObject(), lastKeyEntry,"intsyskey",Integer.toString(sysKey)); } - public ItemPath getLastEntityPath() throws ObjectNotFoundException + @Override + public ItemPath getLastEntityPath() throws ObjectNotFoundException { LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getAuthObject(),lastKeyPath); String lastKey = LDAPLookupUtils.getFirstAttributeValue(lastKeyEntry,"intsyskey"); diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java index 5c46073..806976d 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java @@ -27,9 +27,10 @@ public class LDAPPathSet implements Iterator { public LDAPPathSet(LDAPLookup ldap) { // empty this.ldap = ldap; results = null; - } + } - public LDAPPathSet(LDAPSearchResults results) { + public LDAPPathSet(LDAPSearchResults results, LDAPLookup ldap) { + this.ldap = ldap; this.results = results; } -- cgit v1.2.3