Search in sources :

Example 1 with AgentProxy

use of org.cristalise.kernel.entity.proxy.AgentProxy in project kernel by cristal-ise.

the class Bootstrap method checkAdminAgents.

public static void checkAdminAgents() throws Exception {
    // check for administrative user & admin role
    RolePath rootRole = new RolePath();
    if (!rootRole.exists())
        Gateway.getLookupManager().createRole(rootRole);
    RolePath adminRole = new RolePath(rootRole, "Admin", false);
    if (!adminRole.exists())
        Gateway.getLookupManager().createRole(adminRole);
    // check for import Agent
    AgentProxy system = checkAgent("system", null, adminRole, new UUID(0, 1).toString());
    ScriptConsole.setUser(system);
    String ucRole = Gateway.getProperties().getString("UserCode.roleOverride", UserCodeProcess.DEFAULT_ROLE);
    // check for local usercode user & role
    RolePath usercodeRole = new RolePath(rootRole, ucRole, true);
    if (!usercodeRole.exists())
        Gateway.getLookupManager().createRole(usercodeRole);
    checkAgent(Gateway.getProperties().getString(ucRole + ".agent", InetAddress.getLocalHost().getHostName()), Gateway.getProperties().getString(ucRole + ".password", "uc"), usercodeRole, UUID.randomUUID().toString());
}
Also used : AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) UUID(java.util.UUID) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 2 with AgentProxy

use of org.cristalise.kernel.entity.proxy.AgentProxy 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 3 with AgentProxy

use of org.cristalise.kernel.entity.proxy.AgentProxy in project kernel by cristal-ise.

the class Bootstrap method checkAgent.

/**
 * Checks for the existence of a agents so it can be used
 *
 * @param name
 * @param pass
 * @param rolePath
 * @param uuid
 * @return the Proxy representing the Agent
 * @throws Exception
 */
private static AgentProxy checkAgent(String name, String pass, RolePath rolePath, String uuid) throws Exception {
    Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '" + name + "' agent.");
    LookupManager lookup = Gateway.getLookupManager();
    try {
        AgentProxy agentProxy = Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name));
        systemAgents.put(name, agentProxy);
        Logger.msg(3, "Bootstrap.checkAgent() - Agent '" + name + "' found.");
        return agentProxy;
    } catch (ObjectNotFoundException ex) {
    }
    Logger.msg("Bootstrap.checkAgent() - Agent '" + name + "' not found. Creating.");
    try {
        AgentPath agentPath = new AgentPath(new ItemPath(uuid), name);
        Gateway.getCorbaServer().createAgent(agentPath);
        lookup.add(agentPath);
        if (StringUtils.isNotBlank(pass))
            lookup.setAgentPassword(agentPath, pass);
        // assign admin role
        Logger.msg("Bootstrap.checkAgent() - Assigning role '" + rolePath.getName() + "'");
        Gateway.getLookupManager().addRole(agentPath, rolePath);
        Gateway.getStorage().put(agentPath, new Property(NAME, name, true), null);
        Gateway.getStorage().put(agentPath, new Property(TYPE, "Agent", false), null);
        AgentProxy agentProxy = Gateway.getProxyManager().getAgentProxy(agentPath);
        // TODO: properly init agent here with wf, props and colls
        // agentProxy.initialise(agentId, itemProps, workflow, colls);
        systemAgents.put(name, agentProxy);
        return agentProxy;
    } catch (Exception ex) {
        Logger.error("Unable to create '" + name + "' Agent.");
        throw ex;
    }
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Property(org.cristalise.kernel.property.Property) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 4 with AgentProxy

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

Example 5 with AgentProxy

use of org.cristalise.kernel.entity.proxy.AgentProxy in project kernel by cristal-ise.

the class ConsoleAuth method authenticate.

@Override
public AgentProxy authenticate(String resource) throws Exception {
    AgentProxy agent = null;
    if (resource != null)
        System.out.println("Please log in" + (resource.length() > 0 ? "to " + resource : ""));
    Scanner scan = new Scanner(System.in);
    int loginAttempts = 0;
    while (agent == null && loginAttempts++ < 3) {
        System.out.print("Agent:");
        String name = scan.nextLine();
        System.out.print("Password:");
        String pass = scan.nextLine();
        try {
            agent = Gateway.connect(name, pass, resource);
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
        }
    }
    scan.close();
    if (agent == null) {
        System.err.println("Bye");
        System.exit(0);
    }
    return agent;
}
Also used : Scanner(java.util.Scanner) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy)

Aggregations

AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 Authenticator (org.cristalise.kernel.process.auth.Authenticator)2 Scanner (java.util.Scanner)1 UUID (java.util.UUID)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 ProxyManager (org.cristalise.kernel.entity.proxy.ProxyManager)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 ItemPath (org.cristalise.kernel.lookup.ItemPath)1 LookupManager (org.cristalise.kernel.lookup.LookupManager)1 RolePath (org.cristalise.kernel.lookup.RolePath)1 TransactionManager (org.cristalise.kernel.persistency.TransactionManager)1 Property (org.cristalise.kernel.property.Property)1