From c6204281c819ea4514952ed7623e282babcb5f8c Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 27 Feb 2013 21:36:23 +0100 Subject: More --- .../com/c2kernel/lookup/ldap/LDAPRoleManager.java | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/ldap/LDAPRoleManager.java') 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 roles = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons); ArrayList roleList = new ArrayList(); - 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 res = mLdap.search(mEntityPath,LDAPConnection.SCOPE_SUB,filter,searchCons); - if (!res.hasMoreElements()) + Iterator 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 res = mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons); - if (!res.hasMoreElements()) + Iterator 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"); + } + } -- cgit v1.2.3