Search in sources :

Example 1 with TaskanaRole

use of pro.taskana.TaskanaRole in project taskana by Taskana.

the class TaskanaEngineConfiguration method initTaskanaRoles.

private void initTaskanaRoles(Properties props, String rolesSeparator) {
    List<String> validPropertyNames = Arrays.stream(TaskanaRole.values()).map(TaskanaRole::getPropertyName).collect(Collectors.toList());
    for (Object obj : props.keySet()) {
        String propertyName = ((String) obj);
        if (validPropertyNames.contains(propertyName.toLowerCase().trim())) {
            String propertyValue = props.getProperty(propertyName);
            Set<String> roleMemberSet = new HashSet<>();
            StringTokenizer st = new StringTokenizer(propertyValue, rolesSeparator);
            while (st.hasMoreTokens()) {
                String token = st.nextToken().toLowerCase().trim();
                roleMemberSet.add(token);
            }
            TaskanaRole key = TaskanaRole.fromPropertyName(propertyName);
            if (key != null) {
                roleMap.put(key, roleMemberSet);
            } else {
                LOGGER.error("Internal System error when processing role property {}.", propertyName);
                throw new SystemException("Internal System error when processing role property " + propertyName);
            }
        }
    }
    ensureRoleMapIsFullyInitialized();
    roleMap.forEach((k, v) -> LOGGER.debug("Found Taskana RoleConfig {} : {} ", k, LoggerUtils.setToString(v)));
}
Also used : StringTokenizer(java.util.StringTokenizer) SystemException(pro.taskana.exceptions.SystemException) TaskanaRole(pro.taskana.TaskanaRole) HashSet(java.util.HashSet)

Example 2 with TaskanaRole

use of pro.taskana.TaskanaRole in project taskana by Taskana.

the class TaskanaEngineImpl method isUserInRole.

/**
 * check whether the current user is member of one of the roles specified.
 *
 * @param roles
 *            The roles that are checked for membership of the current user
 * @return true if the current user is a member of at least one of the specified groups
 */
boolean isUserInRole(TaskanaRole... roles) {
    if (!getConfiguration().isSecurityEnabled()) {
        return true;
    } else {
        List<String> accessIds = CurrentUserContext.getAccessIds();
        Set<String> rolesMembers = new HashSet<>();
        for (TaskanaRole role : roles) {
            rolesMembers.addAll(getConfiguration().getRoleMap().get(role));
        }
        for (String accessId : accessIds) {
            if (rolesMembers.contains(accessId)) {
                return true;
            }
        }
        return false;
    }
}
Also used : TaskanaRole(pro.taskana.TaskanaRole) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 TaskanaRole (pro.taskana.TaskanaRole)2 StringTokenizer (java.util.StringTokenizer)1 SystemException (pro.taskana.exceptions.SystemException)1