Search in sources :

Example 11 with PeopleQueryEvaluator

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

the class OperationAuthorizationUtil method authoriseUser.

/**
 * @param task             : The task against which the user being validated.
 * @param validatee        : The OrganizationalEntityDAO being validated.
 * @param allowedRoleTypes : The allowed role types for the validatee object.
 * @param pqe              : PeopleQueryEvaluator for people queries.
 * @return : true if the user is in the specified roles for the given task. false otherwise.
 */
public static boolean authoriseUser(TaskDAO task, OrganizationalEntityDAO validatee, List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoleTypes, PeopleQueryEvaluator pqe) {
    List<GenericHumanRoleDAO> humanRolesInTask = task.getHumanRoles();
    if (isExcludedEntity(task, validatee, pqe)) {
        return false;
    }
    for (GenericHumanRoleDAO role : humanRolesInTask) {
        if (allowedRoleTypes.contains(role.getType())) {
            // check for groups
            for (OrganizationalEntityDAO entityForRole : getGroupOrganizationalEntities(role)) {
                if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(entityForRole.getOrgEntityType())) {
                    String roleName = entityForRole.getName();
                    List<String> userListForRole = pqe.getUserNameListForRole(roleName);
                    if (userListForRole.contains(validatee.getName())) {
                        return true;
                    }
                }
            }
            // check for users
            // TODO validate user existance in the user store.
            List<OrganizationalEntityDAO> orgEntities = getUserOrganizationalEntities(role);
            Collections.sort(orgEntities, PeopleQueryComparators.peopleNameComparator());
            if (Collections.binarySearch(orgEntities, validatee, PeopleQueryComparators.peopleNameComparator()) >= 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) GenericHumanRoleDAO(org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)

Example 12 with PeopleQueryEvaluator

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

the class HumanTaskCoordinationProtocolManagementSkeleton 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)

Example 13 with PeopleQueryEvaluator

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

the class TaskOperationServiceImpl 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)

Example 14 with PeopleQueryEvaluator

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

the class ExpressionBasedOrgEntityProvider method getOrganizationalEntities.

public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) {
    String expression = tFrom.newCursor().getTextValue().trim();
    log.debug("Evaluating expression " + expression + " for ExpressionBasedOrgEntityProvider");
    String expLang = (tFrom.getExpressionLanguage() == null) ? HumanTaskConstants.WSHT_EXP_LANG_XPATH20 : tFrom.getExpressionLanguage();
    ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expLang);
    List list = expLangRuntime.evaluate(expression, evaluationContext);
    List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();
    if (list.isEmpty() || list.size() > 1) {
        log.debug(" Organizational Entities evaluated to null or multiple list");
        return orgEntityList;
    }
    // Returned list should evaluate to an organizationalEntity or a user
    for (Object item : list) {
        if (item instanceof NodeList) {
            for (int i = 0; i < ((NodeList) item).getLength(); i++) {
                Node node = ((NodeList) item).item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    if (node.getLocalName().equals(HumanTaskConstants.userQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.userQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals(HumanTaskConstants.groupQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.groupQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForGroupNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals("wrapper")) {
                        // Expression evaluator wraps the string with wrapper element name
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals(HumanTaskConstants.organizationalEntityQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.organizationalEntityQname.getNamespaceURI())) {
                        // This is an organizational Entity node, hence parse it as org entity
                        // Most probably this logic wont be required
                        CommonTaskUtil.addOrgEntitiesForOrganizationEntityNode(node, peopleQueryEvaluator, orgEntityList);
                    }
                } else if (node.getNodeType() == Node.TEXT_NODE) {
                    String nodeValue = node.getNodeValue().trim();
                    if (nodeValue.length() > 0) {
                        OrganizationalEntityDAO userOrgEntityForName = peopleQueryEvaluator.createUserOrgEntityForName(nodeValue);
                        if (userOrgEntityForName != null) {
                            orgEntityList.add(userOrgEntityForName);
                        }
                    }
                }
            }
        }
    }
    return orgEntityList;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Example 15 with PeopleQueryEvaluator

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

the class LiteralBasedOrgEntityProvider method addOrgEntityForUserNode.

public static void addOrgEntityForUserNode(Node userNode, PeopleQueryEvaluator pqe, List<OrganizationalEntityDAO> orgEntityList) {
    NodeList childNodes = userNode.getChildNodes();
    if (childNodes.getLength() == 1) {
        Node textNode = childNodes.item(0);
        if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) {
            String username = textNode.getNodeValue();
            if (username != null) {
                username = username.trim();
                if (username.length() > 0) {
                    OrganizationalEntityDAO userOrgEntityForUser = pqe.createUserOrgEntityForName(username);
                    orgEntityList.add(userOrgEntityForUser);
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)

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