summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/c2kernel/collection/Dependency.java2
-rw-r--r--src/main/java/com/c2kernel/entity/AgentImplementation.java6
-rw-r--r--src/main/java/com/c2kernel/entity/CorbaServer.java33
-rw-r--r--src/main/java/com/c2kernel/entity/ItemImplementation.java11
-rw-r--r--src/main/java/com/c2kernel/entity/imports/ImportAgent.java2
-rw-r--r--src/main/java/com/c2kernel/entity/imports/ImportItem.java4
-rw-r--r--src/main/java/com/c2kernel/entity/imports/ImportRole.java5
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/ProxyManager.java3
-rw-r--r--src/main/java/com/c2kernel/entity/transfer/TransferItem.java4
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Workflow.java5
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/AddDomainPath.java7
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java170
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java4
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/RemoveDomainPath.java8
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java29
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java95
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java (renamed from src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveAgent.java)29
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java (renamed from src/main/java/com/c2kernel/lifecycle/instance/predefined/server/SetAgentPassword.java)24
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java (renamed from src/main/java/com/c2kernel/lifecycle/instance/predefined/server/SetAgentRoles.java)22
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java183
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java (renamed from src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java)7
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java26
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/server/AddDomainContext.java5
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveDomainContext.java5
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java (renamed from src/main/java/com/c2kernel/lifecycle/instance/predefined/ServerPredefinedStepContainer.java)15
-rw-r--r--src/main/java/com/c2kernel/lookup/Lookup.java141
-rw-r--r--src/main/java/com/c2kernel/lookup/LookupManager.java85
-rw-r--r--src/main/java/com/c2kernel/lookup/Path.java12
-rw-r--r--src/main/java/com/c2kernel/lookup/RolePath.java14
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java95
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java763
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java365
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java97
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java81
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPProperties.java38
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPPropertyManager.java141
-rw-r--r--src/main/java/com/c2kernel/persistency/ClusterStorage.java387
-rw-r--r--src/main/java/com/c2kernel/persistency/ClusterStorageManager.java16
-rw-r--r--src/main/java/com/c2kernel/persistency/LDAPClientReader.java43
-rw-r--r--src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java176
-rw-r--r--src/main/java/com/c2kernel/persistency/NextKeyManager.java27
-rw-r--r--src/main/java/com/c2kernel/persistency/TransactionManager.java10
-rw-r--r--src/main/java/com/c2kernel/process/AbstractMain.java19
-rw-r--r--src/main/java/com/c2kernel/process/Bootstrap.java43
-rw-r--r--src/main/java/com/c2kernel/process/ClientShell.java2
-rw-r--r--src/main/java/com/c2kernel/process/Gateway.java42
-rw-r--r--src/main/java/com/c2kernel/process/ShutdownHandler.java6
-rw-r--r--src/main/java/com/c2kernel/process/StandardClient.java5
-rw-r--r--src/main/java/com/c2kernel/process/StandardServer.java91
-rw-r--r--src/main/java/com/c2kernel/process/auth/Authenticator.java71
-rw-r--r--src/main/java/com/c2kernel/process/auth/ProxyLogin.java15
-rw-r--r--src/main/java/com/c2kernel/process/module/Module.java3
-rw-r--r--src/main/java/com/c2kernel/property/Property.java6
-rw-r--r--src/main/java/com/c2kernel/scripting/ScriptConsole.java5
-rw-r--r--src/main/java/com/c2kernel/utils/CastorXMLUtility.java6
-rw-r--r--src/main/java/com/c2kernel/utils/Logger.java7
56 files changed, 1105 insertions, 2411 deletions
diff --git a/src/main/java/com/c2kernel/collection/Dependency.java b/src/main/java/com/c2kernel/collection/Dependency.java
index c90fa9d..4fb4f70 100644
--- a/src/main/java/com/c2kernel/collection/Dependency.java
+++ b/src/main/java/com/c2kernel/collection/Dependency.java
@@ -61,7 +61,7 @@ public class Dependency extends Parent2ChildCollection<DependencyMember>
// create member object
DependencyMember depMember = new DependencyMember();
depMember.setID(getCounter());
- depMember.setProperties(mProperties);
+ depMember.setProperties((CastorHashMap)mProperties.clone());
depMember.setClassProps(mClassProps);
// assign entity
diff --git a/src/main/java/com/c2kernel/entity/AgentImplementation.java b/src/main/java/com/c2kernel/entity/AgentImplementation.java
index 8010114..7f38f13 100644
--- a/src/main/java/com/c2kernel/entity/AgentImplementation.java
+++ b/src/main/java/com/c2kernel/entity/AgentImplementation.java
@@ -6,6 +6,8 @@ import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.agent.JobArrayList;
import com.c2kernel.entity.agent.JobList;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
+import com.c2kernel.lifecycle.instance.predefined.agent.AgentPredefinedStepContainer;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidItemPathException;
import com.c2kernel.lookup.RolePath;
@@ -75,4 +77,8 @@ public class AgentImplementation extends ItemImplementation implements
}
}
+ @Override
+ protected PredefinedStepContainer getNewPredefStepContainer() {
+ return new AgentPredefinedStepContainer();
+ }
}
diff --git a/src/main/java/com/c2kernel/entity/CorbaServer.java b/src/main/java/com/c2kernel/entity/CorbaServer.java
index 3a01ed7..60c10a8 100644
--- a/src/main/java/com/c2kernel/entity/CorbaServer.java
+++ b/src/main/java/com/c2kernel/entity/CorbaServer.java
@@ -117,29 +117,28 @@ public class CorbaServer {
/**************************************************************************
* Returns a CORBA servant for a pre-existing entity
**************************************************************************/
- private Servant getEntity(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
+ private Servant getItem(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
try {
- ItemPath entityPath = new ItemPath(sysKey);
- Servant entity = null;
+ ItemPath itemPath = Gateway.getLookup().getItemPath(sysKey);
+ Servant item = null;
synchronized (mEntityCache) {
- entity = mEntityCache.get(entityPath);
- if (entity == null) {
+ item = mEntityCache.get(itemPath);
+ if (item == null) {
Logger.msg(7, "Creating new servant for "+sysKey);
- Class<?> entityClass = Gateway.getLookup().getItemClass(entityPath);
-
- if (entityClass == TraceableEntity.class) {
- if (poa == null) poa = mItemPOA;
- entity = new TraceableEntity(sysKey, poa);
- }
- else if (entityClass == ActiveEntity.class) {
+ if (itemPath instanceof AgentPath) {
if (poa == null) poa = mAgentPOA;
- entity = new ActiveEntity(sysKey, poa);
+ item = new ActiveEntity(sysKey, poa);
+ }
+ else if (itemPath instanceof ItemPath) {
+ if (poa == null) poa = mItemPOA;
+ item = new TraceableEntity(sysKey, poa);
}
- mEntityCache.put(entityPath, entity);
+
+ mEntityCache.put(itemPath, item);
}
}
- return entity;
+ return item;
} catch (InvalidItemPathException ex) {
throw new ObjectNotFoundException("Invalid Entity Key", "");
@@ -150,14 +149,14 @@ public class CorbaServer {
* Wrapper for fetching Items
**************************************************************************/
public TraceableEntity getItem(int sysKey) throws ObjectNotFoundException {
- return (TraceableEntity)getEntity(sysKey, mItemPOA);
+ return (TraceableEntity)getItem(sysKey, mItemPOA);
}
/**************************************************************************
* Wrapper for fetching Agents
**************************************************************************/
public ActiveEntity getAgent(int sysKey) throws ObjectNotFoundException {
- return (ActiveEntity)getEntity(sysKey, mAgentPOA);
+ return (ActiveEntity)getItem(sysKey, mAgentPOA);
}
/**
diff --git a/src/main/java/com/c2kernel/entity/ItemImplementation.java b/src/main/java/com/c2kernel/entity/ItemImplementation.java
index b12e105..9aa4f9b 100644
--- a/src/main/java/com/c2kernel/entity/ItemImplementation.java
+++ b/src/main/java/com/c2kernel/entity/ItemImplementation.java
@@ -11,6 +11,8 @@ import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.agent.JobArrayList;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
+import com.c2kernel.lifecycle.instance.predefined.item.ItemPredefinedStepContainer;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.InvalidItemPathException;
import com.c2kernel.persistency.ClusterStorage;
@@ -75,10 +77,10 @@ public class ItemImplementation implements ItemOperations {
try {
Workflow lc = null;
if (initWfString == null || initWfString.length() == 0)
- lc = new Workflow(new CompositeActivity());
+ lc = new Workflow(new CompositeActivity(), getNewPredefStepContainer());
else
lc = new Workflow((CompositeActivity) Gateway
- .getMarshaller().unmarshall(initWfString));
+ .getMarshaller().unmarshall(initWfString), getNewPredefStepContainer());
lc.initialise(mSystemKey, agentPath);
mStorage.put(mSystemKey, lc, locker);
} catch (Throwable ex) {
@@ -112,6 +114,11 @@ public class ItemImplementation implements ItemOperations {
}
+ protected PredefinedStepContainer getNewPredefStepContainer() {
+
+ return new ItemPredefinedStepContainer();
+ }
+
@Override
public String requestAction(int agentId, String stepPath, int transitionID,
String requestData) throws AccessRightsException,
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 2b2e0e9..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<Path> servers = Gateway.getLookup().searchEntities(new DomainPath("/servers"));
+ Iterator<Path> 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/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java
index 8ff2fe2..451d7fd 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java
@@ -48,12 +48,11 @@ public class Workflow extends CompositeActivity implements C2KLocalObject
{
}
- public Workflow(CompositeActivity domain) {
+ public Workflow(CompositeActivity domain, PredefinedStepContainer predef) {
this();
domain.setName("domain");
initChild(domain, true, new GraphPoint(150, 100));
- PredefinedStepContainer act = new PredefinedStepContainer();
- addChild(act, new GraphPoint(300, 100));
+ addChild(predef, new GraphPoint(300, 100));
}
public History getHistory() throws InvalidDataException {
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/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java
deleted file mode 100644
index e16a92c..0000000
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/CreateItemFromDescription.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**************************************************************************
- * CreateItemFromDescription
- *
- * $Workfile$
- * $Revision: 1.47 $
- * $Date: 2005/10/13 08:13:58 $
- *
- * Copyright (C) 2001 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-package com.c2kernel.lifecycle.instance.predefined;
-
-import java.util.ArrayList;
-
-import com.c2kernel.collection.Collection;
-import com.c2kernel.collection.CollectionArrayList;
-import com.c2kernel.collection.CollectionDescription;
-import com.c2kernel.collection.CollectionMember;
-import com.c2kernel.common.AccessRightsException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.CorbaServer;
-import com.c2kernel.entity.TraceableEntity;
-import com.c2kernel.lifecycle.CompositeActivityDef;
-import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.persistency.ClusterStorage;
-import com.c2kernel.persistency.TransactionManager;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.property.Property;
-import com.c2kernel.property.PropertyArrayList;
-import com.c2kernel.property.PropertyDescriptionList;
-import com.c2kernel.property.PropertyUtility;
-import com.c2kernel.utils.LocalObjectLoader;
-import com.c2kernel.utils.Logger;
-
-/**************************************************************************
- *
- * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $
- * @version $Revision: 1.47 $
- **************************************************************************/
-public class CreateItemFromDescription extends PredefinedStep
-{
- public CreateItemFromDescription()
- {
- super();
- }
-
- //requestdata is xmlstring
- @Override
- protected String runActivityLogic(AgentPath agent, int itemSysKey,
- int transitionID, String requestData) throws InvalidDataException {
-
- String[] input = getDataList(requestData);
- String newName = input[0];
- String domPath = input[1];
- CompositeActivityDef wfDef;
- String wfDefName = null;
- int wfDefVer = -1;
- if (input.length > 2) // override wf
- wfDefName = input[2];
-
- PropertyArrayList props = new PropertyArrayList();
- Logger.msg(1, "AddNewItem::request() - Starting.");
- TransactionManager storage = Gateway.getStorage();
-
- try {
- // check if the path is already taken
- DomainPath context = new DomainPath(new DomainPath(domPath), newName);
- Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString());
- if (context.getSysKey()!=-1)
- throw new ObjectAlreadyExistsException("The item name " +newName+ " exists already.", "");
-
- // get init objects
-
- // loop through collections, collecting instantiated descriptions and finding the default workflow def
- CollectionArrayList colls = new CollectionArrayList();
- String[] collNames = storage.getClusterContents(itemSysKey, ClusterStorage.COLLECTION);
- for (String collName : collNames) {
- Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>)storage.get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
- if (thisCol instanceof CollectionDescription) {
- CollectionDescription<? extends CollectionMember> thisDesc = (CollectionDescription<? extends CollectionMember>)thisCol;
- colls.put(thisDesc.newInstance());
- }
- else if (thisCol.getName().equalsIgnoreCase("workflow") && wfDefName == null) {
- ArrayList<? extends CollectionMember> members = thisCol.getMembers().list;
- // get the first member from the wf collection
- CollectionMember wfMember = members.get(0);
- wfDefName = wfMember.resolveItem().getName();
- Object wfVerObj = wfMember.getProperties().get("Version");
- try {
- wfDefVer = Integer.parseInt(wfVerObj.toString());
- } catch (NumberFormatException ex) {
- throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), "");
- }
- }
- }
-
- // load workflow def
- if (wfDefName == null)
- throw new InvalidDataException("No workflow given or defined", "");
- if (wfDefVer == -1)
- throw new InvalidDataException("No workflow def version given","");
-
- try {
- wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, wfDefVer);
- } catch (ObjectNotFoundException ex) {
- throw new InvalidDataException("Workflow def '"+wfDefName+"' item not found", "");
- } catch (ClassCastException ex) {
- throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite", "");
- }
-
-
- // copy properties -- intend to create from propdesc
- PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemSysKey);
- props = pdList.instanciate();
- // set Name prop or create if not present
- boolean foundName = false;
- for (Property prop : props.list) {
- if (prop.getName().equals("Name")) {
- foundName = true;
- prop.setValue(newName);
- }
- }
- if (!foundName) props.list.add(new Property("Name", newName, true));
- props.list.add( new Property("Creator", agent.getAgentName(), false));
-
- /* ITEM CREATION */
-
- // generate new entity key
- Logger.msg(6, "CreateItemFromDescription - Requesting new sysKey");
- ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
-
- // resolve the item factory
- Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
-
- // create the Item object
- Logger.msg(3, "CreateItemFromDescription - Creating Item");
- 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);
-
-
- // initialise it with its properties and workflow
-
- Logger.msg(3, "CreateItemFromDescription - Initializing Item");
-
- newItem.initialise(
- agent.getSysKey(),
- Gateway.getMarshaller().marshall(props),
- Gateway.getMarshaller().marshall(wfDef.instantiate()),
- Gateway.getMarshaller().marshall(colls)
- );
-
- // add its domain path
- Logger.msg(3, "CreateItemFromDescription - Creating "+context);
- context.setEntity(entityPath);
- Gateway.getLookup().add(context);
- return requestData;
- } catch (Exception e) {
- Logger.error(e);
- throw new InvalidDataException(e.getMessage(), "");
- }
-
- }
-}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java
index 43cc8ca..81d70ce 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/PredefinedStepContainer.java
@@ -1,7 +1,7 @@
package com.c2kernel.lifecycle.instance.predefined;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.lifecycle.instance.CompositeActivity;
-public class PredefinedStepContainer extends CompositeActivity
+public abstract class PredefinedStepContainer extends CompositeActivity
{
protected int num = 0;
@@ -14,7 +14,6 @@ public class PredefinedStepContainer extends CompositeActivity
}
public void createChildren()
{
- predInit("CreateItemFromDescription", "Create a new item using this item as its description", new CreateItemFromDescription());
predInit("AddDomainPath", "Adds a new path to this entity in the LDAP domain tree", new AddDomainPath());
predInit("RemoveDomainPath", "Removes an existing path to this Entity from the LDAP domain tree", new RemoveDomainPath());
predInit("ReplaceDomainWorkflow", "Replaces the domain CA with the supplied one. Used by the GUI to save new Wf layout", new ReplaceDomainWorkflow());
@@ -27,7 +26,6 @@ public class PredefinedStepContainer extends CompositeActivity
predInit("ClearSlot", "Clears an aggregation member slot, given a slot no or entity key", new ClearSlot());
predInit("RemoveSlotFromCollection", "Removed the given slot from the aggregation", new RemoveSlotFromCollection());
predInit("AddMemberToCollection", "Creates a new member slot for the given item in a dependency, and assigns the item", new AddMemberToCollection());
- predInit("Erase", "Deletes all objects and domain paths for this item.", new Erase());
predInit("Import", "Imports an outcome into the Item, with a given schema and viewpoint", new Import());
}
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/AgentPredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java
new file mode 100644
index 0000000..2b9acbc
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/AgentPredefinedStepContainer.java
@@ -0,0 +1,29 @@
+package com.c2kernel.lifecycle.instance.predefined.agent;
+
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
+import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription;
+
+
+/**************************************************************************
+ *
+ * $Revision: 1.2 $
+ * $Date: 2005/06/02 10:19:33 $
+ *
+ * Copyright (C) 2003 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+// public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/06/02 10:19:33 $ $Author: abranson $";
+public class AgentPredefinedStepContainer extends PredefinedStepContainer {
+
+
+ @Override
+ public void createChildren()
+ {
+ super.createChildren();
+ predInit("CreateItemFromDescription", "Create a new item using this item as its description", new CreateItemFromDescription());
+ predInit("RemoveAgent", "Deletes the Agent", new RemoveAgent());
+ predInit("SetAgentPassword", "Changes the Agent's password", new SetAgentPassword());
+ predInit("SetAgentRoles", "Sets the roles of the Agent", new SetAgentRoles());
+ }
+}
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
new file mode 100644
index 0000000..f311dc1
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
@@ -0,0 +1,95 @@
+/**************************************************************************
+ * CreateItemFromDescription
+ *
+ * $Workfile$
+ * $Revision: 1.47 $
+ * $Date: 2005/10/13 08:13:58 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+package com.c2kernel.lifecycle.instance.predefined.agent;
+
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.entity.CorbaServer;
+import com.c2kernel.entity.agent.ActiveEntity;
+import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.utils.Logger;
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $
+ * @version $Revision: 1.47 $
+ **************************************************************************/
+public class CreateAgentFromDescription extends CreateItemFromDescription
+{
+ public CreateAgentFromDescription()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
+ String[] input = getDataList(requestData);
+ String newName = input[0];
+ String domPath = input[1];
+ String wfDefName = null;
+ int wfDefVer = -1;
+ if (input.length > 2) // override wf
+ wfDefName = input[2];
+
+ Logger.msg(1, "CreateAgentFromDescription::request() - Starting.");
+
+ try {
+ // check if the path is already taken
+ DomainPath context = new DomainPath(new DomainPath(domPath), newName);
+ Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString());
+ if (context.getSysKey()!=-1)
+ throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", "");
+
+ // generate new entity key
+ Logger.msg(6, "CreateItemFromDescription - Requesting new sysKey");
+ AgentPath newAgentPath = Gateway.getNextKeyManager().generateNextAgentKey();
+
+ // resolve the item factory
+ Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
+
+ // create the Item object
+ Logger.msg(3, "CreateItemFromDescription - Creating Item");
+ CorbaServer factory = Gateway.getCorbaServer();
+ if (factory == null) throw new AccessRightsException("This process cannot create new Items", "");
+ ActiveEntity newAgent = (ActiveEntity)factory.createEntity(newAgentPath);
+ Gateway.getLookupManager().add(newAgentPath);
+
+
+ // initialise it with its properties and workflow
+
+ Logger.msg(3, "CreateItemFromDescription - Initializing Item");
+
+ newAgent.initialise(
+ agent.getSysKey(),
+ Gateway.getMarshaller().marshall(getNewProperties(itemSysKey, newName, agent)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey, wfDefName, wfDefVer)),
+ Gateway.getMarshaller().marshall(getNewCollections(itemSysKey))
+ );
+
+ // add its domain path
+ Logger.msg(3, "CreateItemFromDescription - Creating "+context);
+ context.setEntity(newAgentPath);
+ Gateway.getLookupManager().add(context);
+ return requestData;
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidDataException(e.getMessage(), "");
+ }
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java
index 19641fe..0630f6c 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveAgent.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java
@@ -1,10 +1,12 @@
-package com.c2kernel.lifecycle.instance.predefined.server;
+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;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.InvalidItemPathException;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
@@ -22,37 +24,42 @@ public class RemoveAgent extends PredefinedStep {
Logger.msg(1, "RemoveAgent::request() - Starting.");
- String[] params = getDataList(requestData);
AgentPath targetAgent;
try {
- targetAgent = Gateway.getLookup().getAgentPath(params[0]);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Agent "+params[0]+" not found", "");
+ targetAgent = new AgentPath(itemSysKey);
+ } catch (InvalidItemPathException ex) {
+ throw new InvalidDataException("Could not resolve syskey "+itemSysKey+" as an Agent.");
}
+ String agentName = targetAgent.getAgentName();
+
//remove from roles
for (RolePath role: targetAgent.getRoles()) {
try {
role.removeAgent(targetAgent);
} catch (ObjectCannotBeUpdated e) {
Logger.error(e);
- throw new InvalidDataException("Error removing "+params[0]+" from Role "+role.getName(), "");
+ throw new InvalidDataException("Error removing "+agentName+" from Role "+role.getName(), "");
} catch (ObjectNotFoundException e) {
Logger.error(e);
- throw new InvalidDataException("Tried to remove "+params[0]+" from Role "+role.getName()+" that doesn't exist.", "");
+ 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.", "");
}
}
+
//clear out all storages
try {
Gateway.getStorage().removeCluster(targetAgent.getSysKey(), "", null);
} catch (ClusterStorageException e) {
Logger.error(e);
- throw new InvalidDataException("Error deleting storage for "+params[0], "");
+ throw new InvalidDataException("Error deleting storage for "+agentName, "");
}
+
//remove entity path
try {
- Gateway.getLookup().delete(targetAgent);
- } catch (ObjectCannotBeUpdated e) {
- throw new InvalidDataException("Error deleting AgentPath for "+params[0], "");
+ 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/server/SetAgentPassword.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java
index 8a2863a..09fdefe 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/SetAgentPassword.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentPassword.java
@@ -1,12 +1,14 @@
-package com.c2kernel.lifecycle.instance.predefined.server;
+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;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.InvalidItemPathException;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -22,27 +24,31 @@ public class SetAgentPassword extends PredefinedStep {
Logger.msg(1, "SetAgentPassword::request() - Starting.");
- String[] params = getDataList(requestData);
- if (params.length!=2)
- throw new InvalidDataException("Requires 2 params: agent name and new password", "");
AgentPath targetAgent;
try {
- targetAgent = Gateway.getLookup().getAgentPath(params[0]);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Agent "+params[0]+" not found", "");
+ targetAgent = new AgentPath(itemSysKey);
+ } catch (InvalidItemPathException ex) {
+ throw new InvalidDataException("Could not resolve syskey "+itemSysKey+" as an Agent.");
}
+ String agentName = targetAgent.getAgentName();
+
+ String[] params = getDataList(requestData);
+ if (params.length!=1)
+ throw new InvalidDataException("Requires 1 param: new password", "");
try {
- Gateway.getLookup().setAgentPassword(targetAgent, params[1]);
+ Gateway.getLookupManager().setAgentPassword(targetAgent, params[0]);
} catch (ObjectNotFoundException e) {
Logger.error(e);
- throw new InvalidDataException("Agent "+params[0]+" not found.", "");
+ throw new InvalidDataException("Agent "+agentName+" not found.", "");
} catch (ObjectCannotBeUpdated e) {
Logger.error(e);
throw new InvalidDataException("Error updating LDAP entry.", "");
} 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/server/SetAgentRoles.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java
index 19c6bd8..8bcba30 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/SetAgentRoles.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java
@@ -1,4 +1,4 @@
-package com.c2kernel.lifecycle.instance.predefined.server;
+package com.c2kernel.lifecycle.instance.predefined.agent;
import java.util.ArrayList;
@@ -6,6 +6,7 @@ import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.InvalidItemPathException;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -25,20 +26,19 @@ public class SetAgentRoles extends PredefinedStep {
String[] params = getDataList(requestData);
AgentPath targetAgent;
try {
- targetAgent = Gateway.getLookup().getAgentPath(params[0]);
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Agent "+params[0]+" not found", "");
+ targetAgent = new AgentPath(itemSysKey);
+ } catch (InvalidItemPathException ex) {
+ throw new InvalidDataException("Could not resolve syskey "+itemSysKey+" as an Agent.");
}
RolePath[] currentRoles = targetAgent.getRoles();
ArrayList<RolePath> requestedRoles = new ArrayList<RolePath>();
- if (params.length>1)
- for (int i=1; i<params.length; i++)
- try {
- requestedRoles.add(Gateway.getLookup().getRolePath(params[i]));
- } catch (ObjectNotFoundException e) {
- throw new InvalidDataException("Role "+params[i]+" not found", "");
- }
+ for (int i=0; i<params.length; i++)
+ try {
+ requestedRoles.add(Gateway.getLookup().getRolePath(params[i]));
+ } catch (ObjectNotFoundException e) {
+ throw new InvalidDataException("Role "+params[i]+" not found", "");
+ }
ArrayList<RolePath> rolesToRemove = new ArrayList<RolePath>();
for (RolePath existingRole : currentRoles) { //
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
new file mode 100644
index 0000000..f63c188
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java
@@ -0,0 +1,183 @@
+/**************************************************************************
+ * CreateItemFromDescription
+ *
+ * $Workfile$
+ * $Revision: 1.47 $
+ * $Date: 2005/10/13 08:13:58 $
+ *
+ * Copyright (C) 2001 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+package com.c2kernel.lifecycle.instance.predefined.item;
+
+import java.util.ArrayList;
+
+import com.c2kernel.collection.Collection;
+import com.c2kernel.collection.CollectionArrayList;
+import com.c2kernel.collection.CollectionDescription;
+import com.c2kernel.collection.CollectionMember;
+import com.c2kernel.common.AccessRightsException;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.CorbaServer;
+import com.c2kernel.entity.TraceableEntity;
+import com.c2kernel.lifecycle.CompositeActivityDef;
+import com.c2kernel.lifecycle.instance.CompositeActivity;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.property.Property;
+import com.c2kernel.property.PropertyArrayList;
+import com.c2kernel.property.PropertyDescriptionList;
+import com.c2kernel.property.PropertyUtility;
+import com.c2kernel.utils.LocalObjectLoader;
+import com.c2kernel.utils.Logger;
+
+/**************************************************************************
+ *
+ * @author $Author: abranson $ $Date: 2005/10/13 08:13:58 $
+ * @version $Revision: 1.47 $
+ **************************************************************************/
+public class CreateItemFromDescription extends PredefinedStep
+{
+ public CreateItemFromDescription()
+ {
+ super();
+ }
+
+ //requestdata is xmlstring
+ @Override
+ protected String runActivityLogic(AgentPath agent, int itemSysKey,
+ int transitionID, String requestData) throws InvalidDataException {
+
+ String[] input = getDataList(requestData);
+ String newName = input[0];
+ String domPath = input[1];
+ String wfDefName = null;
+ int wfDefVer = -1;
+ if (input.length > 2) // override wf
+ wfDefName = input[2];
+
+ Logger.msg(1, "CreateItemFromDescription - Starting.");
+
+ try {
+ // check if the path is already taken
+ DomainPath context = new DomainPath(new DomainPath(domPath), newName);
+ Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString());
+ if (context.getSysKey()!=-1)
+ throw new ObjectAlreadyExistsException("The item name " +newName+ " exists already.", "");
+
+ // get init objects
+
+ /* ITEM CREATION */
+
+ // generate new entity key
+ Logger.msg(6, "CreateItemFromDescription - Requesting new sysKey");
+ ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
+
+ // resolve the item factory
+ Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
+
+ // create the Item object
+ Logger.msg(3, "CreateItemFromDescription - Creating Item");
+ CorbaServer factory = Gateway.getCorbaServer();
+ if (factory == null) throw new AccessRightsException("This process cannot create new Items", "");
+ TraceableEntity newItem = (TraceableEntity)factory.createEntity(entityPath);
+ Gateway.getLookupManager().add(entityPath);
+
+
+ // initialise it with its properties and workflow
+
+ Logger.msg(3, "CreateItemFromDescription - Initializing Item");
+
+ newItem.initialise(
+ agent.getSysKey(),
+ Gateway.getMarshaller().marshall(getNewProperties(itemSysKey, newName, agent)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey, wfDefName, wfDefVer)),
+ Gateway.getMarshaller().marshall(getNewCollections(itemSysKey))
+ );
+
+ // add its domain path
+ Logger.msg(3, "CreateItemFromDescription - Creating "+context);
+ context.setEntity(entityPath);
+ Gateway.getLookupManager().add(context);
+ return requestData;
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidDataException(e.getMessage(), "");
+ }
+
+ }
+
+ protected PropertyArrayList getNewProperties(int itemSysKey, String newName, AgentPath agent) throws ObjectNotFoundException {
+ // copy properties -- intend to create from propdesc
+ PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemSysKey);
+ PropertyArrayList props = pdList.instanciate();
+ // set Name prop or create if not present
+ boolean foundName = false;
+ for (Property prop : props.list) {
+ if (prop.getName().equals("Name")) {
+ foundName = true;
+ prop.setValue(newName);
+ }
+ }
+ if (!foundName) props.list.add(new Property("Name", newName, true));
+ props.list.add( new Property("Creator", agent.getAgentName(), false));
+ return props;
+ }
+
+ protected CompositeActivity getNewWorkflow(int itemSysKey, String wfDefName, int wfDefVer) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException {
+ // loop through collections, collecting instantiated descriptions and finding the default workflow def
+ String[] collNames = Gateway.getStorage().getClusterContents(itemSysKey, ClusterStorage.COLLECTION);
+ for (String collName : collNames) {
+ if (collName.equalsIgnoreCase("workflow") && wfDefName == null) {
+ Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>)Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
+ ArrayList<? extends CollectionMember> members = thisCol.getMembers().list;
+ // get the first member from the wf collection
+ CollectionMember wfMember = members.get(0);
+ wfDefName = wfMember.resolveItem().getName();
+ Object wfVerObj = wfMember.getProperties().get("Version");
+ try {
+ wfDefVer = Integer.parseInt(wfVerObj.toString());
+ } catch (NumberFormatException ex) {
+ throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), "");
+ }
+ }
+ }
+
+ // load workflow def
+ if (wfDefName == null)
+ throw new InvalidDataException("No workflow given or defined", "");
+ if (wfDefVer == -1)
+ throw new InvalidDataException("No workflow def version given","");
+
+ try {
+ CompositeActivityDef wfDef = (CompositeActivityDef)LocalObjectLoader.getActDef(wfDefName, wfDefVer);
+ return (CompositeActivity)wfDef.instantiate();
+ } catch (ObjectNotFoundException ex) {
+ throw new InvalidDataException("Workflow def '"+wfDefName+"' item not found", "");
+ } catch (ClassCastException ex) {
+ throw new InvalidDataException("Activity def '"+wfDefName+"' was not Composite", "");
+ }
+ }
+
+ protected CollectionArrayList getNewCollections(int itemSysKey) throws ClusterStorageException, ObjectNotFoundException {
+ // loop through collections, collecting instantiated descriptions and finding the default workflow def
+ CollectionArrayList colls = new CollectionArrayList();
+ String[] collNames = Gateway.getStorage().getClusterContents(itemSysKey, ClusterStorage.COLLECTION);
+ for (String collName : collNames) {
+ Collection<? extends CollectionMember> thisCol = (Collection<? extends CollectionMember>)Gateway.getStorage().get(itemSysKey, ClusterStorage.COLLECTION+"/"+collName, null);
+ if (thisCol instanceof CollectionDescription) {
+ CollectionDescription<? extends CollectionMember> thisDesc = (CollectionDescription<? extends CollectionMember>)thisCol;
+ colls.put(thisDesc.newInstance());
+ }
+ }
+ return colls;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java
index 3c4a6a7..81eb329 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/Erase.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/Erase.java
@@ -9,13 +9,14 @@
* All rights reserved.
**************************************************************************/
-package com.c2kernel.lifecycle.instance.predefined;
+package com.c2kernel.lifecycle.instance.predefined.item;
import java.util.Iterator;
import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.ItemPath;
@@ -52,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/item/ItemPredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java
new file mode 100644
index 0000000..4cb93e2
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/ItemPredefinedStepContainer.java
@@ -0,0 +1,26 @@
+package com.c2kernel.lifecycle.instance.predefined.item;
+
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
+
+
+/**************************************************************************
+ *
+ * $Revision: 1.2 $
+ * $Date: 2005/06/02 10:19:33 $
+ *
+ * Copyright (C) 2003 CERN - European Organization for Nuclear Research
+ * All rights reserved.
+ **************************************************************************/
+
+// public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/06/02 10:19:33 $ $Author: abranson $";
+public class ItemPredefinedStepContainer extends PredefinedStepContainer {
+
+
+ @Override
+ public void createChildren()
+ {
+ super.createChildren();
+ predInit("CreateItemFromDescription", "Create a new item using this item as its description", new CreateItemFromDescription());
+ predInit("Erase", "Deletes all objects and domain paths for this item.", new Erase());
+ }
+}
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/lifecycle/instance/predefined/ServerPredefinedStepContainer.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java
index 32cf7b2..412c468 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/ServerPredefinedStepContainer.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/ServerPredefinedStepContainer.java
@@ -1,13 +1,8 @@
-package com.c2kernel.lifecycle.instance.predefined;
+package com.c2kernel.lifecycle.instance.predefined.server;
import com.c2kernel.graph.model.GraphPoint;
-import com.c2kernel.lifecycle.instance.predefined.server.AddDomainContext;
-import com.c2kernel.lifecycle.instance.predefined.server.CreateNewAgent;
-import com.c2kernel.lifecycle.instance.predefined.server.CreateNewItem;
-import com.c2kernel.lifecycle.instance.predefined.server.RemoveAgent;
-import com.c2kernel.lifecycle.instance.predefined.server.RemoveDomainContext;
-import com.c2kernel.lifecycle.instance.predefined.server.SetAgentPassword;
-import com.c2kernel.lifecycle.instance.predefined.server.SetAgentRoles;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
/**************************************************************************
*
@@ -30,10 +25,6 @@ public class ServerPredefinedStepContainer extends PredefinedStepContainer {
serverPredInit("CreateNewAgent", "Creates a new Agent in this Server without description.", new CreateNewAgent());
serverPredInit("RemoveDomainContext", "Deletes an existing context in the domain tree, but only if empty", new RemoveDomainContext());
serverPredInit("AddDomainContext", "Creates an empty domain context in the tree", new AddDomainContext());
- //TODO: remove the following when agents have workflows
- serverPredInit("RemoveAgent", "Deletes the named Agent in this Server.", new RemoveAgent());
- serverPredInit("SetAgentPassword", "Changes the named Agent's password in this Server.", new SetAgentPassword());
- serverPredInit("SetAgentRoles", "Sets the roles of the named Agent.", new SetAgentRoles());
}
public void serverPredInit(String alias, String Description, PredefinedStep act)
diff --git a/src/main/java/com/c2kernel/lookup/Lookup.java b/src/main/java/com/c2kernel/lookup/Lookup.java
index 026ad19..5384e7c 100644
--- a/src/main/java/com/c2kernel/lookup/Lookup.java
+++ b/src/main/java/com/c2kernel/lookup/Lookup.java
@@ -1,77 +1,152 @@
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;
import com.c2kernel.property.PropertyDescriptionList;
+/**
+ * @author abranson
+ *
+ */
public interface Lookup {
- public void initializeDirectory() throws ObjectNotFoundException;
-
+ /**
+ * Connect to the directory using the credentials supplied in the Authenticator.
+ *
+ * @param user The connected Authenticator. The Lookup implementation may use the AuthObject in this to communicate with the database.
+ */
public void open(Authenticator user);
+ /**
+ * Shutdown the lookup
+ */
public void close();
// Path resolution
+ /**
+ * Fetch the correct subclass class of ItemPath for a particular Item, derived from its lookup entry.
+ * This is used by the CORBA Server to make sure the correct Item subclass is used.
+ *
+ * @param sysKey The system key of the Item
+ * @return an ItemPath or AgentPath
+ * @throws InvalidItemPathException When the system key is invalid/out-of-range
+ * @throws ObjectNotFoundException When the Item does not exist in the directory.
+ */
+ public ItemPath getItemPath(int sysKey) throws InvalidItemPathException, ObjectNotFoundException;
- public Class<?> getItemClass(Path path) throws ObjectNotFoundException;
-
- public ItemPath resolvePath(DomainPath domainPath) throws InvalidItemPathException, ObjectNotFoundException;
-
+ /**
+ * Find the ItemPath for which a DomainPath is an alias.
+ *
+ * @param domainPath The path to resolve
+ * @return The ItemPath it points to (should be an AgentPath if the path references an Agent)
+ * @throws InvalidItemPathException
+ * @throws ObjectNotFoundException
+ */
+ public ItemPath resolvePath(DomainPath domainPath) throws InvalidItemPathException, ObjectNotFoundException;
+
+ /**
+ * Resolve a path to a CORBA Object Item or Agent
+ *
+ * @param path The path to be resolved
+ * @return The CORBA Object
+ * @throws ObjectNotFoundException When the Path doesn't exist, or doesn't have an IOR associated with it
+ */
public org.omg.CORBA.Object resolve(Path path) throws ObjectNotFoundException;
- // Path management
-
- public void add(Path newPath) throws ObjectCannotBeUpdated, ObjectAlreadyExistsException;
-
- public void delete(Path path) throws ObjectCannotBeUpdated;
-
// Path finding and searching
+ /**
+ * Checks if a particular Path exists in the directory
+ * @param path The path to check
+ * @return boolean true if the path exists, false if it doesn't
+ */
public boolean exists(Path path);
+ /**
+ * List the next-level-deep children of a Path
+ *
+ * @param path The parent Path
+ * @return An Iterator of child Paths
+ */
public Iterator<Path> getChildren(Path path);
- public Iterator<Path> search(Path path, String name);
-
- public Iterator<Path> search(Path start, String propname, String propvalue);
+ /**
+ * Find a path with a particular name (last component)
+ *
+ * @param start Search root
+ * @param name The name to search for
+ * @return An Iterator of matching Paths. Should be an empty Iterator if there are no matches.
+ */
+ public Iterator<Path> search(Path start, String name);
+
+ /**
+ * Search for Items in the specified path with the given property name and value
+ * @param start Search root
+ * @param propname Property name
+ * @param propvalue The property value to search for
+ * @return An Iterator of matching Paths
+ */
+ public Iterator<Path> search(Path start, Property... props);
+ /**
+ * Search for Items of a particular type, based on its PropertyDescription outcome
+ * @param start Search root
+ * @param props Properties unmarshalled from an ItemDescription's property description outcome.
+ * @return An Iterator of matching Paths
+ */
public Iterator<Path> search(Path start, PropertyDescriptionList props);
-
- public Iterator<Path> searchEntities(Path path);
-
- public Iterator<Path> searchAliases(DomainPath start);
+ /**
+ * Find all DomainPaths that are aliases for a particular Item or Agent
+ * @param itemPath The ItemPath
+ * @return An Iterator of DomainPaths that are aliases for that Item
+ */
public Iterator<Path> searchAliases(ItemPath itemPath);
// Role and agent management
+ /**
+ * @param agentName
+ * @return
+ * @throws ObjectNotFoundException
+ */
public AgentPath getAgentPath(String agentName) throws ObjectNotFoundException;
+ /**
+ * @param roleName
+ * @return
+ * @throws ObjectNotFoundException
+ */
public RolePath getRolePath(String roleName) throws ObjectNotFoundException;
- public RolePath createRole(String role, boolean b) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated;
-
- public void addRole(AgentPath agent, RolePath rolePath) throws ObjectCannotBeUpdated, ObjectNotFoundException;
-
+ /**
+ * @param rolePath
+ * @return
+ * @throws ObjectNotFoundException
+ */
public AgentPath[] getAgents(RolePath rolePath) throws ObjectNotFoundException;
+ /**
+ * @param agentPath
+ * @return
+ */
public RolePath[] getRoles(AgentPath agentPath);
+ /**
+ * @param agentPath
+ * @param role
+ * @return
+ */
public boolean hasRole(AgentPath agentPath, RolePath role);
- public void removeRole(AgentPath agent, RolePath role) throws ObjectCannotBeUpdated, ObjectNotFoundException;
-
+ /**
+ * @param agentPath
+ * @return
+ * @throws ObjectNotFoundException
+ */
public String getAgentName(AgentPath agentPath) throws ObjectNotFoundException;
- public void setAgentPassword(AgentPath agent, String newPassword) throws ObjectNotFoundException, ObjectCannotBeUpdated, NoSuchAlgorithmException;
-
- 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/Path.java b/src/main/java/com/c2kernel/lookup/Path.java
index f9fd15d..d6be37f 100644
--- a/src/main/java/com/c2kernel/lookup/Path.java
+++ b/src/main/java/com/c2kernel/lookup/Path.java
@@ -12,7 +12,6 @@ package com.c2kernel.lookup;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.StringTokenizer;
import com.c2kernel.common.ObjectNotFoundException;
@@ -201,17 +200,6 @@ public abstract class Path implements Serializable
return mSysKey;
}
- public Path find(String name) throws ObjectNotFoundException {
- Iterator<Path> e = Gateway.getLookup().search(this, name);
- if (e.hasNext()) {
- Path thisPath = e.next();
- if (e.hasNext())
- throw new ObjectNotFoundException("More than one match for "+name, "");
- return thisPath;
- }
- throw new ObjectNotFoundException("No match for "+name, "");
- }
-
public abstract ItemPath getEntity() throws ObjectNotFoundException;
@Override
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/lookup/ldap/LDAPAuthManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java
deleted file mode 100644
index 4c26de6..0000000
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package com.c2kernel.lookup.ldap;
-
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.process.auth.Authenticator;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPConnection;
-import com.novell.ldap.LDAPException;
-
-public class LDAPAuthManager implements Authenticator {
-
- private LDAPConnection mLDAPConn;
- private LDAPProperties ldapProps;
-
-
- @Override
- public boolean authenticate(String agentName,
- String password, String resource) throws InvalidDataException, ObjectNotFoundException {
-
- ldapProps = new LDAPProperties(Gateway.getProperties());
-
- if (ldapProps.mHost!=null && ldapProps.mPort!= null && ldapProps.mLocalPath!=null )
- {
- try { // anonymously bind to LDAP and find the agent entry for the username
- ldapProps.mUser = "";
- ldapProps.mPassword = "";
- mLDAPConn = LDAPLookupUtils.createConnection(ldapProps);
- LDAPLookup anonLookup = new LDAPLookup(ldapProps);
- anonLookup.open(this);
- String agentDN = anonLookup.getFullDN(anonLookup.getAgentPath(agentName));
-
- //found agentDN, try to log in with it
- ldapProps.mUser = agentDN;
- ldapProps.mPassword = password;
- mLDAPConn = LDAPLookupUtils.createConnection(ldapProps);
- return true;
- } catch (LDAPException e) {
- return false;
- }
- }
- else
- {
- throw new InvalidDataException("Cannot log in. Some connection properties are not set.", "");
- }
-
- }
-
- @Override
- public boolean authenticate(String resource) throws InvalidDataException, ObjectNotFoundException {
- ldapProps = new LDAPProperties(Gateway.getProperties());
-
- if (ldapProps.mUser == null || ldapProps.mUser.length()==0 ||
- ldapProps.mPassword == null || ldapProps.mPassword.length()==0)
- throw new InvalidDataException("LDAP root user properties not found in config.");
- try {
- mLDAPConn = LDAPLookupUtils.createConnection(ldapProps);
- return true;
- } catch (LDAPException e) {
- return false;
- }
- }
-
- @Override
- public LDAPConnection getAuthObject() {
-
- if (!mLDAPConn.isConnected()) {
- Logger.warning("LDAPAuthManager - lost connection to LDAP server. Attempting to reconnect.");
- try {
- mLDAPConn = LDAPLookupUtils.createConnection(ldapProps);
- } catch (LDAPException ex) { }
- }
- return mLDAPConn;
- }
-
- @Override
- public void disconnect() {
- Logger.msg(1, "LDAP Lookup: Shutting down LDAP connection.");
- if (mLDAPConn != null) {
- try {
- mLDAPConn.disconnect();
- } catch (LDAPException e) {
- Logger.error(e);
- }
- mLDAPConn = null;
- }
-
- }
-
- public LDAPAuthManager() {
- // TODO Auto-generated constructor stub
- }
-
-
-}
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java
deleted file mode 100644
index 10c1830..0000000
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java
+++ /dev/null
@@ -1,763 +0,0 @@
-/*
- * Directory Lookup Service *
- * author: Florida Estrella
-*/
-
-package com.c2kernel.lookup.ldap;
-
-import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-
-import org.omg.CORBA.Object;
-
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.TraceableEntity;
-import com.c2kernel.entity.agent.ActiveEntity;
-import com.c2kernel.entity.proxy.ProxyMessage;
-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.Path;
-import com.c2kernel.lookup.RolePath;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.process.auth.Authenticator;
-import com.c2kernel.property.PropertyDescription;
-import com.c2kernel.property.PropertyDescriptionList;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPAttribute;
-import com.novell.ldap.LDAPAttributeSet;
-import com.novell.ldap.LDAPConnection;
-import com.novell.ldap.LDAPDN;
-import com.novell.ldap.LDAPEntry;
-import com.novell.ldap.LDAPException;
-import com.novell.ldap.LDAPSearchConstraints;
-import com.novell.ldap.LDAPSearchResults;
-
-/**
- * The LDAPLookup object, statically accessible through the Gateway, manages
- * the LDAP connection for the cristal process. It provides:
- * <ul>
- * <li>Authentication - returning an AgentProxy object if a user has logged in
- * <li>System key generation - through the NextKeyManager
- * <li>Agent and Role lookup/modification - through the RoleManager
- * <li>
- * @version $Revision: 1.113 $ $Date: 2006/03/03 13:52:21 $
- * @author $Author: abranson $
- */
-
-public class LDAPLookup implements Lookup
-
-{
- private LDAPAuthManager mLDAPAuth;
- private LDAPPropertyManager mPropManager;
-
- final String mItemTypeRoot, mDomainTypeRoot, mGlobalPath, mRootPath, mLocalPath, mRolePath;
-
- /**
- * Creates a new LDAPLookup manager with the properties supplied.
- * This should be only done by the Gateway during initialisation.
- *
- * @param props The LDAP properties object that extracts LDAP connection properties from the global c2kprops
- */
- public LDAPLookup(LDAPProperties props)
- {
- Logger.msg(8,"LDAPLookup - initialising.");
-
- mGlobalPath=props.mGlobalPath;
- mRootPath=props.mRootPath;
- mLocalPath=props.mLocalPath;
-
- mItemTypeRoot = "cn=entity,"+props.mLocalPath;
- mDomainTypeRoot = "cn=domain,"+props.mLocalPath;
- mRolePath = "cn=agent,"+mDomainTypeRoot;
-
- }
-
- public LDAPLookup() {
- this(new LDAPProperties(Gateway.getProperties()));
- }
-
- @Override
- public void open(Authenticator auth) {
- mLDAPAuth = (LDAPAuthManager)auth;
- Logger.msg(7, "LDAP.useOldProps="+Gateway.getProperties().getBoolean("LDAP.useOldProps", false));
- mPropManager = new LDAPPropertyManager(this, mLDAPAuth);
- }
-
- /**
- * Gets the property manager, that is used to read and write cristal properties to the LDAP store.
- * @return Returns the global LDAPPropertyManager.
- */
- public LDAPPropertyManager getPropManager() {
- return mPropManager;
- }
-
- /**
- * Disconnects the connection with the LDAP server during shutdown
- */
- @Override
- public void close() {
- Logger.msg(1, "LDAP Lookup: Shutting down LDAP connection.");
- if (mLDAPAuth != null) {
- mLDAPAuth.disconnect();
- mLDAPAuth = null;
- }
- }
-
- /**
- * 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
- */
- public org.omg.CORBA.Object getIOR(Path path)
- throws ObjectNotFoundException
- {
- return resolveObject(getFullDN(path));
- }
-
- /**
- * 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
- */
- private org.omg.CORBA.Object resolveObject(String dn)
- throws ObjectNotFoundException
- {
- Logger.msg(8,"LDAPLookup.resolveObject("+dn+")");
- LDAPEntry anEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(),dn,LDAPSearchConstraints.DEREF_NEVER);
- if (anEntry != null)
- {
- String iorString;
- try {
- iorString = LDAPLookupUtils.getFirstAttributeValue(anEntry, "ior");
- org.omg.CORBA.Object ior=Gateway.getORB().string_to_object(iorString);
- if (ior!=null)
- return ior;
- else
- throw new ObjectNotFoundException("LDAPLookup.resolveObject() - " + dn + " has no IOR", "");
- } catch (ObjectNotFoundException ex) {
- return resolveObject(LDAPLookupUtils.getFirstAttributeValue(anEntry,"aliasedObjectName"));
- }
- }
- else
- throw new ObjectNotFoundException("LDAPLookup.resolveObject() LDAP node " + dn + " is not in LDAP or has no IOR.", "");
- }
-
- /**
- *
- * @param domPath
- * @return
- * @throws InvalidItemPathException
- * @throws ObjectNotFoundException
- */
- @Override
- public ItemPath resolvePath(DomainPath domPath)
- throws InvalidItemPathException, ObjectNotFoundException {
- ItemPath referencedPath = null;
- LDAPEntry domEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(),
- getFullDN(domPath), LDAPSearchConstraints.DEREF_ALWAYS);
- String entityKey = LDAPLookupUtils.getFirstAttributeValue(domEntry,
- "intsyskey");
- Logger.msg(7, "DomainPath " + domPath + " is a reference to "
- + entityKey);
- String objClass = LDAPLookupUtils.getFirstAttributeValue(domEntry,
- "objectClass");
- if (objClass.equals("cristalagent"))
- referencedPath = new AgentPath(Integer.parseInt(entityKey));
- else
- referencedPath = new ItemPath(Integer.parseInt(entityKey));
-
- return referencedPath;
- }
-
-
- @Override
- public void add(Path path)
- throws ObjectCannotBeUpdated, ObjectAlreadyExistsException
- {
- try {
- checkLDAPContext(path);
- LDAPAttributeSet attrSet = createAttributeSet(path);
- LDAPEntry newEntry = new LDAPEntry(getFullDN(path),attrSet);
- LDAPLookupUtils.addEntry(mLDAPAuth.getAuthObject(),newEntry);
- if (path instanceof DomainPath)
- Gateway.getProxyServer().sendProxyEvent(new ProxyMessage(ProxyMessage.NA, path.toString(), ProxyMessage.ADDED));
- } catch (LDAPException ex) {
- if (ex.getResultCode() == LDAPException.ENTRY_ALREADY_EXISTS)
- throw new ObjectAlreadyExistsException(ex.getLDAPErrorMessage(), "");
- else
- throw new ObjectCannotBeUpdated(ex.getLDAPErrorMessage(), "");
- }
- }
-
- //deletes a node
- //throws LDAPexception if node cannot be deleted (eg node is not a leaf)
- @Override
- public void delete(Path path) throws ObjectCannotBeUpdated
- {
- try {
- LDAPLookupUtils.delete(mLDAPAuth.getAuthObject(),getDN(path)+mLocalPath);
- } catch (LDAPException ex) {
- throw new ObjectCannotBeUpdated(ex.getLDAPErrorMessage(), "");
- }
- if (path instanceof DomainPath) {
- Gateway.getProxyServer().sendProxyEvent(new ProxyMessage(ProxyMessage.NA, path.toString(), ProxyMessage.DELETED));
- }
- }
-
- //change specs, add boolean alias leaf context
- protected void checkLDAPContext(Path path)
- {
- String dn = getFullDN(path);
- if (!LDAPLookupUtils.exists(mLDAPAuth.getAuthObject(),dn))
- {
- String listDN[] = path.getPath();
- String name = "cn="+ path.getRoot() + "," + mLocalPath;
- int i=0;
- while (i<listDN.length-1)
- {
- name= "cn="+LDAPLookupUtils.escapeDN(listDN[i])+","+name;
- if (!LDAPLookupUtils.exists(mLDAPAuth.getAuthObject(),name))
- {
- try
- {
- //create cristalcontext
- Logger.msg(8,"LDAPLookup::addLDAPContext() context added " + name);
- LDAPLookupUtils.createCristalContext(mLDAPAuth.getAuthObject(), name);
- }
- catch (Exception ex)
- {
- Logger.error("LDAPLookup::addContext() " + ex);
- }
- }
- i++;
- }
- }
- }
- public void createBootTree()
- {
- Logger.msg(8,"Initializing LDAP Boot tree");
-
- //create org
- LDAPLookupUtils.createOrganizationContext(mLDAPAuth.getAuthObject(), mGlobalPath);
- //create root
- LDAPLookupUtils.createCristalContext(mLDAPAuth.getAuthObject(), mRootPath);
- //create local
- LDAPLookupUtils.createCristalContext(mLDAPAuth.getAuthObject(), mLocalPath);
- }
-
- @Override
- public void initializeDirectory() throws ObjectNotFoundException
- {
- createBootTree();
- initTree( Gateway.getResource().getTextResource(null, "boot/LDAPboot.txt"));
- }
-
- public void initTree(String bootFile)
- {
- Logger.msg(8,"Verifying Cristal LDAP roots");
- StringTokenizer strTokenizer = new StringTokenizer(bootFile, "\n\r");
- while (strTokenizer.hasMoreTokens())
- {
- String line = strTokenizer.nextToken();
- Logger.msg(8,"Checking " + line+mLocalPath);
- LDAPLookupUtils.createCristalContext(mLDAPAuth.getAuthObject(), line+mLocalPath);
- }
-
- }
-
- //typically search for cn=barcode
- @Override
- public LDAPPathSet search(Path start, String filter)
- {
- Logger.msg(8,"LDAPLookup::search() From " + getDN(start) + " for cn=" + filter );
- return search(getFullDN(start),"cn="+LDAPLookupUtils.escapeSearchFilter(filter));
- }
-
- @Override
- public LDAPPathSet search(Path start, String propname, String propvalue)
- {
- String val = propname+":"+propvalue;
- Logger.msg(8,"LDAPLookup::search() From " + getDN(start) + " for cristalprop=" + val );
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_SEARCHING);
- return search(getFullDN(start),LDAPConnection.SCOPE_SUB,"cristalprop="+LDAPLookupUtils.escapeSearchFilter(val),searchCons);
- }
-
- @Override
- public LDAPPathSet search(Path start, PropertyDescriptionList props) {
- StringBuffer query = new StringBuffer();
- int propCount = 0;
- for (PropertyDescription propDesc: props.list) {
- if (propDesc.getIsClassIdentifier()) {
- String thisProp = LDAPLookupUtils.escapeSearchFilter(propDesc.getName()+(":")+propDesc.getDefaultValue());
- query.append("(cristalprop=").append(thisProp).append(")");
- propCount++;
- }
- }
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_SEARCHING);
- if (propCount == 0)
- return search(getFullDN(start),LDAPConnection.SCOPE_SUB,"objectClass=cristalentity",searchCons);
- else if (propCount == 1)
- return search(getFullDN(start),LDAPConnection.SCOPE_SUB,query.toString(),searchCons);
- else
- return search(getFullDN(start),LDAPConnection.SCOPE_SUB,"(&"+query.toString()+")",searchCons);
- }
-
- protected LDAPPathSet search(String startDN, int scope, String filter, LDAPSearchConstraints searchCons)
- {
- Logger.msg(8,"Searching for "+filter+" in "+startDN);
- searchCons.setMaxResults(0);
- String[] attr = { LDAPConnection.ALL_USER_ATTRS };
- try
- {
- LDAPSearchResults res = mLDAPAuth.getAuthObject().search(startDN, scope,
- filter,attr,false,searchCons);
- return new LDAPPathSet(res, this);
- }
- catch (LDAPException ex)
- {
- Logger.error("LDAPException::LDAPLookup::search() " + ex.toString());
- return new LDAPPathSet(this);
- }
- }
- //typically search for (any filter combination)
- public LDAPPathSet search(String startDN,String filter)
- {
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
- return search(startDN,LDAPConnection.SCOPE_SUB,filter,searchCons);
- }
-
- @Override
- public LDAPPathSet searchEntities(Path start) {
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_SEARCHING);
- return search(getFullDN(start), LDAPConnection.SCOPE_SUB, "objectClass=cristalentity", searchCons);
- }
-
- @Override
- public LDAPPathSet searchAliases(DomainPath start) {
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
- return search(getFullDN(start), LDAPConnection.SCOPE_SUB, "objectClass=aliasObject", searchCons);
- }
-
- @Override
- public LDAPPathSet searchAliases(ItemPath entity) {
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
- return search(getFullDN(new DomainPath()), LDAPConnection.SCOPE_SUB, "(&(objectClass=aliasObject)(aliasedObjectName="+
- LDAPLookupUtils.escapeDN(getFullDN(entity))+"))", searchCons);
- }
-
- @Override
- public boolean exists(Path path) {
- return LDAPLookupUtils.exists(mLDAPAuth.getAuthObject(), getFullDN(path));
- }
-
- @Override
- public Class<?> getItemClass(Path path) throws ObjectNotFoundException {
- String[] attr = { LDAPConnection.ALL_USER_ATTRS };
- try {
- LDAPEntry anEntry=mLDAPAuth.getAuthObject().read(getDN(path)+mLocalPath,attr);
- String type = LDAPLookupUtils.getFirstAttributeValue(anEntry, "objectClass");
- if (type.equals("cristalentity"))
- return TraceableEntity.class;
- else if (type.equals("cristalagent"))
- return ActiveEntity.class;
- else
- throw new ObjectNotFoundException("Not an entity", "");
-
- } catch (LDAPException ex) {
- if (ex.getResultCode() == LDAPException.NO_SUCH_OBJECT)
- throw new ObjectNotFoundException("Entity does not exist", "");
- Logger.error(ex);
- throw new ObjectNotFoundException("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
- */
- protected Path nodeToPath(LDAPEntry entry) throws InvalidItemPathException, ObjectNotFoundException
- {
- String dn = entry.getDN();
-
- // extract syskey
- int entityKey = -1;
- try {
- String entityKeyStr = LDAPLookupUtils.getFirstAttributeValue(entry,"intsyskey");
- entityKey = Integer.parseInt(entityKeyStr);
- } catch (Exception e) { }
-
- // extract IOR
- org.omg.CORBA.Object ior = null;
- try {
- String stringIOR = LDAPLookupUtils.getFirstAttributeValue(entry,"ior");
- ior = Gateway.getORB().string_to_object(stringIOR);
- } catch (ObjectNotFoundException e2) { }
-
- /* Find the right path class */
- Path thisPath;
- if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalagent"))
- { //cristalagent
- String agentID = LDAPLookupUtils.getFirstAttributeValue(entry,"uid");
- thisPath = new AgentPath(entityKey, agentID);
- }
-
- else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalrole"))
- { //cristalrole
- thisPath = new RolePath(LDAPDN.explodeDN(dn,true)[0],
- LDAPLookupUtils.getFirstAttributeValue(entry, "jobList").equals("TRUE"));
- }
- else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","aliasObject") ||
- (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalcontext") && dn.endsWith(mDomainTypeRoot)))
- {
- DomainPath domainPath = new DomainPath();
- domainPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mDomainTypeRoot))));
- thisPath = domainPath;
- }
- else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalentity") ||
- (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalcontext") && dn.endsWith(mItemTypeRoot)))
- {
- if(dn.endsWith(mItemTypeRoot)) {
- ItemPath entityPath;
- if (entityKey != -1)
- entityPath = new ItemPath(entityKey);
- else {
- entityPath = new ItemPath();
- entityPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mItemTypeRoot))));
- }
- thisPath = entityPath;
- }
- else
- throw new ObjectNotFoundException("Entity found outside entity tree");
- }
- else
- {
- throw new ObjectNotFoundException("Unrecognised LDAP entry. Not a cristal entry");
- }
-
- //set IOR if we have one
- if (ior!=null) thisPath.setIOR(ior);
- return thisPath;
- }
-
- public String getDN(Path path) {
- StringBuffer dnBuffer = new StringBuffer();
- String[] pathComp = path.getPath();
- for (int i=pathComp.length-1; i>=0; i--)
- dnBuffer.append("cn=").append(LDAPLookupUtils.escapeDN(pathComp[i])).append(",");
- dnBuffer.append("cn="+path.getRoot()+",");
- return dnBuffer.toString();
- }
-
- public String getFullDN(Path path) {
- return getDN(path)+mLocalPath;
- }
-
- public String[] getPathComponents(String dnFragment) {
- ArrayList<String> newPath = new ArrayList<String>();
- StringTokenizer tok = new StringTokenizer(dnFragment, ",");
- String[] path = new String[tok.countTokens()];
- while (tok.hasMoreTokens()) {
- String nextPath = tok.nextToken();
- if (nextPath.indexOf("cn=") == 0)
- newPath.add(0, LDAPLookupUtils.unescapeDN(nextPath.substring(3)));
- else
- break;
- }
- return newPath.toArray(path);
- }
-
- @Override
- public Object resolve(Path path) throws ObjectNotFoundException {
- return resolveObject(getFullDN(path));
- }
-
- @Override
- public Iterator<Path> getChildren(Path path) {
- if (path instanceof RolePath) return ((RolePath)path).getChildren();
- String filter = "objectclass=*";
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(10);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_FINDING );
- return search(getFullDN(path), LDAPConnection.SCOPE_ONE,filter,searchCons);
- }
-
- public LDAPAttributeSet createAttributeSet(Path path) throws ObjectCannotBeUpdated {
- LDAPAttributeSet attrs = new LDAPAttributeSet();
-
- if (path instanceof RolePath) {
- RolePath rolePath = (RolePath)path;
- attrs.add(new LDAPAttribute("objectclass","cristalrole"));
- String jobListString = rolePath.hasJobList()?"TRUE":"FALSE";
- attrs.add(new LDAPAttribute("jobList",jobListString));
- attrs.add(new LDAPAttribute("cn", rolePath.getName()));
- }
- else if (path instanceof DomainPath) {
- DomainPath domPath = (DomainPath)path;
- attrs.add(new LDAPAttribute("cn",domPath.getName()));
- try {
- attrs.add(new LDAPAttribute("aliasedObjectName",getFullDN(domPath.getEntity())));
- String objectclass_values[] = { "alias", "aliasObject" };
- attrs.add(new LDAPAttribute("objectclass",objectclass_values));
- } catch (ObjectNotFoundException e) { // no entity - is a context
- attrs.add(new LDAPAttribute("objectclass","cristalcontext"));
- }
- }
-
- else if (path instanceof ItemPath) {
- ItemPath itemPath = (ItemPath)path;
- attrs.add(new LDAPAttribute("intsyskey",Integer.toString(itemPath.getSysKey())));
- attrs.add(new LDAPAttribute("cn", itemPath.getPath()[itemPath.getPath().length-1]));
- if (itemPath.getIOR() != null)
- attrs.add(new LDAPAttribute("ior", Gateway.getORB().object_to_string(itemPath.getIOR())));
-
- if (path instanceof AgentPath) {
- AgentPath agentPath = (AgentPath)path;
- attrs.add(new LDAPAttribute("objectclass","cristalagent"));
-
- String agentName = agentPath.getAgentName();
- if (agentName != null && agentName.length() > 0)
- attrs.add(new LDAPAttribute("uid", agentName));
- else
- 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.", "");
- }
- else
- throw new ObjectCannotBeUpdated("Cannot create agent. No password given", "");
- }
- else {
- attrs.add(new LDAPAttribute("objectclass","cristalentity"));
- }
- }
-
- return attrs;
-
- }
-
- //NOTE: A role must have at LEAST 1 userDN, cannot be empty...
- //Creates a cristalRole
- //CristalRole is-a specialized CristalContext which contains multi-valued uniqueMember attribute pointing to cristalagents
- @Override
- public RolePath createRole(String roleName, boolean jobList)
- throws ObjectAlreadyExistsException, ObjectCannotBeUpdated
- {
-
- // create the role
- RolePath rolePath = new RolePath(roleName, jobList);
- String roleDN = getFullDN(rolePath);
- LDAPEntry roleNode;
- try
- {
- roleNode = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(rolePath));
- throw new ObjectAlreadyExistsException();
- } catch (ObjectNotFoundException 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(), "");
- }
- return rolePath;
-
-
- }
- public void deleteRole(RolePath role) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- try {
- LDAPLookupUtils.delete(mLDAPAuth.getAuthObject(), getFullDN(role));
- } catch (LDAPException ex) {
- throw new ObjectCannotBeUpdated("Could not remove role");
- }
- }
-
- @Override
- public void addRole(AgentPath agent, RolePath role)
- throws ObjectCannotBeUpdated, ObjectNotFoundException
- {
- LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(role));
- //add memberDN to uniqueMember if it is not yet a member
- if (!LDAPLookupUtils.existsAttributeValue(roleEntry, "uniqueMember", getFullDN(agent)))
- LDAPLookupUtils.addAttributeValue(mLDAPAuth.getAuthObject(), roleEntry, "uniqueMember", getFullDN(agent));
- else
- throw new ObjectCannotBeUpdated("Agent " + agent.getAgentName() + " already has role " + role.getName());
- }
-
- @Override
- public void removeRole(AgentPath agent, RolePath role)
- throws ObjectCannotBeUpdated, ObjectNotFoundException
- {
- LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(role));
- if (LDAPLookupUtils.existsAttributeValue(roleEntry, "uniqueMember", getFullDN(agent)))
- LDAPLookupUtils.removeAttributeValue(mLDAPAuth.getAuthObject(), roleEntry, "uniqueMember", getFullDN(agent));
- else
- throw new ObjectCannotBeUpdated("Agent did not have that role");
- }
-
- @Override
- public boolean hasRole(AgentPath agent, RolePath role) {
- String filter = "(&(objectclass=cristalrole)(uniqueMember="+getFullDN(agent)+")(cn="+role.getName()+"))";
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- return search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons).hasNext();
- }
-
- @Override
- public AgentPath[] getAgents(RolePath role)
- throws ObjectNotFoundException
- {
- //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", "");
- }
-
- String[] res = LDAPLookupUtils.getAllAttributeValues(roleEntry,"uniqueMember");
- ArrayList<AgentPath> agents = new ArrayList<AgentPath>();
- for (String userDN : res) {
- try {
- LDAPEntry userEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), userDN);
- AgentPath path = (AgentPath)nodeToPath(userEntry);
- agents.add(path);
- } catch (ObjectNotFoundException ex) {
- Logger.error("Agent "+userDN+" does not exist");
- } catch (InvalidItemPathException ex) {
- Logger.error("Agent "+userDN+" is not a valid entity");
- }
- }
- AgentPath[] usersList = new AgentPath[0];
- usersList = agents.toArray(usersList);
- return usersList;
- }
-
- //returns the role/s of a user
- @Override
- public RolePath[] getRoles(AgentPath agentPath)
- {
- //search the mDomainPath tree uniqueMember=userDN
- //filter = objectclass=cristalrole AND uniqueMember=userDN
- String filter = "(&(objectclass=cristalrole)(uniqueMember="+getFullDN(agentPath)+"))";
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- Iterator<?> roles = search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
- ArrayList<RolePath> roleList = new ArrayList<RolePath>();
-
- while(roles.hasNext())
- {
- RolePath path = (RolePath) roles.next();
- roleList.add(path);
- }
- RolePath[] roleArr = new RolePath[roleList.size()];
- roleArr = roleList.toArray(roleArr);
- return roleArr;
- }
-
- /**
- * Utility for looking up a login name
- *
- * @param ld
- * @param agentName
- * @param baseDN
- * @return
- * @throws ObjectNotFoundException
- */
- @Override
- 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+"))";
- Iterator<Path> res = search(mItemTypeRoot,LDAPConnection.SCOPE_SUB,filter,searchCons);
- if (!res.hasNext())
- throw new ObjectNotFoundException("Agent not found: "+agentName, "");
- Path result = res.next();
- if (result instanceof AgentPath)
- return (AgentPath)result;
- else
- throw new ObjectNotFoundException("Entry was not an Agent");
- }
-
- @Override
- public RolePath getRolePath(String roleName) throws ObjectNotFoundException
- {
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER );
- String filter = "(&(objectclass=cristalrole)(cn="+roleName+"))";
- Iterator<Path> res = search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons);
- if (!res.hasNext())
- throw new ObjectNotFoundException("Role not found");
- Path result = res.next();
- if (result instanceof RolePath)
- return (RolePath)result;
- else
- throw new ObjectNotFoundException("Entry was not a Role");
- }
-
- @Override
- public void setHasJobList(RolePath role, boolean hasJobList) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- // get entry
- LDAPEntry roleEntry;
- try {
- roleEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(role));
- } catch (ObjectNotFoundException e) {
- throw new ObjectNotFoundException("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 {
- 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", "");
- }
- LDAPLookupUtils.setAttributeValue(mLDAPAuth.getAuthObject(), agentEntry, "userPassword", encPasswd);
-
- }
-
- @Override
- public String getAgentName(AgentPath agentPath)
- throws ObjectNotFoundException {
- LDAPEntry agentEntry = LDAPLookupUtils.getEntry(mLDAPAuth.getAuthObject(), getFullDN(agentPath));
- return LDAPLookupUtils.getFirstAttributeValue(agentEntry,"uid");
- }
-
-}
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java
deleted file mode 100644
index e1c8ac4..0000000
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- * Lookup helper class.
- */
-
-package com.c2kernel.lookup.ldap;
-
-//import netscape.ldap.*;
-//import netscape.ldap.util.*;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPAttribute;
-import com.novell.ldap.LDAPAttributeSet;
-import com.novell.ldap.LDAPConnection;
-import com.novell.ldap.LDAPDN;
-import com.novell.ldap.LDAPEntry;
-import com.novell.ldap.LDAPException;
-import com.novell.ldap.LDAPModification;
-import com.novell.ldap.LDAPSearchConstraints;
-import com.novell.ldap.LDAPSearchResults;
-
-/**
- * @version $Revision: 1.74 $ $Date: 2006/03/03 13:52:21 $
- * @author $Author: abranson $
- */
-
-final public class LDAPLookupUtils
-{
- static final char[] META_CHARS = {'+', '=', '"', ',', '<', '>', ';', '/'};
- static final String[] META_ESCAPED = {"2B", "3D", "22", "2C", "3C", "3E", "3B", "2F"};
- static public LDAPEntry getEntry(LDAPConnection ld, String dn,int dereference)
- throws ObjectNotFoundException
- {
- try {
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(dereference);
- LDAPEntry thisEntry = ld.read(dn,searchCons);
- if (thisEntry != null) return thisEntry;
- } catch (LDAPException ex) {
- throw new ObjectNotFoundException("LDAP Exception for dn:"+dn+": \n"+ex.getMessage(), "");
- }
- throw new ObjectNotFoundException(dn+" does not exist", "");
-
- }
-
-
- /**
- * Utility method to connect to an LDAP server
- * @param lp LDAP properties to connect with
- * @return a novell LDAPConnection object
- * @throws LDAPException when the connection was unsuccessful
- */
- public static LDAPConnection createConnection(LDAPProperties lp) throws LDAPException {
- LDAPConnection ld = new LDAPConnection();
-
- Logger.msg(3, "LDAPLookup - connecting to " + lp.mHost);
- ld.connect(lp.mHost, Integer.valueOf(lp.mPort).intValue());
-
- Logger.msg(3, "LDAPLookup - authenticating user:" + lp.mUser);
- ld.bind( LDAPConnection.LDAP_V3, lp.mUser,
- String.valueOf(lp.mPassword).getBytes());
-
- Logger.msg(3, "LDAPLookup - authentication successful");
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setMaxResults(0);
- ld.setConstraints(searchCons);
-
- return ld;
- }
-
- //Given a DN, return an LDAP Entry
- static public LDAPEntry getEntry(LDAPConnection ld, String dn)
- throws ObjectNotFoundException
- {
- return getEntry(ld, dn, LDAPSearchConstraints.DEREF_NEVER);
- }
-
- static public String getFirstAttributeValue(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException
- {
- LDAPAttribute attr = anEntry.getAttribute(attribute);
- if (attr==null)
- throw new ObjectNotFoundException("No attributes named '"+attribute+"'", "");
- return (String)attr.getStringValues().nextElement();
- }
-
- static public String[] getAllAttributeValues(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException
- {
- LDAPAttribute attr = anEntry.getAttribute(attribute);
- if (attr!=null)
- return attr.getStringValueArray();
-
- throw new ObjectNotFoundException("No attributes named '"+attribute+"'", "");
-
- }
-
- static public boolean existsAttributeValue(LDAPEntry anEntry, String attribute, String value)
- {
- LDAPAttribute attr = anEntry.getAttribute(attribute);
- if (attr!=null)
- {
- String[] attrValues = new String[attr.size()];
- attrValues = attr.getStringValueArray();
- for (int i=0;i<attr.size();i++)
- if (attrValues[i].equalsIgnoreCase(value))
- return true;
- }
- return false;
- }
- static public boolean hasOneAttributeValue(LDAPEntry anEntry, String attribute) throws ObjectNotFoundException
- {
- int j =0;
- LDAPAttribute attr = anEntry.getAttribute(attribute);
- if (attr==null)
- throw new ObjectNotFoundException("No attributes named '"+attribute+"'", "");
- j=attr.size();
- return j==1;
- }
-
- //this is for a single-valued attribute
- static public void setAttributeValue(LDAPConnection ld, LDAPEntry anEntry, String attribute, String newValue)
- throws ObjectNotFoundException, ObjectCannotBeUpdated
- {
- try {
- if (!hasOneAttributeValue(anEntry, attribute))
- throw new ObjectCannotBeUpdated("Attribute "+attribute + " of entry " + anEntry.getDN()+" has more than one value", "");
- } catch (ObjectNotFoundException ex) {
- addAttributeValue(ld, anEntry, attribute, newValue);
- }
- try
- {
- ld.modify(anEntry.getDN(),new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute(attribute,newValue)));
- }
- catch (LDAPException ex)
- {
- Logger.error(ex);
- throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be modified", "");
- }
- }
-
-
- //this is for a multi-valued attribute eg uniqueMember
- static public void addAttributeValue(LDAPConnection ld, LDAPEntry anEntry, String attribute, String value)
- throws ObjectCannotBeUpdated
- {
- try
- {
- ld.modify(anEntry.getDN(),new LDAPModification(LDAPModification.ADD, new LDAPAttribute(attribute,value)));
- }
- catch (LDAPException ex)
- {
- Logger.error(ex);
- throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be added.", "");
- }
- }
-
- //this is for a multi-valued attribute eg uniqueMember
- static public void removeAttributeValue(LDAPConnection ld, LDAPEntry anEntry, String attribute, String value)
- throws ObjectCannotBeUpdated
- {
- try
- {
- ld.modify(anEntry.getDN(),new LDAPModification(LDAPModification.DELETE,new LDAPAttribute(attribute,value)));
- }
- catch (LDAPException ex)
- {
- Logger.error(ex);
- throw new ObjectCannotBeUpdated("Attribute " + attribute + " of entry " + anEntry.getDN() + " could not be deleted", "");
- }
- }
-
- static public boolean exists(LDAPConnection ld, String name)
- {
- try {
- String[] attr = { LDAPConnection.NO_ATTRS };
- LDAPEntry anEntry=ld.read(name,attr);
- if (anEntry!=null)
- return true;
- } catch (LDAPException ex)
- {
- Logger.debug(9, "LDAPLookupUtils.exists("+name+": "+ex.getMessage());
- return false;
- }
- return false;
- }
-
- static public void addEntry(LDAPConnection ld,LDAPEntry myEntry)
- throws ObjectAlreadyExistsException, LDAPException
- {
- try
- {
- ld.add( myEntry );
- }
- catch( LDAPException ex ) {
- if (ex.getResultCode() == LDAPException.ENTRY_ALREADY_EXISTS)
- throw new ObjectAlreadyExistsException("Entry already present." + myEntry.getDN(), "");
- throw ex;
- }
- }
-
- static public boolean hasChildren(LDAPConnection ld, String dn, String filter)
- {
- String[] attr = { LDAPConnection.NO_ATTRS };
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
-
- try
- {
- LDAPSearchResults res = ld.search(dn,LDAPConnection.SCOPE_ONE,filter,attr,false,searchCons);
- if (res.hasMore())
- return true;
- }
- catch (LDAPException ex)
- {
- Logger.error(ex);
- }
- return false;
- }
-
- //returns list of dns
- static public String[] getChildrenDNs(LDAPConnection ld, String dn, String filter)
- {
- String[] result = null;
- String[] attr = { LDAPConnection.NO_ATTRS };
- LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
- searchCons.setBatchSize(0);
- searchCons.setDereference(LDAPSearchConstraints.DEREF_NEVER);
-
- try
- {
- LDAPSearchResults res = ld.search(dn,LDAPConnection.SCOPE_ONE,filter,attr,false,searchCons);
- result = new String[res.getCount()];
- int i=0;
- while (res.hasMore())
- {
- LDAPEntry findEntry=res.next();
- if (findEntry!=null)
- {
- result[i++] = new String(findEntry.getDN());
- }
- }
- }
- catch (Exception ex)
- {
- Logger.error(ex);
- }
- return result;
- }
-
- static public void delete(LDAPConnection ld, String dn)
- throws LDAPException
- {
- try
- {
- Logger.msg(7, "LDAPLookupUtils.delete() - "+dn);
- ld.delete(dn);
- }
- catch (LDAPException ex)
- {
- Logger.error("LDAPLookupUtils.remove() - Cannot remove "+dn+": " + ex.getMessage());
- throw ex;
- }
- }
-
- //param dn is the DN of the name
- //param name is the name of the node (also the RDN)
- //example: cn=lab27,o=cern.ch lab27
- //example: cn=product, cn=domain, cn=lab27, cn= cristal2, o=cern.ch product
- static public void createCristalContext(LDAPConnection ld, String dn)
- {
- if (LDAPLookupUtils.exists(ld,dn))
- return;
- try
- {
- String name = LDAPDN.explodeDN(dn,true)[0];
- LDAPAttributeSet attrs = new LDAPAttributeSet();
- attrs.add(new LDAPAttribute("cn",name));
- String objectclass_values[] = new String[1];
- objectclass_values[0] = "cristalcontext";
- if (name.equals("last"))
- attrs.add(new LDAPAttribute("intsyskey", "0"));
-
- attrs.add(new LDAPAttribute("objectclass",objectclass_values));
-
- LDAPLookupUtils.addEntry(ld,new LDAPEntry(dn,attrs));
- }
- catch (Exception ex)
- {
- Logger.error("LDAPLookupUtils.createCristalContext() " + ex.toString());
- }
- }
-
- static public void createOrganizationContext(LDAPConnection ld, String dn)
- {
- if (LDAPLookupUtils.exists(ld,dn))
- return;
-
- try
- {
- String name = LDAPDN.explodeDN(dn,true)[0];
- LDAPAttributeSet attrs = new LDAPAttributeSet();
- //No idea why this worked, or why it suddenly stopped working when we moved to maven
- //attrs.add(new LDAPAttribute("objectclass","top"));
- attrs.add(new LDAPAttribute("objectclass","organization"));
- attrs.add(new LDAPAttribute("o",name));
- LDAPLookupUtils.addEntry(ld,new LDAPEntry(dn,attrs));
- }
- catch (Exception ex)
- {
- Logger.msg(ex.toString());
- }
- }
-
- public static String escapeDN (String name) {
- //From RFC 2253 and the / character for JNDI
- if (name == null) return null;
- String escapedStr = new String(name);
-
- //Backslash is both a Java and an LDAP escape character, so escape it first
- escapedStr = escapedStr.replaceAll("\\\\","\\\\");
-
- //Positional characters - see RFC 2253
- escapedStr = escapedStr.replaceAll("^#","\\\\23"); // TODO: active directory requires hash to be escaped everywhere
- escapedStr = escapedStr.replaceAll("^ | $","\\\\20");
-
- for (int i=0; i<META_CHARS.length; i++) {
- escapedStr = escapedStr.replaceAll("\\"+META_CHARS[i],"\\\\"+ META_ESCAPED[i]);
- }
- if (!name.equals(escapedStr)) Logger.msg(3, "LDAP DN "+name+" escaped to "+escapedStr);
- return escapedStr;
- }
-
- public static String unescapeDN (String dn) {
- //From RFC 2253 and the / character for JNDI
- String unescapedStr = new String(dn);
-
- //Positional characters - see RFC 2253
- unescapedStr = unescapedStr.replaceAll("^\\\\23", "#"); // TODO: active directory requires hash to be escaped everywhere
- unescapedStr = unescapedStr.replaceAll("^\\\\20|\\\\20$", " ");
-
- for (int i=0; i<META_CHARS.length; i++) {
- unescapedStr = unescapedStr.replaceAll("\\\\" + META_ESCAPED[i], ""+META_CHARS[i]);
- }
-
- //Any remaining escaped backslashes
- unescapedStr = unescapedStr.replaceAll("\\\\","\\");
-
- if (!dn.equals(unescapedStr)) Logger.msg(3, "LDAP DN "+dn+" unescaped to "+unescapedStr);
- return unescapedStr;
- }
-
- public static String escapeSearchFilter (String filter) {
- //From RFC 2254
- String escapedStr = new String(filter);
-
- escapedStr = escapedStr.replaceAll("\\\\","\\\\5c");
- //escapedStr = escapedStr.replaceAll("\\*","\\\\2a"); // we need stars for searching
- escapedStr = escapedStr.replaceAll("\\(","\\\\28");
- escapedStr = escapedStr.replaceAll("\\)","\\\\29");
- if (!filter.equals(escapedStr)) Logger.msg(3, "LDAP Search Filter "+filter+" escaped to "+escapedStr);
- return escapedStr;
- }
-}
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java
deleted file mode 100644
index 48f938e..0000000
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package com.c2kernel.lookup.ldap;
-
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.InvalidItemPathException;
-import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.persistency.ClusterStorageException;
-import com.c2kernel.persistency.NextKeyManager;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.process.auth.Authenticator;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPEntry;
-
-/**************************************************************************
- *
- * $Revision: 1.2 $
- * $Date: 2005/04/27 13:47:24 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-// public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/04/27 13:47:24 $ $Author: abranson $";
-public class LDAPNextKeyManager implements NextKeyManager {
-
- LDAPAuthManager ldap;
- String lastKeyPath;
-
- public LDAPNextKeyManager() {
- super();
- LDAPProperties props = new LDAPProperties(Gateway.getProperties());
- this.lastKeyPath = "cn=last,cn=entity,"+props.mLocalPath;
- }
-
- public void open(Authenticator auth) {
- this.ldap = (LDAPAuthManager)auth;
- }
-
- @Override
- public synchronized ItemPath generateNextEntityKey()
- throws ObjectCannotBeUpdated, ObjectNotFoundException
- {
- ItemPath lastKey = getLastEntityPath();
-
- try {
- lastKey.setSysKey(lastKey.getSysKey()+1);
- } catch (InvalidItemPathException ex) {
- throw new ObjectCannotBeUpdated("Invalid syskey "+(lastKey.getSysKey()+1)+". Maybe centre is full.");
- }
- //test that storage is empty for that key
- try {
- if (Gateway.getStorage().getClusterContents(lastKey.getSysKey(), "").length > 0)
- throw new ObjectCannotBeUpdated("NextKeyManager: Storage already contains data for syskey "+lastKey.getSysKey()+
- ". Storage is out of sync with nextkey. Please contact an administrator", "");
- } catch (ClusterStorageException e) {
- Logger.error(e);
- throw new ObjectCannotBeUpdated("Could not check storage for prior data for the next generated systemKey: "+e.getMessage());
- }
-
- //set the last key
- writeLastEntityKey(lastKey.getSysKey());
-
- return lastKey;
- }
-
- @Override
- public synchronized AgentPath generateNextAgentKey()
- throws ObjectCannotBeUpdated, ObjectNotFoundException {
- ItemPath newEntity = generateNextEntityKey();
- return new AgentPath(newEntity);
- }
-
- @Override
- public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException {
- LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getAuthObject(),lastKeyPath);
- LDAPLookupUtils.setAttributeValue(ldap.getAuthObject(), lastKeyEntry,"intsyskey",Integer.toString(sysKey));
- }
-
- @Override
- public ItemPath getLastEntityPath() throws ObjectNotFoundException
- {
- LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getAuthObject(),lastKeyPath);
- String lastKey = LDAPLookupUtils.getFirstAttributeValue(lastKeyEntry,"intsyskey");
- try {
- int sysKey = Integer.parseInt(lastKey);
- ItemPath sysPath = new ItemPath(sysKey);
- return sysPath;
- } catch (InvalidItemPathException ex) {
- throw new ObjectNotFoundException("Invalid syskey. Maybe centre is full.");
- } catch (NumberFormatException ex) {
- throw new ObjectNotFoundException("Invalid syskey in lastkey.");
- }
-
- }
-
-}
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java
deleted file mode 100644
index 806976d..0000000
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.c2kernel.lookup.ldap;
-
-import java.util.Iterator;
-
-import com.c2kernel.lookup.Path;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPEntry;
-import com.novell.ldap.LDAPException;
-import com.novell.ldap.LDAPSearchResults;
-
-/**************************************************************************
- *
- * $Revision: 1.6 $
- * $Date: 2005/12/01 14:23:14 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-
-
-public class LDAPPathSet implements Iterator<Path> {
- LDAPSearchResults results;
- LDAPEntry nextEntry;
- LDAPLookup ldap;
-
- public LDAPPathSet(LDAPLookup ldap) { // empty
- this.ldap = ldap;
- results = null;
- }
-
- public LDAPPathSet(LDAPSearchResults results, LDAPLookup ldap) {
- this.ldap = ldap;
- this.results = results;
- }
-
- @Override
- public boolean hasNext() {
- if (results == null) return false;
- if (nextEntry != null) return true;
- if (results.hasMore())
- try {
- nextEntry = results.next();
- return true;
- } catch (LDAPException ex) {
- if (ex.getResultCode()!=32) {// no results
- Logger.error(ex);
- Logger.error("Error loading LDAP result set: "+ex.getMessage());
- }
- }
- return false;
- }
-
- @Override
- public Path next() {
- if (results == null) return null;
- try {
- if (nextEntry == null)
- nextEntry = results.next();
- Path nextPath = ldap.nodeToPath(nextEntry);
- nextEntry = null;
- return nextPath;
- } catch (Exception ex) {
- Logger.error("Error loading next path");
- Logger.error(ex);
- nextEntry = null;
- if (hasNext()) {
- Logger.error("Skipping to next entry");
- return next();
- }
- else
- return null;
- }
- }
-
- @Override
- public void remove() {
- // do nothing
-
- }
-}
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPProperties.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPProperties.java
deleted file mode 100644
index 1e9f971..0000000
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPProperties.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Directory Lookup Service
-*/
-
-package com.c2kernel.lookup.ldap;
-
-import com.c2kernel.utils.ObjectProperties;
-
-/**
- * @version $Revision: 1.16 $ $Date: 2005/10/12 12:51:54 $
- * @author $Author: abranson $
- */
-public class LDAPProperties
-{
- public String mGlobalPath = null; //o=cern.ch
- public String mRootPath = null; //cn=cristal2
- public String mLocalPath = null; //cn=lab27
- public Integer mPort = null;
- public String mHost = null;
- public String mUser = null;
- public String mPassword = null;
-
- public LDAPProperties(ObjectProperties obj)
- {
- mGlobalPath = obj.getProperty( "LDAP.GlobalPath" );
- mRootPath = obj.getProperty( "LDAP.RootPath" );
- mLocalPath = obj.getProperty( "LDAP.LocalPath" );
- mPort = obj.getInt( "LDAP.port", 389 );
- mHost = obj.getProperty( "LDAP.host" );
- mUser = obj.getProperty( "LDAP.user" );
- mPassword = obj.getProperty( "LDAP.password" );
-
- mRootPath += "," + mGlobalPath;
- mLocalPath += "," + mRootPath;
-
- }
-}
-
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPPropertyManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPPropertyManager.java
deleted file mode 100644
index 1b6e906..0000000
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPPropertyManager.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package com.c2kernel.lookup.ldap;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.property.Property;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPAttribute;
-import com.novell.ldap.LDAPEntry;
-
-/**************************************************************************
- *
- * $Revision: 1.3 $
- * $Date: 2006/03/03 13:52:21 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-public class LDAPPropertyManager {
- /**
- *
- */
- protected LDAPLookup ldap;
- private final LDAPAuthManager auth;
-
- public LDAPPropertyManager(LDAPLookup ldap, LDAPAuthManager auth) {
- super();
- this.ldap = ldap;
- this.auth = auth;
- }
-
- /**
- * @param thisItem - EntityPath of the subject entity
- * @return
- * @throws ObjectNotFoundException
- */
- public boolean hasProperties(ItemPath thisItem) throws ObjectNotFoundException {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(auth.getAuthObject(), ldap.getFullDN(thisItem));
- return entityEntry.getAttribute("cristalprop") != null;
- }
-
- /**
- * @param thisItem - EntityPath of the subject entity
- * @return array of Property
- * @throws ObjectNotFoundException
- */
- public String[] getPropertyNames(ItemPath thisItem) throws ObjectNotFoundException {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(auth.getAuthObject(), ldap.getFullDN(thisItem));
- ArrayList<String> propbag = new ArrayList<String>();
- LDAPAttribute props = entityEntry.getAttribute("cristalprop");
- for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
- String thisProp = (String)e.nextElement();
- String thisName = thisProp.substring(0, thisProp.indexOf(':'));
- if (thisName.startsWith("!") && thisName.length()>1) thisName = thisName.substring(1);
- propbag.add(thisName);
- }
-
- String[] retArr = new String[props.size()];
- return propbag.toArray(retArr);
- }
-
- /**
- * @param thisItem - EntityPath of the subject entity
- * @param propName - the name of the property to retrieve
- * @return The Property object
- * @throws ObjectNotFoundException
- */
- public Property getProperty(ItemPath thisItem, String name) throws ObjectNotFoundException {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(auth.getAuthObject(), ldap.getFullDN(thisItem));
- return getProperty(entityEntry, name);
- }
-
- /**
- * @param thisItem - EntityPath of the subject entity
- * @param name - the property name to delete
- * @throws ObjectNotFoundException
- * @throws ObjectCannotBeUpdated
- */
- public void deleteProperty(ItemPath thisItem, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(auth.getAuthObject(), ldap.getFullDN(thisItem));
- Property prop = getProperty(entityEntry, name);
- Logger.msg(6, "LDAPLookupUtils.deleteProperty("+name+") - Deleting property");
- LDAPLookupUtils.removeAttributeValue(auth.getAuthObject(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
- }
-
- private static String getPropertyAttrValue(Property prop) {
- return (prop.isMutable()?"":"!")+prop.getName()+":"+prop.getValue();
- }
-
- /**
- * @param thisItem - EntityPath of the subject entity
- * @param prop - the property to store
- * @throws ObjectNotFoundException
- * @throws ObjectCannotBeUpdated
- */
- public void setProperty(ItemPath thisItem, Property prop) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(auth.getAuthObject(), ldap.getFullDN(thisItem));
- try {
- Property oldProp = getProperty(entityEntry, prop.getName());
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - Removing old value '"+oldProp.getValue()+"'");
- LDAPLookupUtils.removeAttributeValue(auth.getAuthObject(), entityEntry, "cristalprop", getPropertyAttrValue(oldProp));
- } catch (ObjectNotFoundException ex) {
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - creating new property.");
- }
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - setting to '"+prop.getValue()+"'");
- LDAPLookupUtils.addAttributeValue(auth.getAuthObject(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
- }
-
- public static Property getProperty(LDAPEntry myEntry, String propName) throws ObjectNotFoundException {
- // delete existing props
- LDAPAttribute props = myEntry.getAttribute("cristalprop");
- if (props == null)
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
- String propPrefix = propName+":";
- String roPropPrefix = "!"+propPrefix;
- String val = null, name = null; boolean mutable = false;
- for (Enumeration<?> e = props.getStringValues(); name==null && e.hasMoreElements();) {
- String attrVal = (String)e.nextElement();
- if (attrVal.toLowerCase().startsWith(propPrefix.toLowerCase())) {
- name = attrVal.substring(0, propPrefix.length()-1);
- val = attrVal.substring(propPrefix.length());
- mutable = true; break;
- }
-
- if (attrVal.toLowerCase().startsWith(roPropPrefix.toLowerCase())) {
- name = attrVal.substring(1, roPropPrefix.length()-1);
- val = attrVal.substring(roPropPrefix.length());
- mutable = false; break;
- }
- }
- if (name == null)
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
- Logger.msg(6, "Loaded "+(mutable?"":"Non-")+"Mutable Property: "+name+"="+val);
- return new Property(name, val, mutable);
- }
-
-}
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorage.java b/src/main/java/com/c2kernel/persistency/ClusterStorage.java
index 76aaf1e..29f9174 100644
--- a/src/main/java/com/c2kernel/persistency/ClusterStorage.java
+++ b/src/main/java/com/c2kernel/persistency/ClusterStorage.java
@@ -1,160 +1,265 @@
-
package com.c2kernel.persistency;
+
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.utils.Logger;
-/** Interface for persistency managers of entities. It allows different kernel objects to be stored in different backend. For instance,
- * Properties may be stored in LDAP, while Events, Outcomes and Viewpoints could be stored in a relational database. There are old generic
- * query methods, but these are deprecated. The kernel does no analytical querying of the ClusterStorages, only simple gets and puts.
- *
- * Each first-level path under the Item is defined as a Cluster. Different Clusters may be stored in different places.
- * Each ClusterStorage must support {@link #get(Integer, String)} and {@link #getClusterContents(Integer, String)} for clusters they return
- * {@link #READ} and {@link #READWRITE} from queryClusterSupport
- * and {@link #put(Integer, C2KLocalObject)} and {@link #delete(Integer, String)} for clusters they return {@link #WRITE} and {@link #READWRITE}
- * from {@link #getClusterContents(Integer, String)}.
- * Operations that have notbeen declared as not supported should throw a ClusterStorageException.
- * If a cluster does not exist, get should return null, and delete should return with no action.
-*/
+/**
+ * Interface for persistency managers of entities. It allows different kernel
+ * objects to be stored in different backend. For instance, Properties may be
+ * stored in LDAP, while Events, Outcomes and Viewpoints could be stored in a
+ * relational database. There are old generic query methods, but these are
+ * deprecated. The kernel does no analytical querying of the ClusterStorages,
+ * only simple gets and puts.
+ *
+ * Each first-level path under the Item is defined as a Cluster. Different
+ * Clusters may be stored in different places. Each ClusterStorage must support
+ * {@link #get(Integer, String)} and
+ * {@link #getClusterContents(Integer, String)} for clusters they return
+ * {@link #READ} and {@link #READWRITE} from queryClusterSupport and
+ * {@link #put(Integer, C2KLocalObject)} and {@link #delete(Integer, String)}
+ * for clusters they return {@link #WRITE} and {@link #READWRITE} from
+ * {@link #getClusterContents(Integer, String)}. Operations that have notbeen
+ * declared as not supported should throw a ClusterStorageException. If a
+ * cluster does not exist, get should return null, and delete should return with
+ * no action.
+ */
public abstract class ClusterStorage {
- /**
- * Constant to return from {@link #queryClusterSupport(String)} for Cluster types this storage does not support.
- */
- public static final short NONE = 0;
- /**
- * Constant to return from {@link #queryClusterSupport(String)} for Cluster types this storage can read from a database but not write.
- * An example would be pre-existing data in a database that is mapped to Items in some way.
- */
- public static final short READ = 1;
- /**
- * Constant to return from {@link #queryClusterSupport(String)} for Cluster types this storage can write to a database but not read.
- * An example would be a realtime database export of data, which is transformed in an unrecoverable way for use in other systems.
- */
- public static final short WRITE = 2;
- /**
- * Constant to return from {@link #queryClusterSupport(String)} for data stores that CRISTAL may use for both reading and writing for the given Cluster type.
- */
- public static final short READWRITE = 3;
-
- // Cluster types
- /**
- * The defined path of the root of the CRISTAL Kernel object cluster tree. A zero-length string.
- */
- public static final String ROOT = "";
- /**
- * The root of the Property object cluster. All Property paths start with this. Defined as "Property". Properties are
- * stored underneath according to their name e.g. "Property/Name"
- */
- public static final String PROPERTY = "Property";
- /**
- * The root of the Collection object cluster. All Collection paths start with this. Defined as "Collection". Collections
- * are stored underneath by name e.g. "Collection/Composition"
- */
- public static final String COLLECTION = "Collection";
- /**
- * The cluster which holds the Item workflow. Defined as "LifeCycle". Holds the workflow inside, which is named "workflow",
- * hence "LifeCycle/workflow".
- * @see com.c2kernel.lifecycle.instance.Workflow
- */
- public static final String LIFECYCLE = "LifeCycle";
- /**
- * This cluster holds all outcomes of this Item. The path to each outcome is "Outcome/<i>Schema Name</i>/<i>Schema Version</i>/<i>Event ID</i>"
- */
- public static final String OUTCOME = "Outcome";
- /**
- * This is the cluster that contains all event for this Item. This cluster may be instantiated in a client as a History, which is a
- * RemoteMap. Events are stored with their ID: "/AuditTrail/<i>Event ID</i>"
- */
- public static final String HISTORY = "AuditTrail";
- /**
- * This cluster contains all viewpoints. Its name is defined as "ViewPoint". The paths of viewpoint objects stored here follow this pattern:
- * "ViewPoint/<i>Schema Name</i>/<i>Viewpoint Name</i>"
- */
- public static final String VIEWPOINT = "ViewPoint";
- /**
- * Agents store their persistent jobs in this cluster that have been pushed to them by activities configured to do so. The name is defined as "Job"
- * and each new job received is assigned an integer ID one more than the highest already present.
- */
- public static final String JOB = "Job";
-
- /**
- * An array of all currently supported cluster types, for iterative purposes.
- */
- public static final String[] allClusterTypes = { PROPERTY, COLLECTION, LIFECYCLE, OUTCOME, HISTORY, VIEWPOINT, JOB };
-
- // connection maintenance
- public abstract void open(Authenticator auth)
- throws ClusterStorageException;
- public abstract void close()
- throws ClusterStorageException;
-
- // introspection
- public abstract short queryClusterSupport(String clusterType);
- public abstract String getName();
- // for addressing queries
- public abstract String getId();
-
-
- /** Quickly gets the first string of the slashed path */
- public static String getClusterType(String path) {
- try {
- if (path == null || path.length() == 0) return ClusterStorage.ROOT;
- int start = path.charAt(0) == '/' ? 1 : 0;
- int end = path.indexOf('/', start + 1);
- if (end == -1) end = path.length();
- return path.substring(start, end);
- } catch (Exception ex) {
- Logger.error(ex);
- return ClusterStorage.ROOT;
- }
- }
+ /**
+ * Constant to return from {@link #queryClusterSupport(String)} for Cluster
+ * types this storage does not support.
+ */
+ public static final short NONE = 0;
+ /**
+ * Constant to return from {@link #queryClusterSupport(String)} for Cluster
+ * types this storage can read from a database but not write. An example
+ * would be pre-existing data in a database that is mapped to Items in some
+ * way.
+ */
+ public static final short READ = 1;
+ /**
+ * Constant to return from {@link #queryClusterSupport(String)} for Cluster
+ * types this storage can write to a database but not read. An example would
+ * be a realtime database export of data, which is transformed in an
+ * unrecoverable way for use in other systems.
+ */
+ public static final short WRITE = 2;
+ /**
+ * Constant to return from {@link #queryClusterSupport(String)} for data
+ * stores that CRISTAL may use for both reading and writing for the given
+ * Cluster type.
+ */
+ public static final short READWRITE = 3;
+
+ // Cluster types
+ /**
+ * The defined path of the root of the CRISTAL Kernel object cluster tree. A
+ * zero-length string.
+ */
+ public static final String ROOT = "";
+ /**
+ * The root of the Property object cluster. All Property paths start with
+ * this. Defined as "Property". Properties are stored underneath according
+ * to their name e.g. "Property/Name"
+ */
+ public static final String PROPERTY = "Property";
+ /**
+ * The root of the Collection object cluster. All Collection paths start
+ * with this. Defined as "Collection". Collections are stored underneath by
+ * name e.g. "Collection/Composition"
+ */
+ public static final String COLLECTION = "Collection";
+ /**
+ * The cluster which holds the Item workflow. Defined as "LifeCycle". Holds
+ * the workflow inside, which is named "workflow", hence
+ * "LifeCycle/workflow".
+ *
+ * @see com.c2kernel.lifecycle.instance.Workflow
+ */
+ public static final String LIFECYCLE = "LifeCycle";
+ /**
+ * This cluster holds all outcomes of this Item. The path to each outcome is
+ * "Outcome/<i>Schema Name</i>/<i>Schema Version</i>/<i>Event ID</i>"
+ */
+ public static final String OUTCOME = "Outcome";
+ /**
+ * This is the cluster that contains all event for this Item. This cluster
+ * may be instantiated in a client as a History, which is a RemoteMap.
+ * Events are stored with their ID: "/AuditTrail/<i>Event ID</i>"
+ */
+ public static final String HISTORY = "AuditTrail";
+ /**
+ * This cluster contains all viewpoints. Its name is defined as "ViewPoint".
+ * The paths of viewpoint objects stored here follow this pattern:
+ * "ViewPoint/<i>Schema Name</i>/<i>Viewpoint Name</i>"
+ */
+ public static final String VIEWPOINT = "ViewPoint";
+ /**
+ * Agents store their persistent jobs in this cluster that have been pushed
+ * to them by activities configured to do so. The name is defined as "Job"
+ * and each new job received is assigned an integer ID one more than the
+ * highest already present.
+ */
+ public static final String JOB = "Job";
+
+ /**
+ * An array of all currently supported cluster types, for iterative
+ * purposes.
+ */
+ public static final String[] allClusterTypes = { PROPERTY, COLLECTION,
+ LIFECYCLE, OUTCOME, HISTORY, VIEWPOINT, JOB };
+
+ /**
+ * Connects to the storage. It must be possible to retrieve CRISTAL local
+ * objects after this method returns.
+ *
+ * @param auth
+ * The Authenticator instance that the user or server logged in
+ * with.
+ * @throws ClusterStorageException
+ * If storage initialization failed
+ */
+ public abstract void open(Authenticator auth)
+ throws ClusterStorageException;
+ /**
+ * Shuts down the storage. Data must be completely written to disk before
+ * this method returns, so the process can exit. No further gets or puts
+ * should follow.
+ *
+ * @throws ClusterStorageException
+ * If closing failed
+ */
+ public abstract void close() throws ClusterStorageException;
+
+ /**
+ * Declares whether or not this ClusterStorage can read or write a
+ * particular CRISTAL local object type.
+ *
+ * @param clusterType
+ * The Cluster type requested. Must be one of the Cluster type
+ * constants from this class.
+ * @return A ClusterStorage constant: NONE, READ, WRITE, or READWRITE
+ */
+ public abstract short queryClusterSupport(String clusterType);
+
+ /**
+ * @return A full name of this storage for logging
+ */
+ public abstract String getName();
+
+ /**
+ * @return A short code for this storage for reference
+ */
+ public abstract String getId();
+
+ /**
+ * Utility method to find the cluster for a particular Local Object (the
+ * first part of its path)
+ *
+ * @param Local
+ * object path
+ * @return The cluster to which it belongs
+ */
+ protected static String getClusterType(String path) {
+ try {
+ if (path == null || path.length() == 0)
+ return ClusterStorage.ROOT;
+ int start = path.charAt(0) == '/' ? 1 : 0;
+ int end = path.indexOf('/', start + 1);
+ if (end == -1)
+ end = path.length();
+ return path.substring(start, end);
+ } catch (Exception ex) {
+ Logger.error(ex);
+ return ClusterStorage.ROOT;
+ }
+ }
+
+ /**
+ * Gives the path for a local object. Varies by Cluster.
+ *
+ * @param C2KLocalObject
+ * @return Its path
+ */
public static String getPath(C2KLocalObject obj) {
String root = obj.getClusterType();
- if (root == null) return null; // no storage allowed
+ if (root == null)
+ return null; // no storage allowed
if (obj instanceof Outcome) {
- Outcome oc = (Outcome)obj;
- return root+"/"+oc.getSchemaType()+"/"+oc.getSchemaVersion()+"/"+oc.getName();
- }
- else if (obj instanceof Viewpoint) {
- Viewpoint vp = (Viewpoint)obj;
- return root+"/"+vp.getSchemaName()+"/"+vp.getName();
- }
- else
- return root+"/"+obj.getName();
+ Outcome oc = (Outcome) obj;
+ return root + "/" + oc.getSchemaType() + "/"
+ + oc.getSchemaVersion() + "/" + oc.getName();
+ } else if (obj instanceof Viewpoint) {
+ Viewpoint vp = (Viewpoint) obj;
+ return root + "/" + vp.getSchemaName() + "/" + vp.getName();
+ } else
+ return root + "/" + obj.getName();
}
/* object manipulation */
- // retrieve object by path
- public abstract C2KLocalObject get(Integer sysKey, String path)
- throws ClusterStorageException;
- // store object by path
- public abstract void put(Integer sysKey, C2KLocalObject obj)
- throws ClusterStorageException;
- // delete cluster
- public abstract void delete(Integer sysKey, String path)
- throws ClusterStorageException;
-
- // db specific queries
- @Deprecated
- public Object query(Object query)
- throws ClusterStorageException {
- throw new ClusterStorageException("Query not supported on this storage");
- }
-
- @Deprecated
- public String queryToXML(String query, boolean genericFormat)
- throws ClusterStorageException {
- throw new ClusterStorageException("Query not supported on this storage");
- }
-
-
- // directory listing
- public abstract String[] getClusterContents(Integer sysKey, String path)
- throws ClusterStorageException;
+ // retrieve object by path
+ /**
+ * Fetches a CRISTAL local object from storage
+ *
+ * @param sysKey
+ * The system key of the containing Item
+ * @param path
+ * The path of the local object
+ * @return The C2KLocalObject, or null if the object was not found
+ * @throws ClusterStorageException
+ * when retrieval failed
+ */
+ public abstract C2KLocalObject get(Integer sysKey, String path)
+ throws ClusterStorageException;
+
+ /**
+ * Stores a CRISTAL local object. The path is automatically generated.
+ *
+ * @param sysKey
+ * The Item that the object will be stored under
+ * @param obj
+ * The C2KLocalObject to store
+ * @throws ClusterStorageException
+ * When storage fails
+ */
+ public abstract void put(Integer sysKey, C2KLocalObject obj)
+ throws ClusterStorageException;
+
+ /**
+ * Remove a CRISTAL local object from storage. This should be used sparingly
+ * and responsibly, as it violated traceability. Objects removed in this way
+ * are not expected to be recoverable.
+ *
+ * @param sysKey
+ * The containing Item
+ * @param path
+ * The path of the object to be removed
+ * @throws ClusterStorageException
+ * When deletion fails or is not allowed
+ */
+ public abstract void delete(Integer sysKey, String path)
+ throws ClusterStorageException;
+
+ // directory listing
+ /**
+ * Queries the local path below the given root and returns the possible next
+ * elements.
+ *
+ * @param sysKey
+ * The Item to query
+ * @param path
+ * The path within that Item to query. May be ClusterStorage.ROOT
+ * (empty String)
+ * @return A String array of the possible next path elements
+ * @throws ClusterStorageException
+ * When an error occurred during the query
+ */
+ public abstract String[] getClusterContents(Integer sysKey, String path)
+ throws ClusterStorageException;
}
diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java
index c9ede04..b1489e0 100644
--- a/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java
+++ b/src/main/java/com/c2kernel/persistency/ClusterStorageManager.java
@@ -386,20 +386,4 @@ public class ClusterStorageManager {
Logger.msg(logLevel, "Total number of cached entities: "+memoryCache.size());
}
}
-
- @Deprecated
- public Object query(String id, Object query) throws ClusterStorageException {
- ClusterStorage requiredStorage = allStores.get(id);
- if (requiredStorage == null)
- throw new ClusterStorageException("Storage "+id+" not found.");
- return requiredStorage.query(query);
- }
-
- @Deprecated
- public String queryToXML(String id, String query, boolean genericFormat) throws ClusterStorageException {
- ClusterStorage requiredStorage = allStores.get(id);
- if (requiredStorage == null)
- throw new ClusterStorageException("Storage "+id+" not found.");
- return requiredStorage.queryToXML(query, genericFormat);
- }
}
diff --git a/src/main/java/com/c2kernel/persistency/LDAPClientReader.java b/src/main/java/com/c2kernel/persistency/LDAPClientReader.java
deleted file mode 100644
index ac9215c..0000000
--- a/src/main/java/com/c2kernel/persistency/LDAPClientReader.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.c2kernel.persistency;
-
-import com.c2kernel.entity.C2KLocalObject;
-
-/** Allows clients to directly load properties and collections from the LDAP
-* so no CORBA calls need to be made during normal browsing
-*/
-
-public class LDAPClientReader extends LDAPClusterStorage {
- // return all readwrite support as readonly
- @Override
- public short queryClusterSupport(String clusterType) {
- return (short)(super.queryClusterSupport(clusterType) & READ);
- }
-
-
- /**
- * @see com.c2kernel.persistency.ClusterStorage#delete(Integer, String)
- */
- @Override
- public void delete(Integer sysKey, String path)
- throws ClusterStorageException {
- throw new ClusterStorageException("Writing not supported in ClientReader");
- }
-
- /**
- * @see com.c2kernel.persistency.ClusterStorage#getName()
- */
- @Override
- public String getName() {
- return "LDAP Client Cluster Reader";
- }
-
- /**
- * @see com.c2kernel.persistency.ClusterStorage#put(Integer, String, C2KLocalObject)
- */
-
- public void put(Integer sysKey, String path, C2KLocalObject obj)
- throws ClusterStorageException {
- throw new ClusterStorageException("Writing not supported in ClientReader");
- }
-
-}
diff --git a/src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java b/src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java
deleted file mode 100644
index 4762a33..0000000
--- a/src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package com.c2kernel.persistency;
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.lookup.InvalidItemPathException;
-import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.lookup.Lookup;
-import com.c2kernel.lookup.ldap.LDAPLookup;
-import com.c2kernel.lookup.ldap.LDAPPropertyManager;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.process.auth.Authenticator;
-import com.c2kernel.property.Property;
-import com.c2kernel.utils.Logger;
-
-public class LDAPClusterStorage extends ClusterStorage {
- LDAPPropertyManager ldapStore;
-
- @Override
- public void open(Authenticator auth) throws ClusterStorageException {
- Lookup lookup = Gateway.getLookup();
- if (lookup instanceof LDAPLookup)
- ldapStore = ((LDAPLookup)lookup).getPropManager();
- else
- throw new ClusterStorageException("Cannot use LDAP cluster storage without LDAP Lookup");
-
- }
-
- @Override
- public void close() throws ClusterStorageException {
- }
-
- // introspection
- @Override
- public short queryClusterSupport(String clusterType) {
- if (clusterType.equals(PROPERTY))
- return READWRITE;
- else
- return NONE;
- }
-
- @Override
- public String getName() {
- return "LDAP Cluster Storage";
- }
-
- @Override
- public String getId() {
- return "LDAP";
- }
-
- // retrieve object by path
- @Override
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
- Logger.msg(6, "LDAPClusterStorage.get() - "+sysKey+"/"+path);
- StringTokenizer tok = new StringTokenizer(path, "/");
- int pathLength = tok.countTokens();
- if (pathLength != 2)
- throw new ClusterStorageException("Path length was invalid: "+path);
- String type = tok.nextToken();
-
- ItemPath thisEntity;
- try {
- thisEntity = new ItemPath(sysKey.intValue());
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- }
-
- String objName = tok.nextToken();
- C2KLocalObject newObj;
-
- if (type.equals(PROPERTY)) {
- try {
- Property newProperty = ldapStore.getProperty(thisEntity, objName);
- newObj = newProperty;
- } catch (ObjectNotFoundException ex) {
- throw new ClusterStorageException("Property "+objName+" not found in "+sysKey);
- }
-
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
-
- return newObj;
- }
- // store object by path
- @Override
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
- Logger.msg(6, "LDAPClusterStorage.put() - "+sysKey+"/"+ClusterStorage.getPath(obj));
-
- String type = obj.getClusterType();
-
- ItemPath thisEntity;
- try {
- thisEntity = new ItemPath(sysKey.intValue());
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- }
-
- if (type.equals(PROPERTY)) {
- try {
- ldapStore.setProperty(thisEntity, (Property)obj);
- } catch (Exception e1) {
- Logger.error(e1);
- throw new ClusterStorageException("LDAPClusterStorage - could not write property");
- }
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
-
- }
- // delete cluster
- @Override
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
- StringTokenizer tok = new StringTokenizer(path, "/");
- int pathLength = tok.countTokens();
- if (pathLength != 2)
- throw new ClusterStorageException("Path length was invalid: "+path);
- String type = tok.nextToken();
-
- ItemPath thisEntity;
- try {
- thisEntity = new ItemPath(sysKey.intValue());
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- }
-
- if (type.equals(PROPERTY)) {
- try {
- ldapStore.deleteProperty(thisEntity, tok.nextToken());
- } catch (Exception e1) {
- Logger.error(e1);
- throw new ClusterStorageException("LDAPClusterStorage - could not delete property");
- }
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
-
- }
-
- /* navigation */
-
- // directory listing
- @Override
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
- Logger.msg(6, "LDAPClusterStorage.getClusterContents() - "+sysKey+"/"+path);
- StringTokenizer tok = new StringTokenizer(path, "/");
- int pathLength = tok.countTokens();
- if (pathLength > 1)
- return new String[0];
-
- String type = getClusterType(path);
- try
- {
- ItemPath thisEntity = new ItemPath(sysKey.intValue());
- if (type.equals(PROPERTY))
- return ldapStore.getPropertyNames(thisEntity);
- else
- if (type.equals("")) { // root query
- String[] allClusters = new String[0];
- ArrayList<String> clusterList = new ArrayList<String>();
- if (ldapStore.hasProperties(thisEntity))
- clusterList.add(PROPERTY);
- allClusters = clusterList.toArray(allClusters);
- return allClusters;
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- } catch (ObjectNotFoundException e) {
- throw new ClusterStorageException("Entity "+sysKey+" does not exist");
- }
- }
-}
diff --git a/src/main/java/com/c2kernel/persistency/NextKeyManager.java b/src/main/java/com/c2kernel/persistency/NextKeyManager.java
index e0d0013..48fa5af 100644
--- a/src/main/java/com/c2kernel/persistency/NextKeyManager.java
+++ b/src/main/java/com/c2kernel/persistency/NextKeyManager.java
@@ -4,16 +4,43 @@ import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.process.auth.Authenticator;
+/**
+ * @author abranson
+ *
+ */
public interface NextKeyManager {
+
+ public void open(Authenticator auth);
+ /**
+ *
+ * @return
+ * @throws ObjectCannotBeUpdated
+ * @throws ObjectNotFoundException
+ */
public ItemPath generateNextEntityKey()
throws ObjectCannotBeUpdated, ObjectNotFoundException;
+ /**
+ * @return
+ * @throws ObjectCannotBeUpdated
+ * @throws ObjectNotFoundException
+ */
public AgentPath generateNextAgentKey()
throws ObjectCannotBeUpdated, ObjectNotFoundException;
+ /**
+ * @param sysKey
+ * @throws ObjectCannotBeUpdated
+ * @throws ObjectNotFoundException
+ */
public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException;
+ /**
+ * @return
+ * @throws ObjectNotFoundException
+ */
public ItemPath getLastEntityPath() throws ObjectNotFoundException;
}
diff --git a/src/main/java/com/c2kernel/persistency/TransactionManager.java b/src/main/java/com/c2kernel/persistency/TransactionManager.java
index 94b8123..7362ae1 100644
--- a/src/main/java/com/c2kernel/persistency/TransactionManager.java
+++ b/src/main/java/com/c2kernel/persistency/TransactionManager.java
@@ -329,14 +329,4 @@ public class TransactionManager {
}
- @Deprecated
- public Object query(String id, Object query) throws ClusterStorageException {
- return storage.query(id, query);
- }
-
- @Deprecated
- public String queryToXML(String id, String query, boolean genericFormat) throws ClusterStorageException {
- return storage.queryToXML(id, query, genericFormat);
- }
-
}
diff --git a/src/main/java/com/c2kernel/process/AbstractMain.java b/src/main/java/com/c2kernel/process/AbstractMain.java
index e241ee2..202ae9e 100644
--- a/src/main/java/com/c2kernel/process/AbstractMain.java
+++ b/src/main/java/com/c2kernel/process/AbstractMain.java
@@ -28,7 +28,8 @@ import com.c2kernel.utils.Logger;
**************************************************************************/
abstract public class AbstractMain
{
- public static boolean runningAsWrapper = false;
+ public static boolean isServer = false;
+ private static ShutdownHandler shutdownHandler;
/**************************************************************************
@@ -112,5 +113,19 @@ abstract public class AbstractMain
return c2kProps;
}
-
+
+ public static void setShutdownHandler(ShutdownHandler handler) {
+ shutdownHandler = handler;
+ }
+
+ public static void shutdown(int errCode) {
+ if (shutdownHandler!= null)
+ shutdownHandler.shutdown(errCode, isServer);
+ else
+ try {
+ Gateway.close();
+ } catch (Exception ex) {
+ Logger.error(ex);
+ }
+ }
}
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java
index bcc5e68..bc93676 100644
--- a/src/main/java/com/c2kernel/process/Bootstrap.java
+++ b/src/main/java/com/c2kernel/process/Bootstrap.java
@@ -9,6 +9,7 @@ import java.util.StringTokenizer;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
+import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
@@ -17,17 +18,17 @@ import com.c2kernel.events.History;
import com.c2kernel.lifecycle.CompositeActivityDef;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
-import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
-import com.c2kernel.lifecycle.instance.predefined.ServerPredefinedStepContainer;
+import com.c2kernel.lifecycle.instance.predefined.server.ServerPredefinedStepContainer;
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;
import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.persistency.outcome.OutcomeValidator;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.resource.DefaultResourceImportHandler;
import com.c2kernel.process.resource.ResourceImportHandler;
@@ -116,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);
@@ -162,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);
}
}
@@ -193,6 +195,15 @@ public class Bootstrap
}
// data was missing or doesn't match
+ // validate it
+ OutcomeValidator validator = OutcomeValidator.getValidator(LocalObjectLoader.getSchema(newOutcome.getSchemaType(), newOutcome.getSchemaVersion()));
+ String error = validator.validate(newOutcome.getData());
+ if (error.length() > 0) {
+ Logger.error("Outcome not valid: \n " + error);
+ throw new InvalidDataException(error, "");
+ }
+
+ // store
Logger.msg("Bootstrap.verifyResource() - Writing new "+newOutcome.getSchemaType()+" v"+version+" to "+typeImpHandler.getName()+" "+itemName);
History hist = new History(thisProxy.getSystemKey(), thisProxy);
Transition predefDone = new Transition(0, "Done", 0, 0);
@@ -242,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();
@@ -265,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;
@@ -279,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;
@@ -299,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+"'");
@@ -331,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;
@@ -340,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);
@@ -358,10 +374,7 @@ public class Bootstrap
public static void initServerItemWf() throws Exception {
CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", 0);
- Workflow wf = new Workflow((CompositeActivity)serverWfCa.instantiate());
- PredefinedStepContainer predef = (PredefinedStepContainer)wf.search("workflow/predefined");
- wf.getChildGraphModel().removeVertex(predef);
- wf.addChild(new ServerPredefinedStepContainer(), predef.getCentrePoint());
+ Workflow wf = new Workflow((CompositeActivity)serverWfCa.instantiate(), new ServerPredefinedStepContainer());
wf.initialise(thisServerPath.getSysKey(), systemAgents.get("system").getPath());
Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null);
}
diff --git a/src/main/java/com/c2kernel/process/ClientShell.java b/src/main/java/com/c2kernel/process/ClientShell.java
index b6afb2c..9f1d3ab 100644
--- a/src/main/java/com/c2kernel/process/ClientShell.java
+++ b/src/main/java/com/c2kernel/process/ClientShell.java
@@ -33,7 +33,7 @@ public class ClientShell extends StandardClient {
}
System.out.print("> ");
}
- close();
+ shutdown(0);
}
public static void main(String[] args) throws Exception {
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java
index 2db7aa1..7a040ac 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;
@@ -111,7 +114,7 @@ public class Gateway
// init module manager
try {
- mModules = new ModuleManager(mResource.getModuleDefURLs(), AbstractMain.runningAsWrapper);
+ mModules = new ModuleManager(mResource.getModuleDefURLs(), AbstractMain.isServer);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Could not load module definitions.", "");
@@ -145,13 +148,20 @@ public class Gateway
*
* @throws InvalidDataException - error initialising
*/
- static public void startServer() 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");
+ mNextKeyManager.open(auth);
// start entity proxy server
mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
@@ -165,7 +175,8 @@ public class Gateway
//TODO: externalize this (or replace corba completely)
mC2KProps.put("com.sun.CORBA.POA.ORBServerId", "1");
mC2KProps.put("com.sun.CORBA.POA.ORBPersistentServerPort", serverPort);
-
+ mC2KProps.put("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109"); // need to force UTF-8 in the Sun ORB
+ mC2KProps.put("com.sun.CORBA.codeset.wcharsets", "0x00010109, 0x05010001");
//Standard initialisation of the ORB
mORB = org.omg.CORBA.ORB.init(new String[0], mC2KProps);
@@ -196,7 +207,7 @@ public class Gateway
* @throws InvalidDataException - bad params
* @throws ClusterStorageException - error starting storages
*/
- static public void connect()
+ static public Authenticator connect()
throws InvalidDataException,
ClusterStorageException
{
@@ -210,6 +221,7 @@ public class Gateway
mStorage = new TransactionManager(auth);
mProxyManager = new ProxyManager();
+ return auth;
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidDataException("Cannot connect server process. Please check config.", "");
@@ -254,6 +266,12 @@ public class Gateway
return userProxy;
}
+
+ static public AgentProxy connect(String agentName, String agentPassword)
+ throws InvalidDataException, ObjectNotFoundException, ClusterStorageException, InstantiationException, IllegalAccessException, ClassNotFoundException
+ {
+ return connect(agentName, agentPassword, null);
+ }
/**
* Shuts down all kernel api objects
@@ -299,8 +317,12 @@ public class Gateway
static public org.omg.CORBA.ORB getORB()
{
if (orbDestroyed) throw new RuntimeException("Gateway has been closed. ORB is destroyed.");
- if (mORB == null)
+
+ if (mORB == null) {
+ mC2KProps.put("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109"); // need to force UTF-8 in the Sun ORB
+ mC2KProps.put("com.sun.CORBA.codeset.wcharsets", "0x00010109, 0x05010001");
mORB = org.omg.CORBA.ORB.init(new String[0], mC2KProps);
+ }
return mORB;
}
@@ -309,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/process/ShutdownHandler.java b/src/main/java/com/c2kernel/process/ShutdownHandler.java
new file mode 100644
index 0000000..aaed899
--- /dev/null
+++ b/src/main/java/com/c2kernel/process/ShutdownHandler.java
@@ -0,0 +1,6 @@
+package com.c2kernel.process;
+
+public interface ShutdownHandler {
+
+ public void shutdown(int errCode, boolean isServer);
+}
diff --git a/src/main/java/com/c2kernel/process/StandardClient.java b/src/main/java/com/c2kernel/process/StandardClient.java
index 5978068..d2b58a5 100644
--- a/src/main/java/com/c2kernel/process/StandardClient.java
+++ b/src/main/java/com/c2kernel/process/StandardClient.java
@@ -18,9 +18,4 @@ abstract public class StandardClient extends AbstractMain
Gateway.init(readC2KArgs(args));
//AgentProxy user = Gateway.connect("username", "password");
}
-
- static public void close() {
- Gateway.close();
- }
-
}
diff --git a/src/main/java/com/c2kernel/process/StandardServer.java b/src/main/java/com/c2kernel/process/StandardServer.java
index e283cb6..5855d7e 100644
--- a/src/main/java/com/c2kernel/process/StandardServer.java
+++ b/src/main/java/com/c2kernel/process/StandardServer.java
@@ -10,9 +10,7 @@
package com.c2kernel.process;
-import org.tanukisoftware.wrapper.WrapperListener;
-import org.tanukisoftware.wrapper.WrapperManager;
-
+import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.utils.Logger;
/**************************************************************************
@@ -21,108 +19,39 @@ import com.c2kernel.utils.Logger;
* @author $Author: abranson $ $Date: 2005/04/28 13:49:43 $
* @version $Revision: 1.47 $
**************************************************************************/
-public class StandardServer extends AbstractMain implements WrapperListener
+public class StandardServer extends AbstractMain
{
protected static StandardServer server;
-
- /**************************************************************************
- * C2KRootPOA suitable for Factory objects
- **************************************************************************/
-
-
-
-
-
/**************************************************************************
* void StandardInitalisation( String[] )
*
* Set-up calls to ORB, POA and Factorys, both optional and required.
**************************************************************************/
- protected void standardInitialisation( String[] args )
+ protected static void standardInitialisation( String[] args )
throws Exception
{
+ isServer = true;
+
// read args and init Gateway
Gateway.init(readC2KArgs(args));
// connect to LDAP as root
- Gateway.connect();
+ Authenticator auth = Gateway.connect();
//start console
Logger.initConsole("ItemServer");
//initialize the server objects
- Gateway.startServer();
+ Gateway.startServer(auth);
Logger.msg(5, "StandardServer::standardInitialisation - complete.");
}
-
- /**************************************************************************
- * Sets up and runs and item server
- **************************************************************************/
- @Override
- public Integer start(String[] args)
+ public static void main(String[] args) throws Exception
{
- try
- {
- //initialise everything
- standardInitialisation( args );
- }
- catch( Exception ex )
- {
- ex.printStackTrace();
- Logger.die("Startup failed");
- }
- return null;
- }
-
- public static void main(String[] args) {
- AbstractMain.runningAsWrapper = true;
- server = new StandardServer();
- WrapperManager.start( server, args );
- }
-
- /**
- *
- */
- @Override
- public void controlEvent(int event) {
- if (WrapperManager.isControlledByNativeWrapper()) {
- // The Wrapper will take care of this event
- } else {
- // We are not being controlled by the Wrapper, so
- // handle the event ourselves.
- if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) ||
- (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) ||
- (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)){
- WrapperManager.stop(0);
- }
- }
-
+ //initialise everything
+ standardInitialisation( args );
}
-
- /**************************************************************************
- * Closes all listeners, quits the VM.
- * This method should be called to kill the server process
- * e.g. from the NT service wrapper
- **************************************************************************/
- @Override
- public int stop(int arg0) {
- WrapperManager.signalStopping(10000);
- try
- {
- Gateway.close();
- }
- catch( Exception ex )
- {
- Logger.error(ex);
- return 1;
- }
-
- Logger.msg("StandardServer::shutdown - complete. ");
- return 0;
- }
-
}
diff --git a/src/main/java/com/c2kernel/process/auth/Authenticator.java b/src/main/java/com/c2kernel/process/auth/Authenticator.java
index 40defc4..44745da 100644
--- a/src/main/java/com/c2kernel/process/auth/Authenticator.java
+++ b/src/main/java/com/c2kernel/process/auth/Authenticator.java
@@ -3,14 +3,71 @@ package com.c2kernel.process.auth;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
-
+/**
+ * This interface is used by the kernel to store an authenticated connection
+ * and/or token that will be used by kernel components. The CRISTAL property
+ * 'Authenticator' is used to specify the implementation used. It is
+ * instantiated by the connect() methods of the Gateway, and will be found in
+ * the AgentProxy returned by connect(). Lookup and ClusterStorage instances are
+ * initialized with this Authenticator, which is expected to maintain the same
+ * user's connection through the process lifetime, reconnecting if the
+ * connection is lost.
+ *
+ * @since 3.0
+ *
+ */
public interface Authenticator {
-
- public boolean authenticate(String agentName, String password, String resource) throws InvalidDataException, ObjectNotFoundException;
-
- public boolean authenticate(String resource) throws InvalidDataException, ObjectNotFoundException;
-
+
+ /**
+ * Authenticates a CRISTAL agent. If this method returns true, then the
+ * connect method will create and return an AgentProxy for the given
+ * username using the Lookup and ProxyManager.
+ *
+ * @param agentName
+ * The username of the Agent to be authenticated. This must be
+ * already present as an Agent in the CRISTAL directory.
+ * @param password
+ * The Agent's password
+ * @param resource
+ * The authentication resource/domain/realm of the agent.
+ * Included so that domains may include CRISTAL users from
+ * different realms. This parameter is passed into the connect()
+ * method if required. May be null.
+ * @return a boolean indicating if the authentication was successful. If so,
+ * then the Gateway will generate an AgentProxy for the given user.
+ * @throws ObjectNotFoundException
+ * When the Agent doesn't exist
+ * @throws InvalidDataException
+ * When authentication fails for another reason
+ */
+ public boolean authenticate(String agentName, String password,
+ String resource) throws InvalidDataException,
+ ObjectNotFoundException;
+
+ /**
+ * Authenticates a superuser connection for the server. It must be able to
+ * act on behalf of any other Agent, as the server needs to do this.
+ * Credentials may be in the CRISTAL properties, or some other mechanism.
+ *
+ * @param resource
+ * @return
+ * @throws InvalidDataException
+ * @throws ObjectNotFoundException
+ */
+ public boolean authenticate(String resource) throws InvalidDataException,
+ ObjectNotFoundException;
+
+ /**
+ * Lookup and storage implementations that need to use user or superuser
+ * authentication can retrieve it using this method. This will be highly
+ * implementation specific.
+ *
+ * @return the connection/token created during authentication
+ */
public Object getAuthObject();
-
+
+ /**
+ * Close or expire the connection as the CRISTAL process shuts down.
+ */
public void disconnect();
}
diff --git a/src/main/java/com/c2kernel/process/auth/ProxyLogin.java b/src/main/java/com/c2kernel/process/auth/ProxyLogin.java
index 94416cf..665158c 100644
--- a/src/main/java/com/c2kernel/process/auth/ProxyLogin.java
+++ b/src/main/java/com/c2kernel/process/auth/ProxyLogin.java
@@ -4,9 +4,18 @@ import java.util.Properties;
import com.c2kernel.entity.proxy.AgentProxy;
+/**
+ * This interface is used by client processes to implement alternative login
+ * mechanisms aside from the standard username and password. Implementations may
+ * synchronize Agents with an external user library, such as Active Directory.
+ * Implementations are expected to set up the Gateway process and its
+ * authenticated components itself.
+ *
+ */
public interface ProxyLogin {
- public void initialize(Properties props) throws Exception;
- public AgentProxy authenticate(String resource) throws Exception;
-
+ public void initialize(Properties props) throws Exception;
+
+ public AgentProxy authenticate(String resource) throws Exception;
+
}
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java
index 873754f..195c883 100644
--- a/src/main/java/com/c2kernel/process/module/Module.java
+++ b/src/main/java/com/c2kernel/process/module/Module.java
@@ -84,6 +84,7 @@ public class Module {
thisRes.resourceType, thisRes.resourceLocation, info.layer, reset);
} catch (Exception ex) {
Logger.error(ex);
+ Logger.die("Error importing module resources. Unsafe to continue.");
}
}
@@ -148,4 +149,4 @@ public class Module {
public boolean hasDependency(String dep) {
return info.dependency.contains(dep);
}
-} \ No newline at end of file
+}
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 );
+ }
/**************************************************************************
*
diff --git a/src/main/java/com/c2kernel/scripting/ScriptConsole.java b/src/main/java/com/c2kernel/scripting/ScriptConsole.java
index 8b668a1..6b77a4f 100644
--- a/src/main/java/com/c2kernel/scripting/ScriptConsole.java
+++ b/src/main/java/com/c2kernel/scripting/ScriptConsole.java
@@ -14,8 +14,7 @@ import java.util.StringTokenizer;
import javax.script.Bindings;
import javax.script.ScriptEngine;
-import org.tanukisoftware.wrapper.WrapperManager;
-
+import com.c2kernel.process.AbstractMain;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.server.SocketHandler;
@@ -190,7 +189,7 @@ public class ScriptConsole implements SocketHandler {
// process control
if (command.equals("shutdown")) {
- WrapperManager.stop(0);
+ AbstractMain.shutdown(0);
}
else {
context.setScript(command);
diff --git a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java
index 98ebbda..4b0a8b0 100644
--- a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java
+++ b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java
@@ -69,13 +69,13 @@ public class CastorXMLUtility
mappingContext.addMapping(thisMapping);
} catch (MappingException ex) {
Logger.error(ex);
- throw new InvalidDataException("XML Mapping files are not valid: "+ex.getMessage());
+ throw new InvalidDataException("XML Mapping files are not valid: "+ex.getMessage(), "");
} catch (MalformedURLException ex) {
Logger.error(ex);
- throw new InvalidDataException("Mapping file location invalid: "+ex.getMessage());
+ throw new InvalidDataException("Mapping file location invalid: "+ex.getMessage(), "");
} catch (IOException ex) {
Logger.error(ex);
- throw new InvalidDataException("Could not read XML mapping files: "+ex.getMessage());
+ throw new InvalidDataException("Could not read XML mapping files: "+ex.getMessage(), "");
}
Logger.msg(1, "Loaded all maps from "+mapURL.toString());
diff --git a/src/main/java/com/c2kernel/utils/Logger.java b/src/main/java/com/c2kernel/utils/Logger.java
index 176f190..fffd191 100644
--- a/src/main/java/com/c2kernel/utils/Logger.java
+++ b/src/main/java/com/c2kernel/utils/Logger.java
@@ -6,8 +6,6 @@ import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Iterator;
-import org.tanukisoftware.wrapper.WrapperManager;
-
import com.c2kernel.process.AbstractMain;
import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.ScriptConsole;
@@ -122,10 +120,7 @@ public class Logger
static public void die(String msg)
{
printMessage("FATAL : " + msg, 0);
- if (AbstractMain.runningAsWrapper)
- WrapperManager.stop(1);
- else
- System.exit(1);
+ AbstractMain.shutdown(1);
}
/**
* @param console