summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/process
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-06-02 11:31:08 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-06-02 11:31:08 +0200
commitb96dd998d6c442be19c342399839896d00d4b6f5 (patch)
tree51a0a07647e1d439d0adefdb57e6818a15d179ec /src/main/java/com/c2kernel/process
parent42adf60503b73c5106b30ba57fdeba13b3091169 (diff)
Initial commit
Diffstat (limited to 'src/main/java/com/c2kernel/process')
-rw-r--r--src/main/java/com/c2kernel/process/Bootstrap.java40
-rw-r--r--src/main/java/com/c2kernel/process/Gateway.java181
-rw-r--r--src/main/java/com/c2kernel/process/auth/Authenticator.java14
-rw-r--r--src/main/java/com/c2kernel/process/module/Module.java6
-rw-r--r--src/main/java/com/c2kernel/process/module/ModuleScript.java2
5 files changed, 83 insertions, 160 deletions
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java
index f273c5d..25ea512 100644
--- a/src/main/java/com/c2kernel/process/Bootstrap.java
+++ b/src/main/java/com/c2kernel/process/Bootstrap.java
@@ -1,8 +1,8 @@
package com.c2kernel.process;
import java.net.InetAddress;
-import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
@@ -22,7 +22,7 @@ import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.lookup.LDAPLookup;
+import com.c2kernel.lookup.Lookup;
import com.c2kernel.lookup.Path;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.persistency.ClusterStorage;
@@ -120,13 +120,13 @@ public class Bootstrap
// Find or create Item for Resource
DomainPath modDomPath = typeImpHandler.getPath(itemName, ns);
ItemProxy thisProxy;
- Enumeration<Path> en = Gateway.getLDAPLookup().search(typeImpHandler.getTypeRoot(), itemName);
- if (!en.hasMoreElements()) {
+ Iterator<Path> en = Gateway.getLookup().search(typeImpHandler.getTypeRoot(), itemName);
+ if (!en.hasNext()) {
Logger.msg("Bootstrap.verifyResource() - "+typeImpHandler.getName()+" "+itemName+" not found. Creating new.");
thisProxy = createResourceItem(typeImpHandler, itemName, layer, ns);
}
else {
- DomainPath path = (DomainPath)en.nextElement();
+ DomainPath path = (DomainPath)en.next();
thisProxy = Gateway.getProxyManager().getProxy(path);
// Verify module property and location
@@ -160,8 +160,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.getLDAPLookup().add(modDomPath);
- Gateway.getLDAPLookup().delete(path);
+ Gateway.getLookup().add(modDomPath);
+ Gateway.getLookup().delete(path);
}
}
@@ -261,12 +261,12 @@ public class Bootstrap
}
- ItemPath entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
+ ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
Gateway.getCorbaServer().createEntity(entityPath);
- Gateway.getLDAPLookup().add(entityPath);
+ Gateway.getLookup().add(entityPath);
DomainPath newDomPath = impHandler.getPath(itemName, ns);
newDomPath.setEntity(entityPath);
- Gateway.getLDAPLookup().add(newDomPath);
+ Gateway.getLookup().add(newDomPath);
ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(entityPath);
newItemProxy.initialise( 1, props, ca, null);
return newItemProxy;
@@ -277,9 +277,9 @@ 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.");
- LDAPLookup lookup = Gateway.getLDAPLookup();
+ Lookup lookup = Gateway.getLookup();
try {
- lookup.getRoleManager().getAgentPath(name);
+ lookup.getAgentPath(name);
Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found.");
return;
} catch (ObjectNotFoundException ex) { }
@@ -287,17 +287,17 @@ public class Bootstrap
RolePath rolePath;
try {
- rolePath = lookup.getRoleManager().getRolePath(role);
+ rolePath = lookup.getRolePath(role);
} catch (ObjectNotFoundException ex) {
- rolePath = lookup.getRoleManager().createRole(role, joblist);
+ rolePath = lookup.createRole(role, joblist);
}
try {
- ItemPath entityPath = lookup.getNextKeyManager().generateNextEntityKey();
+ ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name);
agentPath.setPassword(pass);
Gateway.getCorbaServer().createEntity(agentPath);
- Gateway.getLDAPLookup().add(agentPath);
+ Gateway.getLookup().add(agentPath);
// assign admin role
Logger.msg("Bootstrap.checkAgent() - Assigning role '"+role+"'");
@@ -335,11 +335,11 @@ public class Bootstrap
serverEntity = thisServerPath.getEntity();
} catch (ObjectNotFoundException ex) {
Logger.msg("Creating server item "+thisServerPath);
- serverEntity = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
+ serverEntity = Gateway.getNextKeyManager().generateNextEntityKey();
Gateway.getCorbaServer().createEntity(serverEntity);
- Gateway.getLDAPLookup().add(serverEntity);
+ Gateway.getLookup().add(serverEntity);
thisServerPath.setEntity(serverEntity);
- Gateway.getLDAPLookup().add(thisServerPath);
+ Gateway.getLookup().add(thisServerPath);
}
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Name", serverName, false), null);
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server", false), null);
@@ -359,7 +359,7 @@ public class Bootstrap
PredefinedStepContainer predef = (PredefinedStepContainer)wf.search("workflow/predefined");
wf.getChildGraphModel().removeVertex(predef);
wf.addChild(new ServerPredefinedStepContainer(), predef.getCentrePoint());
- wf.initialise(thisServerPath.getSysKey(), Gateway.getLDAPLookup().getRoleManager().getAgentPath("system"));
+ wf.initialise(thisServerPath.getSysKey(), Gateway.getLookup().getAgentPath("system"));
Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null);
}
}
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java
index 01cc202..9fe51a0 100644
--- a/src/main/java/com/c2kernel/process/Gateway.java
+++ b/src/main/java/com/c2kernel/process/Gateway.java
@@ -16,10 +16,11 @@ import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ProxyManager;
import com.c2kernel.entity.proxy.ProxyServer;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.LDAPLookup;
-import com.c2kernel.lookup.LDAPProperties;
+import com.c2kernel.lookup.Lookup;
import com.c2kernel.persistency.ClusterStorageException;
+import com.c2kernel.persistency.NextKeyManager;
import com.c2kernel.persistency.TransactionManager;
+import com.c2kernel.process.auth.Authenticator;
import com.c2kernel.process.module.ModuleManager;
import com.c2kernel.process.resource.Resource;
import com.c2kernel.process.resource.ResourceLoader;
@@ -37,7 +38,7 @@ import com.c2kernel.utils.ObjectProperties;
*
* Child objects:
* <ul>
- * <li>LDAPLookup - Provides access to the CRISTAL directory. Find or
+ * <li>Lookup - Provides access to the CRISTAL directory. Find or
* search for Items or Agents.
* <li>EntityProxyManager - Gives a local proxy object for Entities found
* in LDAP. Execute activities in Items, query or subscribe to Entity data.
@@ -56,13 +57,13 @@ public class Gateway
static private ModuleManager mModules;
static private org.omg.CORBA.ORB mORB;
static private boolean orbDestroyed = false;
- static private LDAPLookup mLDAPLookup;
+ static private Lookup mLookup;
+ static private NextKeyManager mNextKeyManager;
static private TransactionManager mStorage;
static private ProxyManager mProxyManager;
static private ProxyServer mProxyServer;
static private CorbaServer mCorbaServer;
static private CastorXMLUtility mMarshaller;
- static private AgentProxy mCurrentUser = null;
static private ResourceLoader mResource;
@@ -71,7 +72,7 @@ public class Gateway
/**
* Initialises the Gateway and all of the client objects it holds, with
- * the exception of the LDAPLookup, which is initialised during connect()
+ * the exception of the Lookup, which is initialised during connect()
*
* @param props - java.util.Properties containing all application properties.
* If null, the java system properties are used
@@ -83,7 +84,7 @@ public class Gateway
/**
* Initialises the Gateway and all of the client objects it holds, with
- * the exception of the LDAPLookup, which is initialised during connect()
+ * the exception of the Lookup, which is initialised during connect()
*
* @param props - java.util.Properties containing all application properties.
* If null, the java system properties are used
@@ -149,8 +150,8 @@ public class Gateway
*/
static public void startServer() throws InvalidDataException {
try {
- // check top level LDAP contexts
- mLDAPLookup.install();
+ // check top level directory contexts
+ mLookup.initializeDirectory();
// start entity proxy server
mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
@@ -199,140 +200,54 @@ public class Gateway
throws InvalidDataException,
ClusterStorageException
{
- LDAPProperties ldapProps = new LDAPProperties();
-
- if( ldapProps.mHost != null && ldapProps.mPort != null &&
- ldapProps.mUser != null && ldapProps.mPassword != null )
- {
- try
- {
- mLDAPLookup = new LDAPLookup(ldapProps);
- }
- catch (Exception ex)
- {
- Logger.error(ex);
- throw new InvalidDataException("Cannot authenticate. Name and/or password invalid.", "");
- }
- }
- else
- {
- Logger.error("LDAP properties not set for server login.");
- throw new InvalidDataException("Cannot authenticate with LDAP.", "");
- }
-
- setup();
- }
-
- /**
- * Authenticates a user and returns and AgentProxy on them without overriding the system LDAP context.
- * Useful for handling multiple users in one context e.g. on a web server
- *
- * @param agentName - username
- * @param agentPassword - password
- * @return AgentProxy on that user
- * @throws InvalidDataException
- * @throws ObjectNotFoundException
- */
- static public AgentProxy login(String agentName, String agentPassword) throws InvalidDataException, ObjectNotFoundException {
- LDAPProperties ldapProps = new LDAPProperties();
- AgentPath agentPath;
- try {
- agentPath = mLDAPLookup.getRoleManager().getAgentPath(agentName);
- } catch (Exception ex) {
+ try {
+ Authenticator auth = (Authenticator)mC2KProps.getInstance("Authenticator");
+ auth.authenticate("System");
+
+ mLookup = (Lookup)mC2KProps.getInstance("Lookup");
+ mLookup.open(auth);
+
+ mStorage = new TransactionManager();
+ mProxyManager = new ProxyManager();
+
+ } catch (Exception ex) {
Logger.error(ex);
- throw new ObjectNotFoundException("Could not resolve agent", "");
+ throw new InvalidDataException("Cannot authenticate. Name and/or password invalid.", "");
}
- String agentDN = agentPath.getFullDN();
- ldapProps.mUser = agentDN;
- ldapProps.mPassword = agentPassword;
- try {
- LDAPLookup.createConnection(ldapProps);
- return (AgentProxy)getProxyManager().getProxy(mLDAPLookup.getRoleManager().getAgentPath(agentName));
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Could not log in", "");
- }
- }
+ }
/**
- * Logs into the LDAP server with the given username and password, and initialises the lookup.
+ * Logs in with the given username and password, and initialises the lookup, storage and proxy manager.
*
* @param agentName - username
* @param agentPassword - password
* @return an AgentProxy on the requested user
* @throws InvalidDataException
+ * @throws ClusterStorageException
+ * @throws ClassNotFoundException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
*/
- static public AgentProxy connect(String agentName, String agentPassword)
- throws InvalidDataException, ObjectNotFoundException
- {
-
- LDAPProperties ldapProps = new LDAPProperties();
- if (ldapProps.mHost!=null && ldapProps.mPort!= null && ldapProps.mLocalPath!=null )
- {
- try {
- ldapProps.mUser = "";
- ldapProps.mPassword = "";
- mLDAPLookup = new LDAPLookup(ldapProps);
- String agentDN = mLDAPLookup.getRoleManager().getAgentPath(agentName).getFullDN();
-
- //found agentDN, try to log in with it
- ldapProps.mUser = agentDN;
- ldapProps.mPassword = agentPassword;
- mLDAPLookup = new LDAPLookup(ldapProps);
-
- // find agent proxy
- AgentPath agentPath = mLDAPLookup.getRoleManager().getAgentPath(agentName);
-
- if (agentPath!=null)
- {
- setup();
- mCurrentUser = (AgentProxy) mProxyManager.getProxy(agentPath);
- return mCurrentUser;
- }
- else
- {
- throw new InvalidDataException("The agentDN " +agentDN+ " is invalid.", "");
- }
- } catch (ClusterStorageException e) {
- throw new InvalidDataException(Language.translate("Error initialising storage")+Language.translate(". See log."), "");
- } catch (ObjectNotFoundException e) {
- throw new ObjectNotFoundException(Language.translate("Invalid username/password"), "");
- } catch (Exception e) {
- throw new InvalidDataException(Language.translate("Could not log in")+": "+Language.translate(e.getMessage()), "");
- }
-
- }
- else
- {
- throw new InvalidDataException("Cannot log in. Some connection properties are not set.", "");
- }
-
- }
-
- /**
- * @return the mCurrentUser
- */
- public static AgentProxy getCurrentUser() {
- return mCurrentUser;
- }
-
- /**
- * Initializes the storage and proxy manager, called during connect.
- *
- * @throws InvalidDataException
- * @throws ClusterStorageException
- */
- static private void setup()
- throws InvalidDataException,
- ClusterStorageException
+ static public AgentProxy connect(String resource, String agentName, String agentPassword)
+ throws InvalidDataException, ObjectNotFoundException, ClusterStorageException, InstantiationException, IllegalAccessException, ClassNotFoundException
{
+ Authenticator auth = (Authenticator)mC2KProps.getInstance("Authenticator");
+ if (!auth.authenticate(resource, agentName, agentPassword))
+ throw new InvalidDataException("Login failed", "");
+
+ mLookup = (Lookup)mC2KProps.getInstance("Lookup");
+ mLookup.open(auth);
- // Init storages
mStorage = new TransactionManager();
mProxyManager = new ProxyManager();
+ // find agent proxy
+ AgentPath agentPath = mLookup.getAgentPath(agentName);
+ AgentProxy userProxy = (AgentProxy) mProxyManager.getProxy(agentPath);
+ userProxy.setAuthObj(auth);
+ return userProxy;
}
/**
@@ -354,9 +269,9 @@ public class Gateway
mStorage = null;
// disconnect from ldap
- if (mLDAPLookup != null)
- mLDAPLookup.disconnect();
- mLDAPLookup = null;
+ if (mLookup != null)
+ mLookup.close();
+ mLookup = null;
// shut down proxy manager & server
if (mProxyServer != null)
@@ -384,9 +299,9 @@ public class Gateway
return mORB;
}
- static public LDAPLookup getLDAPLookup()
+ static public Lookup getLookup()
{
- return mLDAPLookup;
+ return mLookup;
}
static public CorbaServer getCorbaServer()
@@ -461,5 +376,9 @@ public class Gateway
}
}
+
+ public static NextKeyManager getNextKeyManager() {
+ return mNextKeyManager;
+ }
}
diff --git a/src/main/java/com/c2kernel/process/auth/Authenticator.java b/src/main/java/com/c2kernel/process/auth/Authenticator.java
index ae18474..61986a6 100644
--- a/src/main/java/com/c2kernel/process/auth/Authenticator.java
+++ b/src/main/java/com/c2kernel/process/auth/Authenticator.java
@@ -1,12 +1,16 @@
package com.c2kernel.process.auth;
-import java.util.Properties;
+import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.proxy.AgentProxy;
public interface Authenticator {
-
- public void initialize(Properties props) throws Exception;
- public AgentProxy authenticate(String resource) throws Exception;
+ public boolean authenticate(String resource, String agentName, String password) throws InvalidDataException, ObjectNotFoundException;
+
+ public boolean authenticate(String resource) throws InvalidDataException, ObjectNotFoundException;
+
+ public Object getAuthObject();
+
+ public void disconnect();
}
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java
index 2c182ea..9c52fee 100644
--- a/src/main/java/com/c2kernel/process/module/Module.java
+++ b/src/main/java/com/c2kernel/process/module/Module.java
@@ -75,7 +75,7 @@ public class Module {
public void importAll(ItemProxy serverEntity, String moduleXML, boolean reset) throws Exception {
addModuleItem(moduleXML);
- int systemAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey();
+ int systemAgentId = Gateway.getLookup().getAgentPath("system").getSysKey();
for (ModuleResource thisRes : imports.getResources()) {
try {
@@ -89,7 +89,7 @@ public class Module {
for (NewRole thisRole : imports.getRoles()) {
RolePath rolePath;
try {
- rolePath = Gateway.getLDAPLookup().getRoleManager().getRolePath(thisRole.name);
+ rolePath = Gateway.getLookup().getRolePath(thisRole.name);
if (rolePath.hasJobList() != thisRole.jobList) {
Logger.msg("Module.importAll() - Role '"+thisRole.name+"' has incorrect joblist settings. Correcting.");
rolePath.setHasJobList(thisRole.jobList);
@@ -102,7 +102,7 @@ public class Module {
for (NewAgent thisAgent : imports.getAgents()) {
try {
- Gateway.getLDAPLookup().getRoleManager().getAgentPath(thisAgent.name);
+ Gateway.getLookup().getAgentPath(thisAgent.name);
Logger.msg(3, "Module.importAll() - User '"+thisAgent.name+"' found.");
continue;
} catch (ObjectNotFoundException ex) { }
diff --git a/src/main/java/com/c2kernel/process/module/ModuleScript.java b/src/main/java/com/c2kernel/process/module/ModuleScript.java
index beed6f9..e948996 100644
--- a/src/main/java/com/c2kernel/process/module/ModuleScript.java
+++ b/src/main/java/com/c2kernel/process/module/ModuleScript.java
@@ -27,7 +27,7 @@ public class ModuleScript {
AgentProxy user = Gateway.getCurrentUser();
try {
if (user == null) user = (AgentProxy)Gateway.getProxyManager().getProxy(
- Gateway.getLDAPLookup().getRoleManager().getAgentPath("system"));
+ Gateway.getLookup().getAgentPath("system"));
} catch (Exception ex) {
throw new ScriptingEngineException("System agent unavailable");
}