in src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/ModifyAceServlet.java [797:849]
protected void addAces(@NotNull String resourcePath, @NotNull Principal principal,
@NotNull Map<Set<LocalRestriction>, List<LocalPrivilege>> restrictionsToLocalPrivilegesMap,
boolean isAllow,
@NotNull JackrabbitAccessControlList acl,
Map<Privilege, Integer> privilegeLongestDepthMap) throws RepositoryException {
List<Entry<Set<LocalRestriction>, List<LocalPrivilege>>> sortedEntries = new ArrayList<>(restrictionsToLocalPrivilegesMap.entrySet());
// sort the entries by the most shallow depth of the contained privileges
Collections.sort(sortedEntries, (e1, e2) -> {
int shallowestDepth1 = Integer.MAX_VALUE;
for (LocalPrivilege lp : e1.getValue()) {
Integer depth = privilegeLongestDepthMap.get(lp.getPrivilege());
if (depth != null && depth.intValue() < shallowestDepth1) {
shallowestDepth1 = depth.intValue();
}
}
int shallowestDepth2 = Integer.MAX_VALUE;
for (LocalPrivilege lp : e2.getValue()) {
Integer depth = privilegeLongestDepthMap.get(lp.getPrivilege());
if (depth != null && depth.intValue() < shallowestDepth2) {
shallowestDepth2 = depth.intValue();
}
}
return Integer.compare(shallowestDepth1, shallowestDepth2);
});
for (Entry<Set<LocalRestriction>, List<LocalPrivilege>> entry: sortedEntries) {
Set<Privilege> privilegesSet = new HashSet<>();
Map<String, Value> restrictions = new HashMap<>();
Map<String, Value[]> mvRestrictions = new HashMap<>();
Set<LocalRestriction> localRestrictions = entry.getKey();
for (LocalRestriction localRestriction : localRestrictions) {
if (localRestriction.isMultiValue()) {
mvRestrictions.put(localRestriction.getName(), localRestriction.getValues());
} else {
restrictions.put(localRestriction.getName(), localRestriction.getValue());
}
}
for (LocalPrivilege localPrivilege : entry.getValue()) {
privilegesSet.add(localPrivilege.getPrivilege());
}
if (!privilegesSet.isEmpty()) {
if (acl instanceof PrincipalAccessControlList) {
((PrincipalAccessControlList)acl).addEntry(resourcePath, privilegesSet.toArray(new Privilege[privilegesSet.size()]), restrictions, mvRestrictions);
} else {
acl.addEntry(principal, privilegesSet.toArray(new Privilege[privilegesSet.size()]), isAllow, restrictions, mvRestrictions);
}
}
}
}