/** * Fetches the scopes of the role identified in the attribute for the provided user account. * * @param userAccountId The id of the user account to fetch the value from. * @param attributeId The name of the attribute. * @return Returns the attribute value in an {@code EvaluationResult}. * @throws de.escidoc.core.common.exceptions.system.SystemException */ private EvaluationResult fetchRoleScopes( final String userAccountId, final CharSequence attributeId) throws SystemException { // get role to fetch final Matcher roleMatcher = PATTERN_PARSE_ROLE_GRANT_ROLE.matcher(attributeId); String roleName = null; if (roleMatcher.find()) { roleName = roleMatcher.group(4); } if (roleName == null || roleName.length() == 0) { return CustomEvaluationResultBuilder.createEmptyEvaluationResult(); } Set<String> userGroups = null; try { userGroups = securityHelper.getUserGroups(userAccountId); } catch (UserAccountNotFoundException e) { // The caller doesn't expect to get an exception from here if // the user doesn't exist. } final Map<String, HashSet<String>> criterias = new HashMap<String, HashSet<String>>(); final HashSet<String> roles = new HashSet<String>(); roles.add(roleName); final HashSet<String> users = new HashSet<String>(); users.add(userAccountId); criterias.put(de.escidoc.core.common.business.Constants.FILTER_PATH_USER_ID, users); criterias.put(de.escidoc.core.common.business.Constants.FILTER_PATH_ROLE_ID, roles); if (userGroups != null && !userGroups.isEmpty()) { criterias.put( de.escidoc.core.common.business.Constants.FILTER_PATH_GROUP_ID, (HashSet<String>) userGroups); } final List<RoleGrant> roleGrants = userAccountDao.retrieveGrants(criterias, null, ListSorting.ASCENDING); final EvaluationResult result; if (roleGrants != null) { final List<StringAttribute> results = new ArrayList<StringAttribute>(); for (final RoleGrant roleGrant : roleGrants) { if (roleGrant.getRevocationDate() == null) { results.add(new StringAttribute(roleGrant.getObjectId())); } } result = new EvaluationResult(new BagAttribute(Constants.URI_XMLSCHEMA_STRING, results)); } else { result = CustomEvaluationResultBuilder.createEmptyEvaluationResult(); } return result; }