diff options
Diffstat (limited to 'source/com/c2kernel/lookup/LDAPLookup.java')
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/lookup/LDAPLookup.java | 119 |
1 files changed, 61 insertions, 58 deletions
diff --git a/source/com/c2kernel/lookup/LDAPLookup.java b/source/com/c2kernel/lookup/LDAPLookup.java index 04d99f0..9bae873 100755..100644 --- a/source/com/c2kernel/lookup/LDAPLookup.java +++ b/source/com/c2kernel/lookup/LDAPLookup.java @@ -5,7 +5,6 @@ package com.c2kernel.lookup;
-import java.util.Enumeration;
import java.util.StringTokenizer;
import com.c2kernel.common.ObjectAlreadyExistsException;
@@ -18,10 +17,16 @@ import com.c2kernel.entity.proxy.ProxyMessage; import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.Resource;
-import com.novell.ldap.*;
+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 LDAPLookup object, statically accessible through the Gateway, manages
* the LDAP connection for the cristal process. It provides:
* <ul>
* <li>Authentication - returning an AgentProxy object if a user has logged in
@@ -32,7 +37,7 @@ import com.novell.ldap.*; * @author $Author: abranson $
*/
-public class LDAPLookup
+public class LDAPLookup
{
private LDAPConnection mLDAPConn;
@@ -40,30 +45,30 @@ public class LDAPLookup private NextKeyManager mNextKeyManager;
private LDAPPropertyManager mPropManager;
private LDAPRoleManager mRoleManager;
-
-
+
+
/**
- * Creates a new LDAPLookup manager with the properties supplied.
+ * Creates a new LDAPLookup manager with the properties supplied.
* This should be only done by the Gateway during initialisation.
- *
+ *
* @param props The LDAP properties object that extracts LDAP connection properties from the global c2kprops
*/
public LDAPLookup(LDAPProperties props) throws LDAPException
{
Logger.msg(8,"LDAPLookup - initialising.");
-
+
mLDAPProps = props;
-
+
mLDAPConn = createConnection(mLDAPProps);
-
+
Path.mGlobalPath=props.mGlobalPath;
Path.mRootPath=props.mRootPath;
Path.mLocalPath=props.mLocalPath;
-
+
EntityPath.mTypeRoot = "cn=entity,"+props.mLocalPath;
DomainPath.mTypeRoot = "cn=domain,"+props.mLocalPath;
-
+
mNextKeyManager = new NextKeyManager(this, "cn=last,"+EntityPath.mTypeRoot);
Logger.debug("LDAP.useOldProps="+Gateway.getProperty("LDAP.useOldProps", "false"));
if (Gateway.getProperty("LDAP.useOldProps", "false").equals("true")) {
@@ -77,9 +82,9 @@ public class LDAPLookup mRoleManager = new LDAPRoleManager(this, "cn=agent,"+DomainPath.mTypeRoot, EntityPath.mTypeRoot);
}
-
+
/**
- * Utility method to connect to an LDAP server
+ * Utility method to connect to an LDAP server
* @param lp LDAP properties to connect with
* @return a novell LDAPConnection object
* @throws LDAPException when the connection was unsuccessful
@@ -92,13 +97,13 @@ public class LDAPLookup Logger.msg(3, "LDAPLookup - authenticating user:" + lp.mUser);
ld.bind( LDAPConnection.LDAP_V3, lp.mUser,
- String.valueOf(lp.mPassword).getBytes());
+ String.valueOf(lp.mPassword).getBytes());
Logger.msg(3, "LDAPLookup - authentication successful");
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setMaxResults(0);
ld.setConstraints(searchCons);
-
+
return ld;
}
@@ -110,7 +115,7 @@ public class LDAPLookup {
return mNextKeyManager;
}
-
+
/**
* Gets the property manager, that is used to read and write cristal properties to the LDAP store.
* @return Returns the global LDAPPropertyManager.
@@ -124,23 +129,23 @@ public class LDAPLookup */
public LDAPRoleManager getRoleManager() {
return mRoleManager;
- }
+ }
/**
* Returns the current LDAP connection, and attempts to reconnect if it has been closed.
* @return
*/
- protected LDAPConnection getConnection()
- {
+ protected LDAPConnection getConnection()
+ {
if (!mLDAPConn.isConnected()) {
Logger.warning("LDAPLookup - lost connection to LDAP server. Attempting to reconnect.");
try {
mLDAPConn = createConnection(mLDAPProps);
} catch (LDAPException ex) { }
}
- return mLDAPConn;
+ return mLDAPConn;
}
-
+
/**
* Disconnects the connection with the LDAP server during shutdown
*/
@@ -156,7 +161,7 @@ public class LDAPLookup }
}
- /**
+ /**
* Attempts to resolve the CORBA object for a Path, either directly or through an alias.
* @param path the path to resolve
* @return the CORBA object
@@ -197,13 +202,13 @@ public class LDAPLookup }
/**
- *
+ *
* @param domPath
* @return
* @throws InvalidEntityPathException
* @throws ObjectNotFoundException
*/
- protected EntityPath resolvePath(DomainPath domPath)
+ protected EntityPath resolvePath(DomainPath domPath)
throws InvalidEntityPathException, ObjectNotFoundException {
EntityPath referencedPath = null;
LDAPEntry domEntry = LDAPLookupUtils.getEntry(getConnection(), domPath
@@ -221,12 +226,11 @@ public class LDAPLookup return referencedPath;
}
-
+
public LDAPEntry add(Path path)
throws ObjectCannotBeUpdated, ObjectAlreadyExistsException
{
- String root = path.getRoot();
try {
checkLDAPContext(path);
LDAPAttributeSet attrSet = path.createAttributeSet();
@@ -256,10 +260,9 @@ public class LDAPLookup EntityProxyManager.sendProxyEvent(new ProxyMessage(ProxyMessage.NA, path.toString(), ProxyMessage.DELETED));
}
}
-
+
//change specs, add boolean alias leaf context
protected void checkLDAPContext(Path path)
- throws LDAPException
{
String dn = path.getFullDN();
if (!LDAPLookupUtils.exists(getConnection(),dn))
@@ -290,7 +293,7 @@ public class LDAPLookup public void createBootTree()
{
Logger.msg(8,"Initializing LDAP Boot tree");
-
+
//create org
LDAPLookupUtils.createOrganizationContext(getConnection(), Path.mGlobalPath);
//create root
@@ -298,13 +301,13 @@ public class LDAPLookup //create local
LDAPLookupUtils.createCristalContext(getConnection(), Path.mLocalPath);
}
-
- public void install() throws LDAPException
+
+ public void install()
{
createBootTree();
initTree( Resource.getTextResource("boot/LDAPboot.txt"));
}
-
+
public void initTree(String bootFile)
{
Logger.msg(8,"Verifying Cristal LDAP roots");
@@ -315,21 +318,21 @@ public class LDAPLookup Logger.msg(8,"Checking " + line+Path.mLocalPath);
LDAPLookupUtils.createCristalContext(getConnection(), line+Path.mLocalPath);
}
-
- }
-
+
+ }
+
//typically search for cn=barcode
- public Enumeration search(Path start, String filter)
+ public LDAPPathSet search(Path start, String filter)
{
Logger.msg(8,"LDAPLookup::search() From " + start.getDN() + " for cn=" + filter );
return search(start.getFullDN(),"cn="+LDAPLookupUtils.escapeSearchFilter(filter));
}
-
- protected Enumeration search(String startDN, int scope, String filter, LDAPSearchConstraints searchCons)
- {
+
+ protected LDAPPathSet search(String startDN, int scope, String filter, LDAPSearchConstraints searchCons)
+ {
Logger.msg(8,"Searching for "+filter+" in "+startDN);
searchCons.setMaxResults(0);
- String[] attr = { LDAPConnection.ALL_USER_ATTRS };
+ String[] attr = { LDAPConnection.ALL_USER_ATTRS };
try
{
LDAPSearchResults res = getConnection().search(LDAPLookupUtils.escapeDN(startDN),scope,
@@ -341,9 +344,9 @@ public class LDAPLookup Logger.error("LDAPException::LDAPLookup::search() " + ex.toString());
return new LDAPPathSet();
}
- }
+ }
//typically search for (any filter combination)
- public Enumeration search(String startDN,String filter)
+ public LDAPPathSet search(String startDN,String filter)
{
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
@@ -351,14 +354,14 @@ public class LDAPLookup return search(startDN,LDAPConnection.SCOPE_SUB,filter,searchCons);
}
- public Enumeration searchEntities(Path start) {
+ public LDAPPathSet searchEntities(Path start) {
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_SEARCHING);
return search(start.getFullDN(), LDAPConnection.SCOPE_SUB, "objectClass=cristalentity", searchCons);
}
-
- public Enumeration searchAliases(DomainPath start) {
+
+ public LDAPPathSet searchAliases(DomainPath start) {
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
@@ -368,8 +371,8 @@ public class LDAPLookup public boolean exists(Path path) {
return LDAPLookupUtils.exists(getConnection(), path.getFullDN());
}
-
- public Class getEntityClass(Path path) throws ObjectNotFoundException {
+
+ public Class<?> getEntityClass(Path path) throws ObjectNotFoundException {
String[] attr = { LDAPConnection.ALL_USER_ATTRS };
try {
LDAPEntry anEntry=getConnection().read(path.getDN()+Path.mLocalPath,attr);
@@ -380,7 +383,7 @@ public class LDAPLookup return ActiveEntity.class;
else
throw new ObjectNotFoundException("Not an entity", "");
-
+
} catch (LDAPException ex) {
if (ex.getResultCode() == LDAPException.NO_SUCH_OBJECT)
throw new ObjectNotFoundException("Entity does not exist", "");
@@ -388,7 +391,7 @@ public class LDAPLookup throw new ObjectNotFoundException("Error getting entity class", "");
}
}
-
+
/** converts an LDAPentry to a Path object
* Note that the search producing the entry should have retrieved the attrs
* 'ior' and 'uniquemember'
@@ -398,14 +401,14 @@ public class LDAPLookup protected Path nodeToPath(LDAPEntry entry) throws InvalidEntityPathException, ObjectNotFoundException
{
String dn = entry.getDN();
-
+
// extract syskey
int entityKey = -1;
try {
String entityKeyStr = LDAPLookupUtils.getFirstAttributeValue(entry,"intsyskey");
entityKey = Integer.parseInt(entityKeyStr);
} catch (Exception e) { }
-
+
// extract IOR
org.omg.CORBA.Object ior = null;
try {
@@ -420,10 +423,10 @@ public class LDAPLookup String agentID = LDAPLookupUtils.getFirstAttributeValue(entry,"uid");
thisPath = new AgentPath(entityKey, agentID);
}
-
+
else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalrole"))
{ //cristalrole
- thisPath = new RolePath(LDAPDN.explodeDN(dn,true)[0],
+ thisPath = new RolePath(LDAPDN.explodeDN(dn,true)[0],
LDAPLookupUtils.getFirstAttributeValue(entry, "jobList").equals("TRUE"));
}
else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","aliasObject") ||
@@ -431,7 +434,7 @@ public class LDAPLookup {
DomainPath domainPath = new DomainPath();
domainPath.setDN(dn);
- thisPath = domainPath;
+ thisPath = domainPath;
}
else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalentity") ||
(LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalcontext") && dn.endsWith(EntityPath.mTypeRoot)))
@@ -452,8 +455,8 @@ public class LDAPLookup else
{
throw new ObjectNotFoundException("Unrecognised LDAP entry. Not a cristal entry");
- }
-
+ }
+
//set IOR if we have one
if (ior!=null) thisPath.setIOR(ior);
return thisPath;
|
