diff options
Diffstat (limited to 'src/main/java/com/c2kernel/process/Gateway.java')
| -rw-r--r-- | src/main/java/com/c2kernel/process/Gateway.java | 229 |
1 files changed, 79 insertions, 150 deletions
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index 0d9dbe6..2db7aa1 100644 --- a/src/main/java/com/c2kernel/process/Gateway.java +++ b/src/main/java/com/c2kernel/process/Gateway.java @@ -13,12 +13,14 @@ import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.proxy.AgentProxy;
-import com.c2kernel.entity.proxy.EntityProxyManager;
+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;
@@ -36,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.
@@ -55,12 +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 EntityProxyManager mProxyManager;
+ 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;
@@ -69,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
@@ -81,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
@@ -108,7 +111,7 @@ public class Gateway // init module manager
try {
- mModules = new ModuleManager(ClassLoader.getSystemResources("META-INF/cristal/module.xml"), AbstractMain.runningAsWrapper);
+ mModules = new ModuleManager(mResource.getModuleDefURLs(), AbstractMain.runningAsWrapper);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Could not load module definitions.", "");
@@ -133,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");
}
/**
@@ -147,17 +147,20 @@ public class Gateway */
static public void startServer() throws InvalidDataException {
try {
- // check top level LDAP contexts
- mLDAPLookup.install();
+ // check top level directory contexts
+ mLookup.initializeDirectory();
+ // init next key manager
+ mNextKeyManager = (NextKeyManager)mC2KProps.getInstance("NextKeyManager");
+
// start entity proxy server
- EntityProxyManager.initServer();
+ mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
// Init ORB - set various config
- String serverName = getProperty("ItemServer.name");
+ String serverName = mC2KProps.getProperty("ItemServer.name");
if (serverName != null)
mC2KProps.put("com.sun.CORBA.ORBServerHost", serverName);
- String serverPort = getProperty("ItemServer.iiop", "1500");
+ String serverPort = mC2KProps.getProperty("ItemServer.iiop", "1500");
mC2KProps.put("com.sun.CORBA.ORBServerPort", serverPort);
//TODO: externalize this (or replace corba completely)
mC2KProps.put("com.sun.CORBA.POA.ORBServerId", "1");
@@ -197,140 +200,59 @@ 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(auth);
+ mProxyManager = new ProxyManager();
+
+ } catch (Exception ex) {
Logger.error(ex);
- throw new ObjectNotFoundException("Could not resolve agent", "");
+ throw new InvalidDataException("Cannot connect server process. Please check config.", "");
}
- 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 agentName, String agentPassword, String resource)
+ throws InvalidDataException, ObjectNotFoundException, ClusterStorageException, InstantiationException, IllegalAccessException, ClassNotFoundException
{
+ Authenticator auth = (Authenticator)mC2KProps.getInstance("Authenticator");
+ if (!auth.authenticate(agentName, agentPassword, resource))
+ throw new InvalidDataException("Login failed", "");
+
+ mLookup = (Lookup)mC2KProps.getInstance("Lookup");
+ mLookup.open(auth);
- // Init storages
- mStorage = new TransactionManager();
- mProxyManager = new EntityProxyManager();
+ mStorage = new TransactionManager(auth);
+ mProxyManager = new ProxyManager();
+ // find agent proxy
+ 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;
}
/**
@@ -352,15 +274,17 @@ 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
+ // shut down proxy manager & server
+ if (mProxyServer != null)
+ mProxyServer.shutdownServer();
if (mProxyManager != null)
mProxyManager.shutdown();
mProxyManager = null;
- EntityProxyManager.shutdownServer();
+
// close log consoles
Logger.closeConsole();
@@ -380,9 +304,9 @@ public class Gateway return mORB;
}
- static public LDAPLookup getLDAPLookup()
+ static public Lookup getLookup()
{
- return mLDAPLookup;
+ return mLookup;
}
static public CorbaServer getCorbaServer()
@@ -405,11 +329,16 @@ public class Gateway return mResource;
}
- static public EntityProxyManager getProxyManager()
+ static public ProxyManager getProxyManager()
{
return mProxyManager;
}
+
+ public static ProxyServer getProxyServer() {
+ return mProxyServer;
+ }
+
static public String getCentreId() {
return getProperty("LocalCentre");
}
@@ -437,11 +366,7 @@ public class Gateway static public void dumpC2KProps(int logLevel) {
if (!Logger.doLog(logLevel)) return;
- Logger.msg(logLevel, "C2K Properties:");
- for (Enumeration<?> e = propertyNames(); e.hasMoreElements();) {
- String name = (String) e.nextElement();
- Logger.msg(" "+name+": "+getProperty(name));
- }
+ mC2KProps.dumpProps(logLevel);
}
static public ObjectProperties getProperties() {
@@ -456,5 +381,9 @@ public class Gateway }
}
+
+ public static NextKeyManager getNextKeyManager() {
+ return mNextKeyManager;
+ }
}
|
