From 2495be9ecfa8aea47e285f63b5bb27b0c133b1f8 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 30 Jun 2014 23:03:03 +0200 Subject: Separated modifying Lookup methods into LookupManager, which is only present in a server process. This stops clients trying to write to the directory without relying on their permissions. --- .../com/c2kernel/entity/imports/ImportAgent.java | 2 +- .../com/c2kernel/entity/imports/ImportItem.java | 4 +- .../com/c2kernel/entity/imports/ImportRole.java | 5 +- .../com/c2kernel/entity/proxy/ProxyManager.java | 3 +- .../com/c2kernel/entity/transfer/TransferItem.java | 4 +- .../instance/predefined/AddDomainPath.java | 7 +- .../instance/predefined/RemoveDomainPath.java | 8 +- .../agent/CreateAgentFromDescription.java | 4 +- .../instance/predefined/agent/RemoveAgent.java | 7 +- .../predefined/agent/SetAgentPassword.java | 5 +- .../predefined/item/CreateItemFromDescription.java | 4 +- .../lifecycle/instance/predefined/item/Erase.java | 4 +- .../predefined/server/AddDomainContext.java | 5 +- .../predefined/server/RemoveDomainContext.java | 5 +- src/main/java/com/c2kernel/lookup/Lookup.java | 71 ------------------ .../java/com/c2kernel/lookup/LookupManager.java | 85 ++++++++++++++++++++++ src/main/java/com/c2kernel/lookup/RolePath.java | 14 ++-- src/main/java/com/c2kernel/process/Bootstrap.java | 24 +++--- src/main/java/com/c2kernel/process/Gateway.java | 21 +++++- src/main/java/com/c2kernel/property/Property.java | 6 ++ 20 files changed, 172 insertions(+), 116 deletions(-) create mode 100644 src/main/java/com/c2kernel/lookup/LookupManager.java (limited to 'src') diff --git a/src/main/java/com/c2kernel/entity/imports/ImportAgent.java b/src/main/java/com/c2kernel/entity/imports/ImportAgent.java index 26e3325..2aa6533 100644 --- a/src/main/java/com/c2kernel/entity/imports/ImportAgent.java +++ b/src/main/java/com/c2kernel/entity/imports/ImportAgent.java @@ -36,7 +36,7 @@ public class ImportAgent extends ModuleImport implements java.io.Serializable { newAgent.setAgentName(name); newAgent.setPassword(password); ActiveEntity newAgentEnt = (ActiveEntity)Gateway.getCorbaServer().createEntity(newAgent); - Gateway.getLookup().add(newAgent); + Gateway.getLookupManager().add(newAgent); // assemble properties properties.add(new com.c2kernel.property.Property("Name", name, true)); properties.add(new com.c2kernel.property.Property("Type", "Agent", false)); diff --git a/src/main/java/com/c2kernel/entity/imports/ImportItem.java b/src/main/java/com/c2kernel/entity/imports/ImportItem.java index a27d88d..3847fbf 100644 --- a/src/main/java/com/c2kernel/entity/imports/ImportItem.java +++ b/src/main/java/com/c2kernel/entity/imports/ImportItem.java @@ -79,7 +79,7 @@ public class ImportItem extends ModuleImport { // create item entPath = Gateway.getNextKeyManager().generateNextEntityKey(); newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entPath); - Gateway.getLookup().add(entPath); + Gateway.getLookupManager().add(entPath); } // set the name property @@ -181,7 +181,7 @@ public class ImportItem extends ModuleImport { // register domain path (before collections in case of recursive collections) if (!domPath.exists()) { domPath.setEntity(entPath); - Gateway.getLookup().add(domPath); + Gateway.getLookupManager().add(domPath); } } } diff --git a/src/main/java/com/c2kernel/entity/imports/ImportRole.java b/src/main/java/com/c2kernel/entity/imports/ImportRole.java index 8313c24..5749b06 100644 --- a/src/main/java/com/c2kernel/entity/imports/ImportRole.java +++ b/src/main/java/com/c2kernel/entity/imports/ImportRole.java @@ -1,5 +1,6 @@ package com.c2kernel.entity.imports; +import com.c2kernel.common.CannotManageException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.process.Gateway; @@ -12,8 +13,8 @@ public class ImportRole extends ModuleImport { public ImportRole() { } - public void create(int agentId) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated { - Gateway.getLookup().createRole(name, jobList); + public void create(int agentId) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated, CannotManageException { + Gateway.getLookupManager().createRole(name, jobList); } } diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java index ae02fc5..f65d26e 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java +++ b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java @@ -40,10 +40,11 @@ public class ProxyManager { Logger.msg(5, "ProxyManager - Starting....."); - Iterator servers = Gateway.getLookup().search(new DomainPath("/servers")); + Iterator servers = Gateway.getLookup().search(new DomainPath("/servers"), new Property("Type", "Server")); while(servers.hasNext()) { Path thisServerPath = servers.next(); try { + Logger.msg(thisServerPath.dump()); int syskey = thisServerPath.getSysKey(); String remoteServer = ((Property)Gateway.getStorage().get(syskey, ClusterStorage.PROPERTY+"/Name", null)).getValue(); String portStr = ((Property)Gateway.getStorage().get(syskey, ClusterStorage.PROPERTY+"/ProxyPort", null)).getValue(); diff --git a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java index 9a4cfc5..9852555 100644 --- a/src/main/java/com/c2kernel/entity/transfer/TransferItem.java +++ b/src/main/java/com/c2kernel/entity/transfer/TransferItem.java @@ -91,7 +91,7 @@ public class TransferItem { // create item ItemPath entityPath = new ItemPath(sysKey); TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath); - Gateway.getLookup().add(entityPath); + Gateway.getLookupManager().add(entityPath); PropertyArrayList props = new PropertyArrayList(); Workflow wf = null; @@ -121,7 +121,7 @@ public class TransferItem { // add domPaths for (String element : domainPaths) { DomainPath newPath = new DomainPath(element, entityPath); - Gateway.getLookup().add(newPath); + Gateway.getLookupManager().add(newPath); } } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java index 3da17e9..4c02cbb 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java @@ -15,7 +15,7 @@ import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; -import com.c2kernel.lookup.Lookup; +import com.c2kernel.lookup.LookupManager; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; @@ -31,14 +31,11 @@ public class AddDomainPath extends PredefinedStep protected String runActivityLogic(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws InvalidDataException { - Logger.msg(8,"AddAlias::request()"); - Lookup lookupManager = Gateway.getLookup(); - Logger.msg(1,"AddAlias::request() - Starting."); - try { + LookupManager lookupManager = Gateway.getLookupManager(); DomainPath domainPath = new DomainPath(getDataList(requestData)[0], new ItemPath(itemSysKey)); lookupManager.add(domainPath); Logger.msg(8,"AddDomainPath::request() - systemKey:" + itemSysKey + diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java index 1ee5e8c..df1c44e 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java @@ -11,11 +11,10 @@ package com.c2kernel.lifecycle.instance.predefined; import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; -import com.c2kernel.lookup.Lookup; +import com.c2kernel.lookup.LookupManager; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; @@ -32,7 +31,7 @@ public class RemoveDomainPath extends PredefinedStep int transitionID, String requestData) throws InvalidDataException { Logger.msg(8,"RemoveDomainPath::request()"); - Lookup lookupManager = Gateway.getLookup(); + Logger.msg(1,"RemoveDomainPath::request() - Starting."); @@ -49,10 +48,11 @@ public class RemoveDomainPath extends PredefinedStep throw new InvalidDataException("Domain path "+domainPath.toString()+" is a context.", ""); } try { + LookupManager lookupManager = Gateway.getLookupManager(); lookupManager.delete(domainPath); Logger.msg(8,"AddAlias::request() - context:" + domainPath.toString() + " DONE."); return requestData; - } catch (ObjectCannotBeUpdated ex) { + } catch (Exception ex) { Logger.error(ex); throw new InvalidDataException("Problem updating directory", ""); } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java index 78ef5a9..f311dc1 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -68,7 +68,7 @@ public class CreateAgentFromDescription extends CreateItemFromDescription CorbaServer factory = Gateway.getCorbaServer(); if (factory == null) throw new AccessRightsException("This process cannot create new Items", ""); ActiveEntity newAgent = (ActiveEntity)factory.createEntity(newAgentPath); - Gateway.getLookup().add(newAgentPath); + Gateway.getLookupManager().add(newAgentPath); // initialise it with its properties and workflow @@ -85,7 +85,7 @@ public class CreateAgentFromDescription extends CreateItemFromDescription // add its domain path Logger.msg(3, "CreateItemFromDescription - Creating "+context); context.setEntity(newAgentPath); - Gateway.getLookup().add(context); + Gateway.getLookupManager().add(context); return requestData; } catch (Exception e) { Logger.error(e); diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java index 80281cc..0630f6c 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java @@ -1,5 +1,6 @@ package com.c2kernel.lifecycle.instance.predefined.agent; +import com.c2kernel.common.CannotManageException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; @@ -41,6 +42,8 @@ public class RemoveAgent extends PredefinedStep { } catch (ObjectNotFoundException e) { Logger.error(e); throw new InvalidDataException("Tried to remove "+agentName+" from Role "+role.getName()+" that doesn't exist.", ""); + } catch (CannotManageException e) { + throw new InvalidDataException("Tried to alter roles in a non-server process.", ""); } } @@ -54,8 +57,8 @@ public class RemoveAgent extends PredefinedStep { //remove entity path try { - Gateway.getLookup().delete(targetAgent); - } catch (ObjectCannotBeUpdated e) { + Gateway.getLookupManager().delete(targetAgent); + } catch (Exception e) { throw new InvalidDataException("Error deleting AgentPath for "+agentName, ""); } return requestData; diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java index 102e8e2..09fdefe 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java @@ -2,6 +2,7 @@ package com.c2kernel.lifecycle.instance.predefined.agent; import java.security.NoSuchAlgorithmException; +import com.c2kernel.common.CannotManageException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; @@ -36,7 +37,7 @@ public class SetAgentPassword extends PredefinedStep { throw new InvalidDataException("Requires 1 param: new password", ""); try { - Gateway.getLookup().setAgentPassword(targetAgent, params[0]); + Gateway.getLookupManager().setAgentPassword(targetAgent, params[0]); } catch (ObjectNotFoundException e) { Logger.error(e); throw new InvalidDataException("Agent "+agentName+" not found.", ""); @@ -46,6 +47,8 @@ public class SetAgentPassword extends PredefinedStep { } catch (NoSuchAlgorithmException e) { Logger.error(e); throw new InvalidDataException("Cryptographic libraries for password hashing not found.", ""); + } catch (CannotManageException e) { + throw new InvalidDataException("Cannot set agent password in a non-server process.", ""); } params[1] = "REDACTED"; // censor user's password from outcome diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java index 5d6c0b9..f63c188 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java @@ -89,7 +89,7 @@ public class CreateItemFromDescription extends PredefinedStep CorbaServer factory = Gateway.getCorbaServer(); if (factory == null) throw new AccessRightsException("This process cannot create new Items", ""); TraceableEntity newItem = (TraceableEntity)factory.createEntity(entityPath); - Gateway.getLookup().add(entityPath); + Gateway.getLookupManager().add(entityPath); // initialise it with its properties and workflow @@ -106,7 +106,7 @@ public class CreateItemFromDescription extends PredefinedStep // add its domain path Logger.msg(3, "CreateItemFromDescription - Creating "+context); context.setEntity(entityPath); - Gateway.getLookup().add(context); + Gateway.getLookupManager().add(context); return requestData; } catch (Exception e) { Logger.error(e); diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java index 2e868c4..81eb329 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java @@ -53,14 +53,14 @@ public class Erase extends PredefinedStep DomainPath path = (DomainPath)domPaths.next(); // delete them if (path.getSysKey() == itemSysKey) - Gateway.getLookup().delete(path); + Gateway.getLookupManager().delete(path); } //clear out all storages Gateway.getStorage().removeCluster(itemSysKey, "", null); //remove entity path - Gateway.getLookup().delete(new ItemPath(itemSysKey)); + Gateway.getLookupManager().delete(new ItemPath(itemSysKey)); } catch( Exception ex ) { diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java index a931143..585f96f 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java @@ -2,6 +2,7 @@ package com.c2kernel.lifecycle.instance.predefined.server; import java.util.Stack; +import com.c2kernel.common.CannotManageException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectAlreadyExistsException; import com.c2kernel.common.ObjectCannotBeUpdated; @@ -35,12 +36,14 @@ public class AddDomainContext extends PredefinedStep { while(!pathsToAdd.empty()) { pathToAdd = pathsToAdd.pop(); try { - Gateway.getLookup().add(pathToAdd); + Gateway.getLookupManager().add(pathToAdd); } catch (ObjectAlreadyExistsException e) { Logger.error("Context "+pathToAdd+" inconsistently exists."); } catch (ObjectCannotBeUpdated e) { Logger.error(e); throw new InvalidDataException("Exception adding path "+pathToAdd+": "+e.getMessage(), ""); + } catch (CannotManageException e) { + throw new InvalidDataException("Cannot alter directory in a non-server process", ""); } } return requestData; diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java index a55f7dd..956166a 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java @@ -1,5 +1,6 @@ package com.c2kernel.lifecycle.instance.predefined.server; +import com.c2kernel.common.CannotManageException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; @@ -31,10 +32,12 @@ public class RemoveDomainContext extends PredefinedStep { throw new InvalidDataException("Context "+pathToDelete+" is not empty. Cannot delete.", ""); try { - Gateway.getLookup().delete(pathToDelete); + Gateway.getLookupManager().delete(pathToDelete); } catch (ObjectCannotBeUpdated e) { Logger.error(e); throw new InvalidDataException("Exception deleting path"+pathToDelete+": "+e.getMessage(), ""); + } catch (CannotManageException e) { + throw new InvalidDataException("Cannot alter directory in a non-server process", ""); } return requestData; } diff --git a/src/main/java/com/c2kernel/lookup/Lookup.java b/src/main/java/com/c2kernel/lookup/Lookup.java index 039c368..5384e7c 100644 --- a/src/main/java/com/c2kernel/lookup/Lookup.java +++ b/src/main/java/com/c2kernel/lookup/Lookup.java @@ -1,10 +1,7 @@ package com.c2kernel.lookup; -import java.security.NoSuchAlgorithmException; import java.util.Iterator; -import com.c2kernel.common.ObjectAlreadyExistsException; -import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.process.auth.Authenticator; import com.c2kernel.property.Property; @@ -16,13 +13,6 @@ import com.c2kernel.property.PropertyDescriptionList; */ public interface Lookup { - /** - * Called when a server starts up. The Lookup implementation should ensure that the initial structure of its directory is valid, and create it on first boot. - * - * @throws ObjectNotFoundException When initialization data is not found - */ - public void initializeDirectory() throws ObjectNotFoundException; - /** * Connect to the directory using the credentials supplied in the Authenticator. * @@ -66,24 +56,6 @@ public interface Lookup { */ public org.omg.CORBA.Object resolve(Path path) throws ObjectNotFoundException; - // Path management - - /** - * Register a new a Path in the directory. - * - * @param newPath The path to add - * @throws ObjectCannotBeUpdated When there is an error writing to the directory - * @throws ObjectAlreadyExistsException When the Path has already been registered - */ - public void add(Path newPath) throws ObjectCannotBeUpdated, ObjectAlreadyExistsException; - - /** - * Remove a Path from the directory - * @param path The path to remove - * @throws ObjectCannotBeUpdated When an error occurs writing to the directory - */ - public void delete(Path path) throws ObjectCannotBeUpdated; - // Path finding and searching /** @@ -150,23 +122,6 @@ public interface Lookup { */ public RolePath getRolePath(String roleName) throws ObjectNotFoundException; - /** - * @param role - * @param hasJobList - * @return - * @throws ObjectAlreadyExistsException - * @throws ObjectCannotBeUpdated - */ - public RolePath createRole(String role, boolean hasJobList) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated; - - /** - * @param agent - * @param rolePath - * @throws ObjectCannotBeUpdated - * @throws ObjectNotFoundException - */ - public void addRole(AgentPath agent, RolePath rolePath) throws ObjectCannotBeUpdated, ObjectNotFoundException; - /** * @param rolePath * @return @@ -187,14 +142,6 @@ public interface Lookup { */ public boolean hasRole(AgentPath agentPath, RolePath role); - /** - * @param agent - * @param role - * @throws ObjectCannotBeUpdated - * @throws ObjectNotFoundException - */ - public void removeRole(AgentPath agent, RolePath role) throws ObjectCannotBeUpdated, ObjectNotFoundException; - /** * @param agentPath * @return @@ -202,22 +149,4 @@ public interface Lookup { */ public String getAgentName(AgentPath agentPath) throws ObjectNotFoundException; - /** - * @param agent - * @param newPassword - * @throws ObjectNotFoundException - * @throws ObjectCannotBeUpdated - * @throws NoSuchAlgorithmException - */ - public void setAgentPassword(AgentPath agent, String newPassword) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException; - - /** - * @param role - * @param hasJobList - * @throws ObjectNotFoundException - * @throws ObjectCannotBeUpdated - */ - public void setHasJobList(RolePath role, boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated; - - } diff --git a/src/main/java/com/c2kernel/lookup/LookupManager.java b/src/main/java/com/c2kernel/lookup/LookupManager.java new file mode 100644 index 0000000..ce1268e --- /dev/null +++ b/src/main/java/com/c2kernel/lookup/LookupManager.java @@ -0,0 +1,85 @@ +package com.c2kernel.lookup; + +import java.security.NoSuchAlgorithmException; + +import com.c2kernel.common.ObjectAlreadyExistsException; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFoundException; + +/** + * @author abranson + * + */ +public interface LookupManager extends Lookup { + + /** + * Called when a server starts up. The Lookup implementation should ensure that the initial structure of its directory is valid, and create it on first boot. + * + * @throws ObjectNotFoundException When initialization data is not found + */ + public void initializeDirectory() throws ObjectNotFoundException; + + // Path management + + /** + * Register a new a Path in the directory. + * + * @param newPath The path to add + * @throws ObjectCannotBeUpdated When there is an error writing to the directory + * @throws ObjectAlreadyExistsException When the Path has already been registered + */ + public void add(Path newPath) throws ObjectCannotBeUpdated, ObjectAlreadyExistsException; + + /** + * Remove a Path from the directory + * @param path The path to remove + * @throws ObjectCannotBeUpdated When an error occurs writing to the directory + */ + public void delete(Path path) throws ObjectCannotBeUpdated; + + // Role and agent management + + /** + * @param role + * @param hasJobList + * @return + * @throws ObjectAlreadyExistsException + * @throws ObjectCannotBeUpdated + */ + public RolePath createRole(String role, boolean hasJobList) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated; + + /** + * @param agent + * @param rolePath + * @throws ObjectCannotBeUpdated + * @throws ObjectNotFoundException + */ + public void addRole(AgentPath agent, RolePath rolePath) throws ObjectCannotBeUpdated, ObjectNotFoundException; + + /** + * @param agent + * @param role + * @throws ObjectCannotBeUpdated + * @throws ObjectNotFoundException + */ + public void removeRole(AgentPath agent, RolePath role) throws ObjectCannotBeUpdated, ObjectNotFoundException; + + /** + * @param agent + * @param newPassword + * @throws ObjectNotFoundException + * @throws ObjectCannotBeUpdated + * @throws NoSuchAlgorithmException + */ + public void setAgentPassword(AgentPath agent, String newPassword) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException; + + /** + * @param role + * @param hasJobList + * @throws ObjectNotFoundException + * @throws ObjectCannotBeUpdated + */ + public void setHasJobList(RolePath role, boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated; + + +} diff --git a/src/main/java/com/c2kernel/lookup/RolePath.java b/src/main/java/com/c2kernel/lookup/RolePath.java index bd23991..fa37fb3 100644 --- a/src/main/java/com/c2kernel/lookup/RolePath.java +++ b/src/main/java/com/c2kernel/lookup/RolePath.java @@ -13,6 +13,7 @@ package com.c2kernel.lookup; import java.util.ArrayList; import java.util.Iterator; +import com.c2kernel.common.CannotManageException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.process.Gateway; @@ -51,10 +52,11 @@ public class RolePath extends DomainPath * @param hasJobList The hasJobList to set. * @throws ObjectCannotBeUpdated * @throws ObjectNotFoundException + * @throws CannotManageException */ - public void setHasJobList(boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated { + public void setHasJobList(boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException { this.hasJobList = hasJobList; - Gateway.getLookup().setHasJobList(this, hasJobList); + Gateway.getLookupManager().setHasJobList(this, hasJobList); } @@ -80,12 +82,12 @@ public class RolePath extends DomainPath } } - public void addAgent(AgentPath agent) throws ObjectCannotBeUpdated, ObjectNotFoundException { - Gateway.getLookup().addRole(agent, this); + public void addAgent(AgentPath agent) throws ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException { + Gateway.getLookupManager().addRole(agent, this); } - public void removeAgent(AgentPath agent) throws ObjectCannotBeUpdated, ObjectNotFoundException { - Gateway.getLookup().removeRole(agent, this); + public void removeAgent(AgentPath agent) throws ObjectCannotBeUpdated, CannotManageException, ObjectNotFoundException { + Gateway.getLookupManager().removeRole(agent, this); } @Override diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index f32764c..bc93676 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -23,7 +23,7 @@ import com.c2kernel.lifecycle.instance.stateMachine.Transition; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; import com.c2kernel.lookup.ItemPath; -import com.c2kernel.lookup.Lookup; +import com.c2kernel.lookup.LookupManager; import com.c2kernel.lookup.Path; import com.c2kernel.lookup.RolePath; import com.c2kernel.persistency.ClusterStorage; @@ -117,6 +117,7 @@ public class Bootstrap public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, int layer, boolean reset) throws Exception { if (version == null) version = 0; + LookupManager lookupManager = Gateway.getLookupManager(); ResourceImportHandler typeImpHandler = getHandler(itemType); Logger.msg(1, "Bootstrap.verifyResource() - Verifying version "+version+" of "+typeImpHandler.getName()+" "+itemName); @@ -163,8 +164,8 @@ public class Bootstrap Logger.msg("Module item "+itemName+" found with path "+path.toString()+". Moving to "+modDomPath.toString()); modDomPath.setEntity(new ItemPath(thisProxy.getSystemKey())); if (!modDomPath.exists()) - Gateway.getLookup().add(modDomPath); - Gateway.getLookup().delete(path); + lookupManager.add(modDomPath); + lookupManager.delete(path); } } @@ -252,6 +253,8 @@ public class Bootstrap // create props PropertyDescriptionList pdList = impHandler.getPropDesc(); PropertyArrayList props = new PropertyArrayList(); + LookupManager lookupManager = Gateway.getLookupManager(); + for (int i = 0; i < pdList.list.size(); i++) { PropertyDescription pd = pdList.list.get(i); String propName = pd.getName(); @@ -275,10 +278,10 @@ public class Bootstrap ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey(); Gateway.getCorbaServer().createEntity(entityPath); - Gateway.getLookup().add(entityPath); + lookupManager.add(entityPath); DomainPath newDomPath = impHandler.getPath(itemName, ns); newDomPath.setEntity(entityPath); - Gateway.getLookup().add(newDomPath); + lookupManager.add(newDomPath); ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(entityPath); newItemProxy.initialise( 1, props, ca, null); return newItemProxy; @@ -289,12 +292,14 @@ public class Bootstrap **************************************************************************/ private static void checkAgent(String name, String pass, String role, boolean joblist) throws Exception { Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user."); - Lookup lookup = Gateway.getLookup(); + LookupManager lookup = Gateway.getLookupManager(); + try { systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name))); Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found."); return; } catch (ObjectNotFoundException ex) { } + Logger.msg("Bootstrap.checkAgent() - User '"+name+"' not found. Creating."); RolePath rolePath; @@ -309,7 +314,7 @@ public class Bootstrap AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name); agentPath.setPassword(pass); Gateway.getCorbaServer().createEntity(agentPath); - Gateway.getLookup().add(agentPath); + lookup.add(agentPath); // assign admin role Logger.msg("Bootstrap.checkAgent() - Assigning role '"+role+"'"); @@ -341,6 +346,7 @@ public class Bootstrap } public static void createServerItem() throws Exception { + LookupManager lookupManager = Gateway.getLookupManager(); String serverName = Gateway.getProperties().getProperty("ItemServer.name"); thisServerPath = new DomainPath("/servers/"+serverName); ItemPath serverEntity; @@ -350,9 +356,9 @@ public class Bootstrap Logger.msg("Creating server item "+thisServerPath); serverEntity = Gateway.getNextKeyManager().generateNextEntityKey(); Gateway.getCorbaServer().createEntity(serverEntity); - Gateway.getLookup().add(serverEntity); + lookupManager.add(serverEntity); thisServerPath.setEntity(serverEntity); - Gateway.getLookup().add(thisServerPath); + lookupManager.add(thisServerPath); } Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Name", serverName, false), null); Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server", false), null); diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index 2499bf7..09700d6 100644 --- a/src/main/java/com/c2kernel/process/Gateway.java +++ b/src/main/java/com/c2kernel/process/Gateway.java @@ -9,6 +9,7 @@ import java.net.MalformedURLException; import java.util.Enumeration; import java.util.Properties; +import com.c2kernel.common.CannotManageException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.CorbaServer; @@ -17,6 +18,7 @@ import com.c2kernel.entity.proxy.ProxyManager; import com.c2kernel.entity.proxy.ProxyServer; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.Lookup; +import com.c2kernel.lookup.LookupManager; import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.NextKeyManager; import com.c2kernel.persistency.TransactionManager; @@ -58,6 +60,7 @@ public class Gateway static private org.omg.CORBA.ORB mORB; static private boolean orbDestroyed = false; static private Lookup mLookup; + static private LookupManager mLookupManager = null; static private NextKeyManager mNextKeyManager; static private TransactionManager mStorage; static private ProxyManager mProxyManager; @@ -145,10 +148,16 @@ public class Gateway * * @throws InvalidDataException - error initialising */ - static public void startServer(Authenticator auth) throws InvalidDataException { + static public void startServer(Authenticator auth) throws InvalidDataException, CannotManageException { try { // check top level directory contexts - mLookup.initializeDirectory(); + if (mLookup instanceof LookupManager) { + mLookupManager = (LookupManager)mLookup; + mLookupManager.initializeDirectory(); + } + else { + throw new CannotManageException("Lookup implementation is not a LookupManager. Cannot write to directory"); + } // init next key manager mNextKeyManager = (NextKeyManager)mC2KProps.getInstance("NextKeyManager"); @@ -322,6 +331,14 @@ public class Gateway return mLookup; } + static public LookupManager getLookupManager() throws CannotManageException + { + if (mLookupManager == null) + throw new CannotManageException("No Lookup Manager created. Not a server process.", ""); + else + return mLookupManager; + } + static public CorbaServer getCorbaServer() { return mCorbaServer; diff --git a/src/main/java/com/c2kernel/property/Property.java b/src/main/java/com/c2kernel/property/Property.java index 6b7c4ee..3240b07 100644 --- a/src/main/java/com/c2kernel/property/Property.java +++ b/src/main/java/com/c2kernel/property/Property.java @@ -37,6 +37,12 @@ public class Property implements C2KLocalObject setValue( value ); setMutable( mutable ); } + + public Property( String name, String value) + { + setName( name ); + setValue( value ); + } /************************************************************************** * -- cgit v1.2.3