diff options
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/ldap/LDAPRoleManager.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/ldap/LDAPRoleManager.java | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPRoleManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPRoleManager.java index 816d1c4..42032f3 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPRoleManager.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPRoleManager.java @@ -1,7 +1,7 @@ package com.c2kernel.lookup.ldap;
import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Iterator;
import com.c2kernel.common.ObjectAlreadyExistsException;
import com.c2kernel.common.ObjectCannotBeUpdated;
@@ -11,6 +11,7 @@ import com.c2kernel.lookup.InvalidEntityPathException; import com.c2kernel.lookup.Path;
import com.c2kernel.lookup.RoleManager;
import com.c2kernel.lookup.RolePath;
+import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry;
@@ -92,7 +93,8 @@ public class LDAPRoleManager implements RoleManager { throw new ObjectCannotBeUpdated("Agent " + agent.getAgentName() + " already has role " + role.getName());
}
- public void removeRole(AgentPath agent, RolePath role)
+ @Override
+ public void removeRole(AgentPath agent, RolePath role)
throws ObjectCannotBeUpdated, ObjectNotFoundException
{
LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), role.getFullDN());
@@ -102,12 +104,13 @@ public class LDAPRoleManager implements RoleManager { throw new ObjectCannotBeUpdated("Agent did not have that role");
}
- public boolean hasRole(AgentPath agent, RolePath role) {
+ @Override
+ public boolean hasRole(AgentPath agent, RolePath role) {
String filter = "(&(objectclass=cristalrole)(uniqueMember="+agent.getFullDN()+")(cn="+role.getName()+"))";
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- return mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons).hasMoreElements();
+ return mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons).hasNext();
}
@Override
@@ -150,12 +153,12 @@ public class LDAPRoleManager implements RoleManager { LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- Enumeration<?> roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
+ Iterator<Path> roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
ArrayList<RolePath> roleList = new ArrayList<RolePath>();
- while(roles.hasMoreElements())
+ while(roles.hasNext())
{
- RolePath path = (RolePath) roles.nextElement();
+ RolePath path = (RolePath) roles.next();
roleList.add(path);
}
RolePath[] roleArr = new RolePath[roleList.size()];
@@ -180,10 +183,10 @@ public class LDAPRoleManager implements RoleManager { searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
String filter = "(&(objectclass=cristalagent)(uid="+agentName+"))";
- Enumeration<Path> res = mLdap.search(mEntityPath,LDAPConnection.SCOPE_SUB,filter,searchCons);
- if (!res.hasMoreElements())
+ Iterator<Path> res = mLdap.search(mEntityPath,LDAPConnection.SCOPE_SUB,filter,searchCons);
+ if (!res.hasNext())
throw new ObjectNotFoundException("Agent not found");
- Path result = res.nextElement();
+ Path result = res.next();
if (result instanceof AgentPath)
return (AgentPath)result;
else
@@ -197,14 +200,25 @@ public class LDAPRoleManager implements RoleManager { searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
String filter = "(&(objectclass=cristalrole)(cn="+roleName+"))";
- Enumeration<Path> res = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
- if (!res.hasMoreElements())
+ Iterator<Path> res = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
+ if (!res.hasNext())
throw new ObjectNotFoundException("Role not found");
- Path result = res.nextElement();
+ Path result = res.next();
if (result instanceof RolePath)
return (RolePath)result;
else
throw new ObjectNotFoundException("Entry was not a Role");
}
+ /* (non-Javadoc)
+ * @see com.c2kernel.lookup.RoleManager#getAgentName(com.c2kernel.lookup.AgentPath)
+ */
+ @Override
+ public String getAgentName(AgentPath agentPath) throws ObjectNotFoundException {
+ LDAPLookup ldap = (LDAPLookup)Gateway.getLookup();
+ LDAPEntry agentEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), agentPath.getDN() + ldap.mLocalPath);
+
+ return LDAPLookupUtils.getFirstAttributeValue(agentEntry,"uid");
+ }
+
}
|
