diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-06-05 15:02:07 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-06-05 15:02:07 +0200 |
| commit | d4fa3bd9dd48f4d5e26850a23f5ba48a9c10ad64 (patch) | |
| tree | 5ad7bfbce8ba9df9aad53ef33a8b908ca0680fc4 /src/main/java/com/c2kernel/process/Gateway.java | |
| parent | 8bb86312d4f07dcb343ca2d212f4020906dbdb52 (diff) | |
LDAP refactored behind interfaces. All functions of LDAP now hidden
behind interfaces: Authenticator, Lookup and NextKeyManager (LDAP
property storage was already a ClusterStorage). Gateway holds additional
objects, and
Fixes #26 #191. Refs #27 (needs additional work for read perms and auth
tokens)
Diffstat (limited to 'src/main/java/com/c2kernel/process/Gateway.java')
| -rw-r--r-- | src/main/java/com/c2kernel/process/Gateway.java | 192 |
1 files changed, 58 insertions, 134 deletions
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index 01cc202..836b34b 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
@@ -135,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");
}
/**
@@ -149,9 +147,12 @@ 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
mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
@@ -199,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();
+ 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 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;
}
/**
@@ -354,9 +274,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 +304,9 @@ public class Gateway return mORB;
}
- static public LDAPLookup getLDAPLookup()
+ static public Lookup getLookup()
{
- return mLDAPLookup;
+ return mLookup;
}
static public CorbaServer getCorbaServer()
@@ -461,5 +381,9 @@ public class Gateway }
}
+
+ public static NextKeyManager getNextKeyManager() {
+ return mNextKeyManager;
+ }
}
|
