diff options
Diffstat (limited to 'source/com/c2kernel/lookup/LDAPRoleManager.java')
| -rw-r--r-- | source/com/c2kernel/lookup/LDAPRoleManager.java | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/source/com/c2kernel/lookup/LDAPRoleManager.java b/source/com/c2kernel/lookup/LDAPRoleManager.java index a45da13..1df2f29 100644 --- a/source/com/c2kernel/lookup/LDAPRoleManager.java +++ b/source/com/c2kernel/lookup/LDAPRoleManager.java @@ -7,7 +7,10 @@ import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.utils.Logger;
-import com.novell.ldap.*;
+import com.novell.ldap.LDAPConnection;
+import com.novell.ldap.LDAPEntry;
+import com.novell.ldap.LDAPException;
+import com.novell.ldap.LDAPSearchConstraints;
/**************************************************************************
*
@@ -27,7 +30,7 @@ public class LDAPRoleManager { LDAPLookup mLdap;
private String mRolePath;
private String mEntityPath;
-
+
public LDAPRoleManager(LDAPLookup ldap, String rolePath, String entityPath) {
super();
this.mLdap = ldap;
@@ -44,14 +47,14 @@ public class LDAPRoleManager { // create the role
RolePath rolePath = new RolePath(roleName, jobList);
- String roleDN = rolePath.getFullDN();
+ String roleDN = rolePath.getFullDN();
LDAPEntry roleNode;
try
- {
+ {
roleNode = LDAPLookupUtils.getEntry(mLdap.getConnection(), rolePath.getFullDN());
throw new ObjectAlreadyExistsException();
} catch (ObjectNotFoundException ex) { }
-
+
//create CristalRole if it does not exist
roleNode = new LDAPEntry(roleDN, rolePath.createAttributeSet());
try {
@@ -60,7 +63,7 @@ public class LDAPRoleManager { throw new ObjectCannotBeUpdated(e.getLDAPErrorMessage(), "");
}
return rolePath;
-
+
}
public void deleteRole(RolePath role) throws ObjectNotFoundException, ObjectCannotBeUpdated {
@@ -72,7 +75,7 @@ public class LDAPRoleManager { }
protected void addRole(AgentPath agent, RolePath role)
- throws ObjectCannotBeUpdated, ObjectNotFoundException
+ throws ObjectCannotBeUpdated, ObjectNotFoundException
{
LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), role.getFullDN());
//add memberDN to uniqueMember if it is not yet a member
@@ -82,7 +85,7 @@ public class LDAPRoleManager { throw new ObjectCannotBeUpdated("Agent " + agent.getAgentName() + " already has role " + role.getName());
}
- protected void removeRole(AgentPath agent, RolePath role)
+ protected void removeRole(AgentPath agent, RolePath role)
throws ObjectCannotBeUpdated, ObjectNotFoundException
{
LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), role.getFullDN());
@@ -91,44 +94,42 @@ public class LDAPRoleManager { else
throw new ObjectCannotBeUpdated("Agent did not have that role");
}
-
+
protected boolean hasRole(AgentPath agent, RolePath role) {
- String filter = "(&(objectclass=cristalrole)(uniqueMember="+agent.getFullDN()+")(cn="+role.getName()+"))";
+ String filter = "(&(objectclass=cristalrole)(uniqueMember="+agent.getFullDN()+")(cn="+role.getName()+"))";
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- Enumeration roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
+ Enumeration<?> roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
return roles.hasMoreElements();
}
protected AgentPath[] getAgents(RolePath role)
throws ObjectNotFoundException
{
- //get the roleDN entry, and its uniqueMember entry pointing to
+ //get the roleDN entry, and its uniqueMember entry pointing to
LDAPEntry roleEntry;
try {
roleEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), role.getFullDN());
} catch (ObjectNotFoundException e) {
throw new ObjectNotFoundException("Role does not exist", "");
}
-
+
String[] res = LDAPLookupUtils.getAllAttributeValues(roleEntry,"uniqueMember");
ArrayList<AgentPath> agents = new ArrayList<AgentPath>();
- for (int i=0; i<res.length; i++)
- {
- String userDN = res[i];
- try {
- LDAPEntry userEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), userDN);
+ for (String userDN : res) {
+ try {
+ LDAPEntry userEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), userDN);
AgentPath path = (AgentPath)mLdap.nodeToPath(userEntry);
agents.add(path);
} catch (ObjectNotFoundException ex) {
- Logger.error("Agent "+res[i]+" does not exist");
+ Logger.error("Agent "+userDN+" does not exist");
} catch (InvalidEntityPathException ex) {
- Logger.error("Agent "+res[i]+" is not a valid entity");
+ Logger.error("Agent "+userDN+" is not a valid entity");
}
- }
+ }
AgentPath[] usersList = new AgentPath[0];
- usersList = (AgentPath[])agents.toArray(usersList);
+ usersList = agents.toArray(usersList);
return usersList;
}
@@ -137,26 +138,26 @@ public class LDAPRoleManager { {
//search the mDomainPath tree uniqueMember=userDN
//filter = objectclass=cristalrole AND uniqueMember=userDN
- String filter = "(&(objectclass=cristalrole)(uniqueMember="+agentPath.getFullDN()+"))";
+ String filter = "(&(objectclass=cristalrole)(uniqueMember="+agentPath.getFullDN()+"))";
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- Enumeration roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
+ Enumeration<?> roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
ArrayList<RolePath> roleList = new ArrayList<RolePath>();
-
+
while(roles.hasMoreElements())
{
RolePath path = (RolePath) roles.nextElement();
- roleList.add(path);
- }
+ roleList.add(path);
+ }
RolePath[] roleArr = new RolePath[roleList.size()];
- roleArr = (RolePath[])roleList.toArray(roleArr);
+ roleArr = roleList.toArray(roleArr);
return roleArr;
}
/**
* Utility for looking up a login name
- *
+ *
* @param ld
* @param agentName
* @param baseDN
@@ -164,15 +165,15 @@ public class LDAPRoleManager { * @throws ObjectNotFoundException
*/
public AgentPath getAgentPath(String agentName) throws ObjectNotFoundException
- {
+ {
//search to get the userDN equivalent of the userID
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- String filter = "(&(objectclass=cristalagent)(uid="+agentName+"))";
- Enumeration res = mLdap.search(mEntityPath,LDAPConnection.SCOPE_SUB,filter,searchCons);
+ String filter = "(&(objectclass=cristalagent)(uid="+agentName+"))";
+ Enumeration<?> res = mLdap.search(mEntityPath,LDAPConnection.SCOPE_SUB,filter,searchCons);
if (!res.hasMoreElements())
- throw new ObjectNotFoundException("Agent not found");
+ throw new ObjectNotFoundException("Agent not found");
Path result = (Path)res.nextElement();
if (result instanceof AgentPath)
return (AgentPath)result;
@@ -185,15 +186,15 @@ public class LDAPRoleManager { LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- String filter = "(&(objectclass=cristalrole)(cn="+roleName+"))";
- Enumeration res = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
+ String filter = "(&(objectclass=cristalrole)(cn="+roleName+"))";
+ Enumeration<?> res = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
if (!res.hasMoreElements())
- throw new ObjectNotFoundException("Role not found");
+ throw new ObjectNotFoundException("Role not found");
Path result = (Path)res.nextElement();
if (result instanceof RolePath)
return (RolePath)result;
else
- throw new ObjectNotFoundException("Entry was not a Role");
+ throw new ObjectNotFoundException("Entry was not a Role");
}
}
|
