Search in sources :

Example 1 with ProxyManager

use of org.cristalise.kernel.entity.proxy.ProxyManager 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;
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) AgentPath(org.cristalise.kernel.lookup.AgentPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ProxyManager(org.cristalise.kernel.entity.proxy.ProxyManager) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Example 2 with ProxyManager

use of org.cristalise.kernel.entity.proxy.ProxyManager 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.");
    }
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ProxyManager(org.cristalise.kernel.entity.proxy.ProxyManager) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Aggregations

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)2 ProxyManager (org.cristalise.kernel.entity.proxy.ProxyManager)2 TransactionManager (org.cristalise.kernel.persistency.TransactionManager)2 Authenticator (org.cristalise.kernel.process.auth.Authenticator)2 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)1 AgentPath (org.cristalise.kernel.lookup.AgentPath)1