use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class ImportAgent method create.
@Override
public Path create(AgentPath agentPath, boolean reset) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException {
if (roles.isEmpty())
throw new ObjectNotFoundException("Agent '" + name + "' must declare at least one Role ");
AgentPath newAgent = new AgentPath(getItemPath(), name);
ActiveEntity newAgentEnt = Gateway.getCorbaServer().createAgent(newAgent);
Gateway.getLookupManager().add(newAgent);
// assemble properties
properties.add(new Property(NAME, name, true));
properties.add(new Property(TYPE, "Agent", false));
try {
if (StringUtils.isNotBlank(password))
Gateway.getLookupManager().setAgentPassword(newAgent, password);
newAgentEnt.initialise(agentPath.getSystemKey(), Gateway.getMarshaller().marshall(new PropertyArrayList(properties)), null, null);
} catch (Exception ex) {
Logger.error(ex);
throw new CannotManageException("Error initialising new agent name:" + name);
}
for (ImportRole role : roles) {
RolePath thisRole = (RolePath) role.create(agentPath, reset);
Gateway.getLookupManager().addRole(newAgent, thisRole);
}
return newAgent;
}
use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class CreateAgentFromDescription method createAgentAddRoles.
/**
* @param newAgentPath
* @param roles
* @return
* @throws CannotManageException
* @throws ObjectCannotBeUpdated
* @throws ObjectAlreadyExistsException
*/
protected ActiveEntity createAgentAddRoles(AgentPath newAgentPath, String[] roles, String pwd) throws CannotManageException, ObjectCannotBeUpdated, ObjectAlreadyExistsException {
// create the Agent object
Logger.msg(3, "CreateAgentFromDescription.createAgentAddRoles() - Creating Agent");
CorbaServer factory = Gateway.getCorbaServer();
if (factory == null)
throw new CannotManageException("This process cannot create new Items");
ActiveEntity newAgent = factory.createAgent(newAgentPath);
Gateway.getLookupManager().add(newAgentPath);
try {
if (StringUtils.isNotBlank(pwd))
Gateway.getLookupManager().setAgentPassword(newAgentPath, pwd);
for (String roleName : roles) {
RolePath role = Gateway.getLookupManager().getRolePath(roleName);
Gateway.getLookupManager().addRole(newAgentPath, role);
}
} catch (ObjectNotFoundException | NoSuchAlgorithmException e) {
Logger.error(e);
Gateway.getLookupManager().delete(newAgentPath);
}
return newAgent;
}
use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class RemoveAgent method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath itemPath, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, PersistencyException {
Logger.msg(1, "RemoveAgent::request() - Starting.");
AgentPath targetAgent;
try {
targetAgent = new AgentPath(itemPath);
} catch (InvalidAgentPathException ex) {
throw new InvalidDataException("Could not resolve " + itemPath + " as an Agent.");
}
String agentName = targetAgent.getAgentName();
// remove from roles
for (RolePath role : targetAgent.getRoles()) {
try {
Gateway.getLookupManager().removeRole(targetAgent, role);
} catch (ObjectCannotBeUpdated | ObjectNotFoundException | CannotManageException e) {
Logger.error(e);
throw new InvalidDataException("Error removing " + agentName + " from Role " + role.getName() + " exceptoin message:" + e.getMessage());
}
}
return super.runActivityLogic(agent, itemPath, transitionID, requestData, locker);
}
use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class SetAgentRoles method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException {
String[] params = getDataList(requestData);
Logger.msg(3, "SetAgentRoles: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
AgentPath targetAgent;
try {
targetAgent = new AgentPath(item);
} catch (InvalidItemPathException ex) {
throw new InvalidDataException("Could not resolve syskey " + item + " as an Agent.");
}
RolePath[] currentRoles = targetAgent.getRoles();
ArrayList<RolePath> requestedRoles = new ArrayList<RolePath>();
for (int i = 0; i < params.length; i++) {
try {
requestedRoles.add(Gateway.getLookup().getRolePath(params[i]));
} catch (ObjectNotFoundException e) {
throw new InvalidDataException("Role " + params[i] + " not found");
}
}
ArrayList<RolePath> rolesToRemove = new ArrayList<RolePath>();
for (RolePath existingRole : currentRoles) {
//
if (// if we have it, and it's requested, then it will be kept
requestedRoles.contains(existingRole))
// so remove it from request - this will be left with roles to be added
requestedRoles.remove(existingRole);
else
// else this role will be removed
rolesToRemove.add(existingRole);
}
// remove roles not in new list
for (RolePath roleToRemove : rolesToRemove) try {
Gateway.getLookupManager().removeRole(targetAgent, roleToRemove);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error removing role " + roleToRemove.getName());
}
// add requested roles we don't already have
for (RolePath roleToAdd : requestedRoles) {
try {
Gateway.getLookupManager().addRole(targetAgent, roleToAdd);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error adding role " + roleToAdd.getName());
}
}
return requestData;
}
use of org.cristalise.kernel.lookup.RolePath in project kernel by cristal-ise.
the class Transition method getPerformingRole.
public String getPerformingRole(Activity act, AgentPath agent) throws ObjectNotFoundException, AccessRightsException {
// check available
if (!isEnabled(act))
throw new AccessRightsException("Trans:" + toString() + " is disabled by the '" + enabledProp + "' property.");
// check active
if (isRequiresActive() && !act.getActive())
throw new AccessRightsException("Activity must be active to perform trans:" + toString());
String overridingRole = getRoleOverride(act.getProperties());
boolean override = overridingRole != null;
boolean isOwner = false, isOwned = true;
// Check agent name
String agentName = act.getCurrentAgentName();
if (StringUtils.isNotBlank(agentName)) {
if (agent.getAgentName().equals(agentName))
isOwner = true;
} else
isOwned = false;
List<RolePath> roles = new ArrayList<RolePath>();
// determine transition role
if (override) {
roles.add(Gateway.getLookup().getRolePath(overridingRole));
} else {
String actRole = act.getCurrentAgentRole();
if (StringUtils.isNotBlank(actRole)) {
for (String role : actRole.split(",")) {
roles.add(Gateway.getLookup().getRolePath(role.trim()));
}
}
}
// Decide the access
if (isOwned && !override && !isOwner)
throw new AccessRightsException("Agent '" + agent.getAgentName() + "' cannot perform this trans:" + toString() + " because the activity '" + act.getName() + "' is currently owned by " + agentName);
if (roles.size() != 0) {
RolePath matchingRole = agent.getFirstMatchingRole(roles);
if (matchingRole != null)
return matchingRole.getName();
else if (agent.hasRole("Admin"))
return "Admin";
else
throw new AccessRightsException("Agent '" + agent.getAgentName() + "' does not hold a suitable role '" + act.getCurrentAgentRole() + "' for the activity " + act.getName());
} else
return null;
}
Aggregations