Search in sources :

Example 6 with RolePath

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;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) Property(org.cristalise.kernel.property.Property) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CannotManageException(org.cristalise.kernel.common.CannotManageException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 7 with RolePath

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;
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) CorbaServer(org.cristalise.kernel.entity.CorbaServer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ActiveEntity(org.cristalise.kernel.entity.agent.ActiveEntity) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 8 with RolePath

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);
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 9 with RolePath

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;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ArrayList(java.util.ArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 10 with RolePath

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;
}
Also used : AccessRightsException(org.cristalise.kernel.common.AccessRightsException) ArrayList(java.util.ArrayList) RolePath(org.cristalise.kernel.lookup.RolePath)

Aggregations

RolePath (org.cristalise.kernel.lookup.RolePath)13 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)4 CannotManageException (org.cristalise.kernel.common.CannotManageException)3 ArrayList (java.util.ArrayList)2 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)2 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)2 ActiveEntity (org.cristalise.kernel.entity.agent.ActiveEntity)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UUID (java.util.UUID)1 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1 CorbaServer (org.cristalise.kernel.entity.CorbaServer)1 ImportRole (org.cristalise.kernel.entity.imports.ImportRole)1 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)1 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1