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