From e64e6fada90a93be37f171277b484630db263266 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 3 Oct 2014 17:31:22 +0200 Subject: Adapt to new Exceptions --- .../java/com/c2kernel/lookup/ldap/LDAPLookup.java | 114 ++++++++++----------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java') diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java index 7d4c53f..a9fcd6d 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java @@ -12,9 +12,9 @@ import java.util.StringTokenizer; import org.omg.CORBA.Object; -import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectAlreadyExists; import com.c2kernel.common.ObjectCannotBeUpdated; -import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.common.ObjectNotFound; import com.c2kernel.entity.proxy.ProxyMessage; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; @@ -121,10 +121,10 @@ public class LDAPLookup implements LookupManager{ * 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 - * @throws ObjectNotFoundException When the path does not exist + * @throws ObjectNotFound When the path does not exist */ public org.omg.CORBA.Object getIOR(Path path) - throws ObjectNotFoundException + throws ObjectNotFound { return resolveObject(getFullDN(path)); } @@ -132,10 +132,10 @@ public class LDAPLookup implements LookupManager{ /** * Attempts to resolve the CORBA object from the IOR attribute of a DN, either directly or through an alias * @param dn The String dn - * @throws ObjectNotFoundException when the dn or aliased dn does not exist + * @throws ObjectNotFound when the dn or aliased dn does not exist */ private org.omg.CORBA.Object resolveObject(String dn) - throws ObjectNotFoundException + throws ObjectNotFound { Logger.msg(8,"LDAPLookup.resolveObject("+dn+")"); LDAPEntry anEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(),dn,LDAPSearchConstraints.DEREF_NEVER); @@ -148,13 +148,13 @@ public class LDAPLookup implements LookupManager{ if (ior!=null) return ior; else - throw new ObjectNotFoundException("LDAPLookup.resolveObject() - " + dn + " has no IOR", ""); - } catch (ObjectNotFoundException ex) { + throw new ObjectNotFound("LDAPLookup.resolveObject() - " + dn + " has no IOR"); + } catch (ObjectNotFound ex) { return resolveObject(LDAPLookupUtils.getFirstAttributeValue(anEntry,"aliasedObjectName")); } } else - throw new ObjectNotFoundException("LDAPLookup.resolveObject() LDAP node " + dn + " is not in LDAP or has no IOR.", ""); + throw new ObjectNotFound("LDAPLookup.resolveObject() LDAP node " + dn + " is not in LDAP or has no IOR."); } /** @@ -162,11 +162,11 @@ public class LDAPLookup implements LookupManager{ * @param domPath * @return * @throws InvalidItemPathException - * @throws ObjectNotFoundException + * @throws ObjectNotFound */ @Override public ItemPath resolvePath(DomainPath domPath) - throws InvalidItemPathException, ObjectNotFoundException { + throws InvalidItemPathException, ObjectNotFound { LDAPEntry domEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(domPath), LDAPSearchConstraints.DEREF_ALWAYS); @@ -186,7 +186,7 @@ public class LDAPLookup implements LookupManager{ @Override public void add(Path path) - throws ObjectCannotBeUpdated, ObjectAlreadyExistsException + throws ObjectCannotBeUpdated, ObjectAlreadyExists { try { checkLDAPContext(path); @@ -197,9 +197,9 @@ public class LDAPLookup implements LookupManager{ Gateway.getProxyServer().sendProxyEvent(new ProxyMessage(null, path.toString(), ProxyMessage.ADDED)); } catch (LDAPException ex) { if (ex.getResultCode() == LDAPException.ENTRY_ALREADY_EXISTS) - throw new ObjectAlreadyExistsException(ex.getLDAPErrorMessage(), ""); + throw new ObjectAlreadyExists(ex.getLDAPErrorMessage()); else - throw new ObjectCannotBeUpdated(ex.getLDAPErrorMessage(), ""); + throw new ObjectCannotBeUpdated(ex.getLDAPErrorMessage()); } } @@ -211,7 +211,7 @@ public class LDAPLookup implements LookupManager{ try { LDAPLookupUtils.delete(mLDAPAuth.getAuthObject(),getDN(path)+mLocalPath); } catch (LDAPException ex) { - throw new ObjectCannotBeUpdated(ex.getLDAPErrorMessage(), ""); + throw new ObjectCannotBeUpdated(ex.getLDAPErrorMessage()); } if (path instanceof DomainPath) { Gateway.getProxyServer().sendProxyEvent(new ProxyMessage(null, path.toString(), ProxyMessage.DELETED)); @@ -260,7 +260,7 @@ public class LDAPLookup implements LookupManager{ } @Override - public void initializeDirectory() throws ObjectNotFoundException + public void initializeDirectory() throws ObjectNotFound { createBootTree(); initTree( Gateway.getResource().getTextResource("ldap", "LDAPboot.txt")); @@ -364,7 +364,7 @@ public class LDAPLookup implements LookupManager{ } @Override - public ItemPath getItemPath(String uuid) throws ObjectNotFoundException, InvalidItemPathException { + public ItemPath getItemPath(String uuid) throws ObjectNotFound, InvalidItemPathException { String[] attr = { LDAPConnection.ALL_USER_ATTRS }; try { ItemPath item = new ItemPath(uuid); @@ -375,24 +375,24 @@ public class LDAPLookup implements LookupManager{ else if (type.equals("cristalagent")) return new AgentPath(item); else - throw new ObjectNotFoundException("Not an entity", ""); + throw new ObjectNotFound("Not an entity"); } catch (LDAPException ex) { if (ex.getResultCode() == LDAPException.NO_SUCH_OBJECT) - throw new ObjectNotFoundException("Entity does not exist", ""); + throw new ObjectNotFound("Entity does not exist"); Logger.error(ex); - throw new ObjectNotFoundException("Error getting entity class", ""); + throw new ObjectNotFound("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' - * @throws ObjectNotFoundException - * @throws ObjectNotFoundException + * @throws ObjectNotFound + * @throws ObjectNotFound * @throws */ - protected Path nodeToPath(LDAPEntry entry) throws InvalidItemPathException, ObjectNotFoundException + protected Path nodeToPath(LDAPEntry entry) throws InvalidItemPathException, ObjectNotFound { String dn = entry.getDN(); ItemPath entityKey; @@ -402,7 +402,7 @@ public class LDAPLookup implements LookupManager{ try { String entityKeyStr = LDAPLookupUtils.getFirstAttributeValue(entry, "cn"); entityKey = new ItemPath(entityKeyStr); - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { entityKey = null; } catch (InvalidItemPathException ex) { entityKey = null; @@ -412,7 +412,7 @@ public class LDAPLookup implements LookupManager{ try { String stringIOR = LDAPLookupUtils.getFirstAttributeValue(entry,"ior"); ior = Gateway.getORB().string_to_object(stringIOR); - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { ior = null; } @@ -443,11 +443,11 @@ public class LDAPLookup implements LookupManager{ thisPath = entityKey; } else - throw new ObjectNotFoundException("Entity found outside entity tree", ""); + throw new ObjectNotFound("Entity found outside entity tree"); } else { - throw new ObjectNotFoundException("Unrecognised LDAP entry. Not a cristal entry", ""); + throw new ObjectNotFound("Unrecognised LDAP entry. Not a cristal entry"); } //set IOR if we have one @@ -483,7 +483,7 @@ public class LDAPLookup implements LookupManager{ } @Override - public Object resolve(Path path) throws ObjectNotFoundException { + public Object resolve(Path path) throws ObjectNotFound { return resolveObject(getFullDN(path)); } @@ -513,7 +513,7 @@ public class LDAPLookup implements LookupManager{ attrs.add(new LDAPAttribute("aliasedObjectName",getFullDN(domPath.getItemPath()))); String objectclass_values[] = { "alias", "aliasObject" }; attrs.add(new LDAPAttribute("objectclass",objectclass_values)); - } catch (ObjectNotFoundException e) { // no entity - is a context + } catch (ObjectNotFound e) { // no entity - is a context attrs.add(new LDAPAttribute("objectclass","cristalcontext")); } } @@ -532,17 +532,17 @@ public class LDAPLookup implements LookupManager{ if (agentName != null && agentName.length() > 0) attrs.add(new LDAPAttribute("uid", agentName)); else - throw new ObjectCannotBeUpdated("Cannot create agent. No userId specified", ""); + throw new ObjectCannotBeUpdated("Cannot create agent. No userId specified"); String agentPass = agentPath.getPassword(); if (agentPass != null && agentPass.length() > 0) try { attrs.add(new LDAPAttribute("userPassword", AgentPath.generateUserPassword(agentPass, "SHA"))); } catch (NoSuchAlgorithmException ex) { - throw new ObjectCannotBeUpdated("Cryptographic libraries for password hashing not found.", ""); + throw new ObjectCannotBeUpdated("Cryptographic libraries for password hashing not found."); } else - throw new ObjectCannotBeUpdated("Cannot create agent. No password given", ""); + throw new ObjectCannotBeUpdated("Cannot create agent. No password given"); } else { attrs.add(new LDAPAttribute("objectclass","cristalentity")); @@ -557,7 +557,7 @@ public class LDAPLookup implements LookupManager{ //CristalRole is-a specialized CristalContext which contains multi-valued uniqueMember attribute pointing to cristalagents @Override public RolePath createRole(RolePath rolePath) - throws ObjectAlreadyExistsException, ObjectCannotBeUpdated + throws ObjectAlreadyExists, ObjectCannotBeUpdated { // create the role @@ -566,21 +566,21 @@ public class LDAPLookup implements LookupManager{ try { roleNode = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(rolePath)); - throw new ObjectAlreadyExistsException(); - } catch (ObjectNotFoundException ex) { } + throw new ObjectAlreadyExists(); + } catch (ObjectNotFound ex) { } //create CristalRole if it does not exist roleNode = new LDAPEntry(roleDN, createAttributeSet(rolePath)); try { LDAPLookupUtils.addEntry(mLDAPAuth.getAuthObject(),roleNode); } catch (LDAPException e) { - throw new ObjectCannotBeUpdated(e.getLDAPErrorMessage(), ""); + throw new ObjectCannotBeUpdated(e.getLDAPErrorMessage()); } return rolePath; } - public void deleteRole(RolePath role) throws ObjectNotFoundException, ObjectCannotBeUpdated { + public void deleteRole(RolePath role) throws ObjectNotFound, ObjectCannotBeUpdated { try { LDAPLookupUtils.delete(mLDAPAuth.getAuthObject(), getFullDN(role)); } catch (LDAPException ex) { @@ -590,7 +590,7 @@ public class LDAPLookup implements LookupManager{ @Override public void addRole(AgentPath agent, RolePath role) - throws ObjectCannotBeUpdated, ObjectNotFoundException + throws ObjectCannotBeUpdated, ObjectNotFound { LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(role)); //add memberDN to uniqueMember if it is not yet a member @@ -602,7 +602,7 @@ public class LDAPLookup implements LookupManager{ @Override public void removeRole(AgentPath agent, RolePath role) - throws ObjectCannotBeUpdated, ObjectNotFoundException + throws ObjectCannotBeUpdated, ObjectNotFound { LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(role)); if (LDAPLookupUtils.existsAttributeValue(roleEntry, "uniqueMember", getFullDN(agent))) @@ -622,14 +622,14 @@ public class LDAPLookup implements LookupManager{ @Override public AgentPath[] getAgents(RolePath role) - throws ObjectNotFoundException + throws ObjectNotFound { //get the roleDN entry, and its uniqueMember entry pointing to LDAPEntry roleEntry; try { roleEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(role)); - } catch (ObjectNotFoundException e) { - throw new ObjectNotFoundException("Role does not exist", ""); + } catch (ObjectNotFound e) { + throw new ObjectNotFound("Role does not exist"); } String[] res = LDAPLookupUtils.getAllAttributeValues(roleEntry,"uniqueMember"); @@ -639,7 +639,7 @@ public class LDAPLookup implements LookupManager{ LDAPEntry userEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), userDN); AgentPath path = (AgentPath)nodeToPath(userEntry); agents.add(path); - } catch (ObjectNotFoundException ex) { + } catch (ObjectNotFound ex) { Logger.error("Agent "+userDN+" does not exist"); } catch (InvalidItemPathException ex) { Logger.error("Agent "+userDN+" is not a valid entity"); @@ -680,10 +680,10 @@ public class LDAPLookup implements LookupManager{ * @param agentName * @param baseDN * @return - * @throws ObjectNotFoundException + * @throws ObjectNotFound */ @Override - public AgentPath getAgentPath(String agentName) throws ObjectNotFoundException + public AgentPath getAgentPath(String agentName) throws ObjectNotFound { //search to get the userDN equivalent of the userID LDAPSearchConstraints searchCons = new LDAPSearchConstraints(); @@ -692,16 +692,16 @@ public class LDAPLookup implements LookupManager{ String filter = "(&(objectclass=cristalagent)(uid="+agentName+"))"; Iterator res = search(mItemTypeRoot,LDAPConnection.SCOPE_SUB,filter,searchCons); if (!res.hasNext()) - throw new ObjectNotFoundException("Agent not found: "+agentName, ""); + throw new ObjectNotFound("Agent not found: "+agentName); Path result = res.next(); if (result instanceof AgentPath) return (AgentPath)result; else - throw new ObjectNotFoundException("Entry was not an Agent"); + throw new ObjectNotFound("Entry was not an Agent"); } @Override - public RolePath getRolePath(String roleName) throws ObjectNotFoundException + public RolePath getRolePath(String roleName) throws ObjectNotFound { LDAPSearchConstraints searchCons = new LDAPSearchConstraints(); searchCons.setBatchSize(0); @@ -709,35 +709,35 @@ public class LDAPLookup implements LookupManager{ String filter = "(&(objectclass=cristalrole)(cn="+roleName+"))"; Iterator res = search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons); if (!res.hasNext()) - throw new ObjectNotFoundException("Role not found"); + throw new ObjectNotFound("Role not found"); Path result = res.next(); if (result instanceof RolePath) return (RolePath)result; else - throw new ObjectNotFoundException("Entry was not a Role"); + throw new ObjectNotFound("Entry was not a Role"); } @Override - public void setHasJobList(RolePath role, boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated { + public void setHasJobList(RolePath role, boolean hasJobList) throws ObjectNotFound, ObjectCannotBeUpdated { // get entry LDAPEntry roleEntry; try { roleEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(role)); - } catch (ObjectNotFoundException e) { - throw new ObjectNotFoundException("Role does not exist", ""); + } catch (ObjectNotFound e) { + throw new ObjectNotFound("Role does not exist"); } // set attribute LDAPLookupUtils.setAttributeValue(mLDAPAuth.getAuthObject(), roleEntry, "jobList", hasJobList?"TRUE":"FALSE"); } @Override - public void setAgentPassword(AgentPath agent, String newPassword) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException { + public void setAgentPassword(AgentPath agent, String newPassword) throws ObjectNotFound, ObjectCannotBeUpdated, NoSuchAlgorithmException { String encPasswd = AgentPath.generateUserPassword(newPassword, "SHA"); LDAPEntry agentEntry; try { agentEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(agent)); - } catch (ObjectNotFoundException e) { - throw new ObjectNotFoundException("Agent "+agent.getAgentName()+" does not exist", ""); + } catch (ObjectNotFound e) { + throw new ObjectNotFound("Agent "+agent.getAgentName()+" does not exist"); } LDAPLookupUtils.setAttributeValue(mLDAPAuth.getAuthObject(), agentEntry, "userPassword", encPasswd); @@ -745,7 +745,7 @@ public class LDAPLookup implements LookupManager{ @Override public String getAgentName(AgentPath agentPath) - throws ObjectNotFoundException { + throws ObjectNotFound { LDAPEntry agentEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(agentPath)); return LDAPLookupUtils.getFirstAttributeValue(agentEntry,"uid"); } -- cgit v1.2.3