use of org.cristalise.kernel.process.auth.Authenticator in project kernel by cristal-ise.
the class Gateway method connect.
/**
* Log in with the given username and password, and initialises the {@link Lookup}, {@link TransactionManager} and {@link ProxyManager}.
* It shall be uses in client processes only.
*
* @param agentName - username
* @param agentPassword - password
* @return an AgentProxy on the requested user
*
* @throws InvalidDataException - bad params
* @throws PersistencyException - error starting storages
* @throws ObjectNotFoundException - object not found
*/
public static AgentProxy connect(String agentName, String agentPassword, String resource) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
Authenticator auth = getAuthenticator();
if (!auth.authenticate(agentName, agentPassword, resource))
throw new InvalidDataException("Login failed");
try {
if (mLookup != null)
mLookup.close();
mLookup = (Lookup) mC2KProps.getInstance("Lookup");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
Logger.error(ex);
throw new InvalidDataException("Lookup " + mC2KProps.getString("Lookup") + " could not be instantiated");
}
mLookup.open(auth);
mStorage = new TransactionManager(auth);
mProxyManager = new ProxyManager();
// find agent proxy
AgentPath agentPath = mLookup.getAgentPath(agentName);
AgentProxy agent = (AgentProxy) mProxyManager.getProxy(agentPath);
agent.setAuthObj(auth);
ScriptConsole.setUser(agent);
// Run module startup scripts. Server does this during bootstrap
mModules.setUser(agent);
mModules.runScripts("startup");
Logger.msg("Gateway.connect(agent) - DONE.");
return agent;
}
use of org.cristalise.kernel.process.auth.Authenticator in project kernel by cristal-ise.
the class Gateway method login.
/**
* Authenticates the agent using the configured {@link Authenticator}
*
* @param agentName the name of the agent
* @param agentPassword the password of the agent
* @param resource check {@link Authenticator#authenticate(String, String, String)}
* @return AgentProxy representing the logged in user/agent
*
* @throws InvalidDataException - bad params
* @throws ObjectNotFoundException - object not found
*/
public static AgentProxy login(String agentName, String agentPassword, String resource) throws InvalidDataException, ObjectNotFoundException {
Authenticator auth = getAuthenticator();
if (!auth.authenticate(agentName, agentPassword, resource))
throw new InvalidDataException("Login failed");
// find agent proxy
AgentPath agentPath = mLookup.getAgentPath(agentName);
AgentProxy agent = (AgentProxy) mProxyManager.getProxy(agentPath);
agent.setAuthObj(auth);
return agent;
}
use of org.cristalise.kernel.process.auth.Authenticator in project kernel by cristal-ise.
the class Gateway method connect.
/**
* Connects to the Lookup server in an administrative context - using the admin username and
* password available in the implementation of the Authenticator. It shall be
* used in server processes only.
*
* @throws InvalidDataException - bad params
* @throws PersistencyException - error starting storages
* @throws ObjectNotFoundException - object not found
*/
public static Authenticator connect() throws InvalidDataException, PersistencyException, ObjectNotFoundException {
try {
Authenticator auth = getAuthenticator();
if (!auth.authenticate("System"))
throw new InvalidDataException("Server authentication failed");
if (mLookup != null)
mLookup.close();
mLookup = (Lookup) mC2KProps.getInstance("Lookup");
mLookup.open(auth);
mStorage = new TransactionManager(auth);
mProxyManager = new ProxyManager();
Logger.msg("Gateway.connect() - DONE.");
return auth;
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
Logger.error(ex);
throw new InvalidDataException("Cannot connect server process. Please check config.");
}
}
Aggregations