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());
}
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;
}
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;
}
}
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;
}
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;
}
Aggregations