diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-06-02 11:31:08 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-06-02 11:31:08 +0200 |
| commit | b96dd998d6c442be19c342399839896d00d4b6f5 (patch) | |
| tree | 51a0a07647e1d439d0adefdb57e6818a15d179ec /src/main/java/com/c2kernel/process/Gateway.java | |
| parent | 42adf60503b73c5106b30ba57fdeba13b3091169 (diff) | |
Initial commit
Diffstat (limited to 'src/main/java/com/c2kernel/process/Gateway.java')
| -rw-r--r-- | src/main/java/com/c2kernel/process/Gateway.java | 181 |
1 files changed, 50 insertions, 131 deletions
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;
+ }
}
|
