summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-06-05 14:13:37 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-06-05 14:13:37 +0200
commitcedb32b6b7a799ef4142b418e64d3538cf604af1 (patch)
tree20b6975f944132485beff9304869df0ac589da36
parent28f6763508612fadcc34d87cff383e6a5aef2ad6 (diff)
Recreate old Authenticator interface as 'ProxyLogin'
Server boots with new lookup interface.
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/ProxyManager.java22
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java12
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java17
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java4
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java15
-rw-r--r--src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java5
-rw-r--r--src/main/java/com/c2kernel/process/Bootstrap.java9
-rw-r--r--src/main/java/com/c2kernel/process/ClientShell.java4
-rw-r--r--src/main/java/com/c2kernel/process/Gateway.java10
-rw-r--r--src/main/java/com/c2kernel/process/UserCodeProcess.java8
-rw-r--r--src/main/java/com/c2kernel/process/auth/ConsoleAuth.java4
-rw-r--r--src/main/java/com/c2kernel/process/auth/ProxyLogin.java12
-rw-r--r--src/main/java/com/c2kernel/process/module/Module.java9
-rw-r--r--src/main/java/com/c2kernel/process/module/ModuleManager.java12
-rw-r--r--src/main/java/com/c2kernel/process/module/ModuleScript.java11
-rw-r--r--src/main/java/com/c2kernel/scripting/ScriptConsole.java10
-rw-r--r--src/main/java/com/c2kernel/utils/ObjectProperties.java10
17 files changed, 106 insertions, 68 deletions
diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java
index 9503e54..2b2e0e9 100644
--- a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java
+++ b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java
@@ -156,7 +156,7 @@ public class ProxyManager
**************************************************************************/
private ItemProxy createProxy( org.omg.CORBA.Object ior,
int systemKey,
- boolean isItem )
+ boolean isAgent )
throws ObjectNotFoundException
{
@@ -164,13 +164,13 @@ public class ProxyManager
Logger.msg(5, "ProxyManager::creating proxy on Item " + systemKey);
- if( isItem )
+ if( isAgent )
{
- newProxy = new ItemProxy(ior, systemKey);
+ newProxy = new AgentProxy(ior, systemKey);
}
else
{
- newProxy = new AgentProxy(ior, systemKey);
+ newProxy = new ItemProxy(ior, systemKey);
}
// subscribe to changes from server
@@ -194,7 +194,7 @@ public class ProxyManager
**************************************************************************/
private ItemProxy getProxy( org.omg.CORBA.Object ior,
int systemKey,
- boolean isItem )
+ boolean isAgent )
throws ObjectNotFoundException
{
Integer key = new Integer(systemKey);
@@ -205,7 +205,7 @@ public class ProxyManager
newProxy = proxyPool.get(key);
if (newProxy == null) {
// create a new one
- newProxy = createProxy(ior, systemKey, isItem );
+ newProxy = createProxy(ior, systemKey, isAgent );
proxyPool.put(key, newProxy);
}
return newProxy;
@@ -224,12 +224,18 @@ public class ProxyManager
//convert namePath to dn format
Logger.msg(8,"ProxyManager::getProxy(" + path.toString() + ")");
- boolean isItem = !(path.getEntity() instanceof AgentPath);
+ boolean isAgent = (path.getEntity() instanceof AgentPath);
return getProxy( Gateway.getLookup().resolve(path),
path.getSysKey(),
- isItem );
+ isAgent );
}
+
+ public AgentProxy getAgentProxy( AgentPath path )
+ throws ObjectNotFoundException
+ {
+ return (AgentProxy) getProxy(path);
+ }
/**************************************************************************
* void reportCurrentProxies()
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java
index 20d16c3..4c26de6 100644
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java
+++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java
@@ -26,7 +26,8 @@ public class LDAPAuthManager implements Authenticator {
ldapProps.mUser = "";
ldapProps.mPassword = "";
mLDAPConn = LDAPLookupUtils.createConnection(ldapProps);
- LDAPLookup anonLookup = new LDAPLookup(ldapProps, this);
+ LDAPLookup anonLookup = new LDAPLookup(ldapProps);
+ anonLookup.open(this);
String agentDN = anonLookup.getFullDN(anonLookup.getAgentPath(agentName));
//found agentDN, try to log in with it
@@ -47,10 +48,17 @@ public class LDAPAuthManager implements Authenticator {
@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.");
- return authenticate(null, ldapProps.mUser, ldapProps.mPassword);
+ try {
+ mLDAPConn = LDAPLookupUtils.createConnection(ldapProps);
+ return true;
+ } catch (LDAPException e) {
+ return false;
+ }
}
@Override
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java
index a5624b1..a96a46b 100644
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java
+++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java
@@ -66,7 +66,7 @@ public class LDAPLookup implements Lookup
*
* @param props The LDAP properties object that extracts LDAP connection properties from the global c2kprops
*/
- public LDAPLookup(LDAPProperties props, LDAPAuthManager auth) throws LDAPException
+ public LDAPLookup(LDAPProperties props)
{
Logger.msg(8,"LDAPLookup - initialising.");
@@ -80,10 +80,15 @@ public class LDAPLookup implements Lookup
}
+ public LDAPLookup() {
+ this(new LDAPProperties(Gateway.getProperties()));
+ }
+
@Override
public void open(Authenticator auth) {
mLDAPAuth = (LDAPAuthManager)auth;
mNextKeyManager = new LDAPNextKeyManager(mLDAPAuth, "cn=last,"+mItemTypeRoot);
+ Gateway.getProperties().setProperty("NextKeyManager", mNextKeyManager);
Logger.msg(7, "LDAP.useOldProps="+Gateway.getProperties().getBoolean("LDAP.useOldProps", false));
mPropManager = new LDAPPropertyManager(this, mLDAPAuth);
}
@@ -330,7 +335,7 @@ public class LDAPLookup implements Lookup
{
LDAPSearchResults res = mLDAPAuth.getAuthObject().search(startDN, scope,
filter,attr,false,searchCons);
- return new LDAPPathSet(res);
+ return new LDAPPathSet(res, this);
}
catch (LDAPException ex)
{
@@ -439,7 +444,7 @@ public class LDAPLookup implements Lookup
(LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalcontext") && dn.endsWith(mDomainTypeRoot)))
{
DomainPath domainPath = new DomainPath();
- domainPath.setPath(getPathComponents(dn));
+ domainPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mDomainTypeRoot))));
thisPath = domainPath;
}
else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalentity") ||
@@ -451,7 +456,7 @@ public class LDAPLookup implements Lookup
entityPath = new ItemPath(entityKey);
else {
entityPath = new ItemPath();
- entityPath.setPath(getPathComponents(dn));
+ entityPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mItemTypeRoot))));
}
thisPath = entityPath;
}
@@ -497,7 +502,7 @@ public class LDAPLookup implements Lookup
@Override
public Object resolve(Path path) throws ObjectNotFoundException {
- return resolveObject(getDN(path));
+ return resolveObject(getFullDN(path));
}
@Override
@@ -709,7 +714,7 @@ public class LDAPLookup implements Lookup
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");
+ throw new ObjectNotFoundException("Agent not found: "+agentName, "");
Path result = res.next();
if (result instanceof AgentPath)
return (AgentPath)result;
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java
index 6ff6b2f..e1c8ac4 100644
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java
+++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java
@@ -39,7 +39,7 @@ final public class LDAPLookupUtils
LDAPEntry thisEntry = ld.read(dn,searchCons);
if (thisEntry != null) return thisEntry;
} catch (LDAPException ex) {
- throw new ObjectNotFoundException("LDAP Exception: "+ex.getMessage(), "");
+ throw new ObjectNotFoundException("LDAP Exception for dn:"+dn+": \n"+ex.getMessage(), "");
}
throw new ObjectNotFoundException(dn+" does not exist", "");
@@ -315,7 +315,7 @@ final public class LDAPLookupUtils
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
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java
index fdd565a..4db8a49 100644
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java
+++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java
@@ -6,6 +6,7 @@ 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.utils.Logger;
import com.novell.ldap.LDAPEntry;
@@ -20,7 +21,7 @@ import com.novell.ldap.LDAPEntry;
**************************************************************************/
// public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/04/27 13:47:24 $ $Author: abranson $";
-public class LDAPNextKeyManager {
+public class LDAPNextKeyManager implements NextKeyManager {
LDAPAuthManager ldap;
String lastKeyPath;
@@ -31,7 +32,8 @@ public class LDAPNextKeyManager {
this.lastKeyPath = lastKeyPath;
}
- public synchronized ItemPath generateNextEntityKey()
+ @Override
+ public synchronized ItemPath generateNextEntityKey()
throws ObjectCannotBeUpdated, ObjectNotFoundException
{
ItemPath lastKey = getLastEntityPath();
@@ -57,18 +59,21 @@ public class LDAPNextKeyManager {
return lastKey;
}
- public synchronized AgentPath generateNextAgentKey()
+ @Override
+ public synchronized AgentPath generateNextAgentKey()
throws ObjectCannotBeUpdated, ObjectNotFoundException {
ItemPath newEntity = generateNextEntityKey();
return new AgentPath(newEntity);
}
- public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException {
+ @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));
}
- public ItemPath getLastEntityPath() throws ObjectNotFoundException
+ @Override
+ public ItemPath getLastEntityPath() throws ObjectNotFoundException
{
LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getAuthObject(),lastKeyPath);
String lastKey = LDAPLookupUtils.getFirstAttributeValue(lastKeyEntry,"intsyskey");
diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java
index 5c46073..806976d 100644
--- a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java
+++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java
@@ -27,9 +27,10 @@ public class LDAPPathSet implements Iterator<Path> {
public LDAPPathSet(LDAPLookup ldap) { // empty
this.ldap = ldap;
results = null;
- }
+ }
- public LDAPPathSet(LDAPSearchResults results) {
+ public LDAPPathSet(LDAPSearchResults results, LDAPLookup ldap) {
+ this.ldap = ldap;
this.results = results;
}
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java
index 25ea512..bcc5e68 100644
--- a/src/main/java/com/c2kernel/process/Bootstrap.java
+++ b/src/main/java/com/c2kernel/process/Bootstrap.java
@@ -10,6 +10,7 @@ import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
@@ -47,6 +48,7 @@ public class Bootstrap
{
static DomainPath thisServerPath;
static HashMap<String, ResourceImportHandler> resHandlerCache = new HashMap<String, ResourceImportHandler>();
+ static HashMap<String, AgentProxy> systemAgents = new HashMap<String, AgentProxy>();
/**
* Run everything without timing-out the service wrapper
@@ -71,7 +73,7 @@ public class Bootstrap
Logger.msg("Bootstrap.run() - Initialising Server Item Workflow");
initServerItemWf();
- // register modules
+ Gateway.getModuleManager().setUser(systemAgents.get("system"));
Gateway.getModuleManager().registerModules();
Logger.msg("Bootstrap.run() - Bootstrapping complete");
@@ -279,7 +281,7 @@ public class Bootstrap
Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user.");
Lookup lookup = Gateway.getLookup();
try {
- lookup.getAgentPath(name);
+ systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name)));
Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found.");
return;
} catch (ObjectNotFoundException ex) { }
@@ -304,6 +306,7 @@ public class Bootstrap
rolePath.addAgent(agentPath);
Gateway.getStorage().put(agentPath.getSysKey(), new Property("Name", name, true), null);
Gateway.getStorage().put(agentPath.getSysKey(), new Property("Type", "Agent", false), null);
+ systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(agentPath));
Logger.msg("Bootstrap.checkAgent() - Done");
} catch (Exception ex) {
Logger.error("Unable to create "+name+" user.");
@@ -359,7 +362,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.getLookup().getAgentPath("system"));
+ 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 6a620d8..b6afb2c 100644
--- a/src/main/java/com/c2kernel/process/ClientShell.java
+++ b/src/main/java/com/c2kernel/process/ClientShell.java
@@ -3,7 +3,7 @@ package com.c2kernel.process;
import java.util.Scanner;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.process.auth.Authenticator;
+import com.c2kernel.process.auth.ProxyLogin;
import com.c2kernel.scripting.Script;
public class ClientShell extends StandardClient {
@@ -40,7 +40,7 @@ public class ClientShell extends StandardClient {
Gateway.init(readC2KArgs(args));
String authClassName = Gateway.getProperties().getProperty("cli.auth");
Class<?> authClass = Gateway.getResource().getClassForName(authClassName);
- Authenticator auth = (Authenticator)authClass.newInstance();
+ ProxyLogin auth = (ProxyLogin)authClass.newInstance();
AgentProxy user = auth.authenticate(Gateway.getProperties().getProperty("Name"));
ClientShell shell = new ClientShell(user);
shell.run();
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java
index 0c97a77..af24fe2 100644
--- a/src/main/java/com/c2kernel/process/Gateway.java
+++ b/src/main/java/com/c2kernel/process/Gateway.java
@@ -136,9 +136,6 @@ public class Gateway
Language.isTranlated=true;
Language.mTableOfTranslation = FileStringUtility.loadLanguageFile(languageFile);
}
-
- // if client, run module startup scripts. Otherwise bootstrap will do it after all imports
- if (!AbstractMain.runningAsWrapper) mModules.runScripts("startup");
}
/**
@@ -215,7 +212,7 @@ public class Gateway
} catch (Exception ex) {
Logger.error(ex);
- throw new InvalidDataException("Cannot authenticate. Name and/or password invalid.", "");
+ throw new InvalidDataException("Cannot connect server process. Please check config.", "");
}
@@ -250,6 +247,11 @@ public class Gateway
AgentPath agentPath = mLookup.getAgentPath(agentName);
AgentProxy userProxy = (AgentProxy) mProxyManager.getProxy(agentPath);
userProxy.setAuthObj(auth);
+
+ // Run module startup scripts. Server does this during bootstrap
+ mModules.setUser(userProxy);
+ mModules.runScripts("startup");
+
return userProxy;
}
diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java
index 47742aa..0d35025 100644
--- a/src/main/java/com/c2kernel/process/UserCodeProcess.java
+++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java
@@ -9,8 +9,8 @@ import com.c2kernel.common.InvalidTransitionException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.entity.proxy.ProxyObserver;
import com.c2kernel.entity.proxy.MemberSubscription;
+import com.c2kernel.entity.proxy.ProxyObserver;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.ScriptErrorException;
@@ -38,12 +38,12 @@ public class UserCodeProcess extends StandardClient implements ProxyObserver<Job
HashMap<String, ErrorInfo> errors = new HashMap<String, ErrorInfo>();
HashMap<String, C2KLocalObject> jobs;
- public UserCodeProcess(String agentName, String agentPass) {
+ public UserCodeProcess(String agentName, String agentPass, String resource) {
// login - try for a while in case server hasn't imported our user yet
for (int i=1;i<6;i++) {
try {
Logger.msg("Login attempt "+i+" of 5");
- agent = Gateway.connect(agentName, agentPass);
+ agent = Gateway.connect(agentName, agentPass, resource);
break;
} catch (Exception ex) {
Logger.error("Could not log in.");
@@ -209,7 +209,7 @@ public class UserCodeProcess extends StandardClient implements ProxyObserver<Job
}
public static UserCodeProcess getInstance() throws UnknownHostException {
- return new UserCodeProcess(InetAddress.getLocalHost().getHostName(), "uc");
+ return new UserCodeProcess(InetAddress.getLocalHost().getHostName(), "uc", Gateway.getProperties().getProperty("AuthResource", "Cristal"));
}
static public void main(String[] args)
diff --git a/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java b/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java
index a6af253..96d2196 100644
--- a/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java
+++ b/src/main/java/com/c2kernel/process/auth/ConsoleAuth.java
@@ -6,7 +6,7 @@ import java.util.Scanner;
import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.process.Gateway;
-public class ConsoleAuth implements Authenticator {
+public class ConsoleAuth implements ProxyLogin {
public ConsoleAuth() {
}
@@ -27,7 +27,7 @@ public class ConsoleAuth implements Authenticator {
System.out.print("Password:");
String pass = scan.nextLine();
try {
- user = Gateway.connect(username, pass);
+ user = Gateway.connect(username, pass, "Pandora");
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
diff --git a/src/main/java/com/c2kernel/process/auth/ProxyLogin.java b/src/main/java/com/c2kernel/process/auth/ProxyLogin.java
new file mode 100644
index 0000000..94416cf
--- /dev/null
+++ b/src/main/java/com/c2kernel/process/auth/ProxyLogin.java
@@ -0,0 +1,12 @@
+package com.c2kernel.process.auth;
+
+import java.util.Properties;
+
+import com.c2kernel.entity.proxy.AgentProxy;
+
+public interface ProxyLogin {
+
+ 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 9c52fee..dae5711 100644
--- a/src/main/java/com/c2kernel/process/module/Module.java
+++ b/src/main/java/com/c2kernel/process/module/Module.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Properties;
import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.Dependency;
import com.c2kernel.lifecycle.instance.predefined.entitycreation.DependencyMember;
@@ -33,11 +34,11 @@ public class Module {
super();
}
- public void runScript(String event, boolean isServer) throws ScriptingEngineException {
+ public void runScript(String event, AgentProxy user, boolean isServer) throws ScriptingEngineException {
for (ModuleScript script : scripts) {
if (script.shouldRun(event, isServer)) {
Logger.msg("Running "+script.event+" "+script.target+" script from "+name);
- Object result = script.getScript(ns).execute();
+ Object result = script.getScript(ns, user).execute();
if (result instanceof ErrorInfo) {
ErrorInfo error = (ErrorInfo) result;
Logger.error(error.toString());
@@ -73,9 +74,9 @@ public class Module {
imports.list.add(moduleItem);
}
- public void importAll(ItemProxy serverEntity, String moduleXML, boolean reset) throws Exception {
+ public void importAll(ItemProxy serverEntity, AgentProxy systemAgent, String moduleXML, boolean reset) throws Exception {
+ int systemAgentId = systemAgent.getSystemKey();
addModuleItem(moduleXML);
- int systemAgentId = Gateway.getLookup().getAgentPath("system").getSysKey();
for (ModuleResource thisRes : imports.getResources()) {
try {
diff --git a/src/main/java/com/c2kernel/process/module/ModuleManager.java b/src/main/java/com/c2kernel/process/module/ModuleManager.java
index 0afe3af..6a69ff8 100644
--- a/src/main/java/com/c2kernel/process/module/ModuleManager.java
+++ b/src/main/java/com/c2kernel/process/module/ModuleManager.java
@@ -9,6 +9,7 @@ import java.util.Properties;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.persistency.outcome.OutcomeValidator;
@@ -22,6 +23,7 @@ public class ModuleManager {
ArrayList<Module> modules = new ArrayList<Module>();
HashMap<String, String> modulesXML = new HashMap<String, String>();
Properties props = new Properties();
+ AgentProxy user;
boolean isServer;
OutcomeValidator moduleValidator;
@@ -110,6 +112,10 @@ public class ModuleManager {
if (!allDepsPresent) Logger.die("Unmet module dependencies. Cannot continue");
}
+ public void setUser(AgentProxy user) {
+ this.user = user;
+ }
+
public String getModuleVersions() {
StringBuffer ver = new StringBuffer();
for (Module thisMod : modules) {
@@ -127,7 +133,7 @@ public class ModuleManager {
public void runScripts(String event) {
for (Module thisMod : modules) {
try {
- thisMod.runScript(event, isServer);
+ thisMod.runScript(event, user, isServer);
} catch (ScriptingEngineException e) {
Logger.error(e);
Logger.die(e.getMessage());
@@ -152,7 +158,7 @@ public class ModuleManager {
try {
String nsReset = Gateway.getProperties().getProperty("Module."+thisMod.ns+".reset");
boolean thisReset = nsReset == null?reset:nsReset.equals("true");
- thisMod.importAll(serverEntity, modulesXML.get(thisMod.ns), thisReset);
+ thisMod.importAll(serverEntity, user, modulesXML.get(thisMod.ns), thisReset);
} catch (Exception e) {
Logger.error(e);
throw new ModuleException("Error importing items for module "+thisMod.getName());
@@ -160,7 +166,7 @@ public class ModuleManager {
Logger.msg("Module "+thisMod.getName()+" registered");
try {
- thisMod.runScript("startup", true);
+ thisMod.runScript("startup", user, true);
} catch (ScriptingEngineException e) {
Logger.error(e);
throw new ModuleException("Error in startup script for module "+thisMod.getName());
diff --git a/src/main/java/com/c2kernel/process/module/ModuleScript.java b/src/main/java/com/c2kernel/process/module/ModuleScript.java
index e948996..f16f390 100644
--- a/src/main/java/com/c2kernel/process/module/ModuleScript.java
+++ b/src/main/java/com/c2kernel/process/module/ModuleScript.java
@@ -1,7 +1,6 @@
package com.c2kernel.process.module;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.Script;
import com.c2kernel.scripting.ScriptingEngineException;
@@ -23,16 +22,8 @@ public class ModuleScript {
this.script = script;
}
- public Script getScript(String ns) throws ScriptingEngineException {
- AgentProxy user = Gateway.getCurrentUser();
- try {
- if (user == null) user = (AgentProxy)Gateway.getProxyManager().getProxy(
- Gateway.getLookup().getAgentPath("system"));
- } catch (Exception ex) {
- throw new ScriptingEngineException("System agent unavailable");
- }
+ public Script getScript(String ns, AgentProxy user) throws ScriptingEngineException {
return new Script(lang, ns+" "+target+" "+event, script, user);
-
}
public boolean shouldRun(String event, boolean isServer) {
diff --git a/src/main/java/com/c2kernel/scripting/ScriptConsole.java b/src/main/java/com/c2kernel/scripting/ScriptConsole.java
index a98ab57..a01e25f 100644
--- a/src/main/java/com/c2kernel/scripting/ScriptConsole.java
+++ b/src/main/java/com/c2kernel/scripting/ScriptConsole.java
@@ -16,7 +16,6 @@ import javax.script.ScriptEngine;
import org.tanukisoftware.wrapper.WrapperManager;
-import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.server.SocketHandler;
@@ -138,16 +137,9 @@ public class ScriptConsole implements SocketHandler {
// get system objects
try {
Logger.addLogStream(output, 0);
- AgentProxy user = Gateway.getCurrentUser();
- try {
- if (user == null) user = (AgentProxy)Gateway.getProxyManager().getProxy(
- Gateway.getLookup().getAgentPath("system"));
- } catch (Exception ex) {
- output.println("System agent unavailable");
- }
Script context;
try {
- context = new Script("javascript", user, output);
+ context = new Script("javascript", null, output);
} catch (Exception ex) {
output.println("Error initializing console script context");
ex.printStackTrace(output);
diff --git a/src/main/java/com/c2kernel/utils/ObjectProperties.java b/src/main/java/com/c2kernel/utils/ObjectProperties.java
index 1e9db8b..731b009 100644
--- a/src/main/java/com/c2kernel/utils/ObjectProperties.java
+++ b/src/main/java/com/c2kernel/utils/ObjectProperties.java
@@ -151,11 +151,17 @@ public class ObjectProperties extends Properties {
}
}
- public Object getInstance(String propName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
- Object prop = getObject(propName);
+ public Object getInstance(String propName, Object defaultVal) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ Object prop = getObject(propName, defaultVal);
+ if (prop == null || prop.equals(""))
+ throw new InstantiationException("Property '"+propName+"' was not defined. Cannot instantiate.");
if (prop instanceof String)
return Class.forName((String)prop).newInstance();
return prop;
+ }
+
+ public Object getInstance(String propName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+ return getInstance(propName, null);
}
}