Search in sources :

Example 1 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class TransformerUtils method transformTaskAuthorization.

/**
 * Creates the TTaskAuthorisationParams object based on the authorisations the caller has on the
 * given task
 *
 * @param task       : The TaskDAO object for the authorisations to be checked.
 * @param callerName : The caller user name.
 * @return : The TTaskAuthorisationParams object containing the authorisation parameters as
 *         boolean flags.
 */
public static TTaskAuthorisationParams transformTaskAuthorization(TaskDAO task, String callerName) {
    PeopleQueryEvaluator pqe = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator();
    OrganizationalEntityDAO caller = pqe.createUserOrgEntityForName(callerName);
    TTaskAuthorisationParams authParams = new TTaskAuthorisationParams();
    if (TaskType.TASK.equals(task.getType())) {
        authParams.setAuthorisedToActivate(OperationAuthorizationUtil.authorisedToActivate(task, caller, pqe));
        authParams.setAuthorisedToClaim(OperationAuthorizationUtil.authorisedToClaim(task, caller, pqe));
        authParams.setAuthorisedToComment(OperationAuthorizationUtil.authorisedToComment(task, caller, pqe));
        authParams.setAuthorisedToComplete(OperationAuthorizationUtil.authorisedToComplete(task, caller, pqe));
        authParams.setAuthorisedToDelegate(OperationAuthorizationUtil.authorisedToDelegate(task, caller, pqe));
        authParams.setAuthorisedToDeleteFault(OperationAuthorizationUtil.authorisedToDeleteFault(task, caller, pqe));
        authParams.setAuthorisedToDeleteComment(OperationAuthorizationUtil.authorisedToDeleteComment(task, caller, pqe));
        authParams.setAuthorisedToDeleteOutput(OperationAuthorizationUtil.authorisedToDeleteOutput(task, caller, pqe));
        authParams.setAuthorisedToExit(OperationAuthorizationUtil.authorisedToExit(task, caller, pqe));
        authParams.setAuthorisedToFail(OperationAuthorizationUtil.authorisedToFail(task, caller, pqe));
        authParams.setAuthorisedToForward(OperationAuthorizationUtil.authorisedToForward(task, caller, pqe));
        authParams.setAuthorisedToGetComments(OperationAuthorizationUtil.authorisedToGetComments(task, caller, pqe));
        authParams.setAuthorisedToGetDescription(OperationAuthorizationUtil.authorisedToGetDescription(task, caller, pqe));
        authParams.setAuthorisedToGetInput(OperationAuthorizationUtil.authorisedToGetInput(task, caller, pqe));
        authParams.setAuthorisedToNominate(OperationAuthorizationUtil.authorisedToNominate(task, caller, pqe));
        authParams.setAuthorisedToRelease(OperationAuthorizationUtil.authorisedToRelease(task, caller, pqe));
        authParams.setAuthorisedToResume(OperationAuthorizationUtil.authorisedToResume(task, caller, pqe));
        authParams.setAuthorisedToRemove(OperationAuthorizationUtil.authorisedToRemove(task, caller, pqe));
        authParams.setAuthorisedToSetFault(OperationAuthorizationUtil.authorisedToSetFault(task, caller, pqe));
        authParams.setAuthorisedToSetOutput(OperationAuthorizationUtil.authorisedToSetOutput(task, caller, pqe));
        authParams.setAuthorisedToSetPriority(OperationAuthorizationUtil.authorisedToSetPriority(task, caller, pqe));
        authParams.setAuthorisedToSkip(OperationAuthorizationUtil.authorisedToSkip(task, caller, pqe));
        authParams.setAuthorisedToStart(OperationAuthorizationUtil.authorisedToStart(task, caller, pqe));
        authParams.setAuthorisedToStop(OperationAuthorizationUtil.authorisedToStop(task, caller, pqe));
        authParams.setAuthorisedToSuspend(OperationAuthorizationUtil.authorisedToSuspend(task, caller, pqe));
        authParams.setAuthorisedToUpdateComment(OperationAuthorizationUtil.authorisedToUpdateComment(task, caller, pqe));
    } else if (TaskType.NOTIFICATION.equals(task.getType())) {
        authParams.setAuthorisedToGetDescription(OperationAuthorizationUtil.authorisedToGetDescription(task, caller, pqe));
        authParams.setAuthorisedToRemove(OperationAuthorizationUtil.authorisedToRemove(task, caller, pqe));
    }
    return authParams;
}
Also used : PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)

Example 2 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class HumanTaskServer method initPeopleQueryEvaluator.

/**
 * @throws HumanTaskServerException :
 */
private void initPeopleQueryEvaluator() throws HumanTaskServerException {
    try {
        PeopleQueryEvaluator peopleQueryEvaluator = (PeopleQueryEvaluator) Class.forName(serverConfig.getPeopleQueryEvaluatorClass()).newInstance();
        taskEngine.setPeopleQueryEvaluator(peopleQueryEvaluator);
    } catch (Exception ex) {
        String errMsg = "Error instantiating the PeopleQueryEvaluator Class :" + serverConfig.getPeopleQueryEvaluatorClass();
        throw new HumanTaskServerException(errMsg, ex);
    }
}
Also used : HumanTaskServerException(org.wso2.carbon.humantask.core.engine.HumanTaskServerException) PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator) HumanTaskServerException(org.wso2.carbon.humantask.core.engine.HumanTaskServerException)

Example 3 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class TaskOperationsImpl method getCaller.

private String getCaller() {
    // TODO - remove hard coded user name value once moved to task view page.
    String userName = "admin";
    PeopleQueryEvaluator pqe = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator();
    if (StringUtils.isNotEmpty(pqe.getLoggedInUser())) {
        userName = pqe.getLoggedInUser();
    }
    // logged in user.
    if (StringUtils.isEmpty(userName)) {
        throw new HumanTaskRuntimeException("Cannot determine the user name of the user " + "performing the task operation!");
    }
    return userName;
}
Also used : PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 4 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class TaskOperationsImpl method authoriseToLoadTask.

/**
 * Throws an exception if the current user is not allowed to perform loadTask() operation
 * @param taskId
 */
private void authoriseToLoadTask(TaskDAO task) throws Exception {
    List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoles = new ArrayList<GenericHumanRoleDAO.GenericHumanRoleType>();
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.TASK_INITIATOR);
    HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
    PeopleQueryEvaluator pqe = taskEngine.getPeopleQueryEvaluator();
    OrganizationalEntityDAO invoker = taskEngine.getScheduler().execTransaction(new Callable<OrganizationalEntityDAO>() {

        @Override
        public OrganizationalEntityDAO call() throws Exception {
            return HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(getCaller(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
        }
    });
    if (!OperationAuthorizationUtil.authoriseUser(task, invoker, allowedRoles, pqe)) {
        String errorMsg = String.format("The user[%s] cannot perform loadTask()" + " operation as either he is in EXCLUDED_OWNERS role or he is not in task roles [%s]", invoker.getName(), allowedRoles);
        log.error(errorMsg);
        throw new HumanTaskIllegalAccessException("Access Denied. You are not authorized to perform this task");
    }
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator) GenericHumanRoleDAO(org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 5 with PeopleQueryEvaluator

use of org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator in project carbon-business-process by wso2.

the class LiteralBasedOrgEntityProvider method getOrganizationalEntities.

public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) {
    TLiteral literal = tFrom.getLiteral();
    List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();
    Element domNode = (Element) literal.getDomNode();
    if (domNode != null) {
        NodeList orgEntityNodes = domNode.getElementsByTagNameNS(HumanTaskConstants.organizationalEntityQname.getNamespaceURI(), HumanTaskConstants.organizationalEntityQname.getLocalPart());
        // There should be only one organizational Entity
        if (orgEntityNodes.getLength() == 1) {
            Node orgEntityNode = orgEntityNodes.item(0);
            addOrgEntitiesForOrganizationEntityNode(orgEntityNode, peopleQueryEvaluator, orgEntityList);
        } else {
            NodeList elements = domNode.getElementsByTagNameNS(HumanTaskConstants.userQname.getNamespaceURI(), HumanTaskConstants.userQname.getLocalPart());
            if (elements.getLength() == 1) {
                // There should only be one user element
                CommonTaskUtil.addOrgEntityForUserNode(elements.item(0), peopleQueryEvaluator, orgEntityList);
            }
        }
    }
    return orgEntityList;
}
Also used : TLiteral(org.wso2.carbon.humantask.TLiteral) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Aggregations

PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)9 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)8 ArrayList (java.util.ArrayList)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)4 GenericHumanRoleDAO (org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)3 Element (org.w3c.dom.Element)2 OrganizationalEntityProvider (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)2 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)2 List (java.util.List)1 TArgument (org.wso2.carbon.humantask.TArgument)1 TLiteral (org.wso2.carbon.humantask.TLiteral)1 TaskCreationContext (org.wso2.carbon.humantask.core.dao.TaskCreationContext)1 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)1 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)1 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)1 HumanTaskServerException (org.wso2.carbon.humantask.core.engine.HumanTaskServerException)1 ExpressionLanguageRuntime (org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)1 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)1