From 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 Mon Sep 17 00:00:00 2001 From: abranson Date: Thu, 4 Aug 2011 00:42:34 +0200 Subject: More code cleanup: Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class --- source/com/c2kernel/lookup/LDAPRoleManager.java | 75 +++++++++++++------------ 1 file changed, 38 insertions(+), 37 deletions(-) (limited to 'source/com/c2kernel/lookup/LDAPRoleManager.java') 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 agents = new ArrayList(); - for (int i=0; i roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons); ArrayList roleList = new ArrayList(); - + 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"); } } -- cgit v1.2.3