public Map getDeclaredRestrictionsForPrincipal()

in src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/PrivilegesInfo.java [289:358]


    public Map<String, Object> getDeclaredRestrictionsForPrincipal(Session session, String absPath, String principalId) throws RepositoryException {
        JsonObject aclJson = useGetAcl(json -> {
            try {
                return json.getAcl(session, absPath);
            } catch (RepositoryException e) {
                logger.warn("Failed to load Acl", e);
            }
            return null;
        });

        Map<String, Object> map;
        if (aclJson == null) {
            map = Collections.emptyMap();
        } else {
            Map<String, RestrictionDefinition> srMap = new HashMap<>();
            useRestrictionProvider(restrictionProvider -> {
                Set<RestrictionDefinition> supportedRestrictions = restrictionProvider.getSupportedRestrictions(absPath);
                for (RestrictionDefinition restrictionDefinition : supportedRestrictions) {
                    srMap.put(restrictionDefinition.getName(), restrictionDefinition);
                }
                return null;
            });

            ValueFactory valueFactory = session.getValueFactory();
            map = new HashMap<>();
            aclJson.values().stream()
                    .filter(val -> val instanceof JsonObject && ((JsonObject)val).getString(JsonConvert.KEY_PRINCIPAL).equals(principalId))
                    .forEach(item -> {
                        JsonObject privilegesObj = ((JsonObject)item).getJsonObject(JsonConvert.KEY_PRIVILEGES);
                        if (privilegesObj != null) {
                            privilegesObj.values()
                                .forEach(privItem -> {
                                    if (privItem instanceof JsonObject) {
                                        JsonObject privilegeObj = (JsonObject)privItem;
                                        JsonValue jsonValue = privilegeObj.get(JsonConvert.KEY_ALLOW);
                                        if (jsonValue instanceof JsonObject) {
                                            JsonObject restriction = (JsonObject)jsonValue;
                                            restriction.entrySet().stream()
                                                .forEach(restrictionItem -> {
                                                    String restrictionName = restrictionItem.getKey();
                                                    int type = srMap.get(restrictionName).getRequiredType().tag();
                                                    JsonValue value = restrictionItem.getValue();
                                                    if (ValueType.ARRAY.equals(value.getValueType())) {
                                                        JsonArray jsonArray = ((JsonArray)value);
                                                        Value [] restrictionValues = new Value[jsonArray.size()];
                                                        for (int i=0; i < jsonArray.size(); i++) {
                                                            try {
                                                                restrictionValues[i] = valueFactory.createValue(jsonArray.getString(i), type);
                                                            } catch (ValueFormatException e) {
                                                                logger.warn("Failed to create restriction value", e);
                                                            }
                                                        }
                                                        map.put(restrictionName, restrictionValues);
                                                    } else if (value instanceof JsonString){
                                                        try {
                                                            Value restrictionValue = valueFactory.createValue(((JsonString)value).getString(), type);
                                                            map.put(restrictionName, restrictionValue);
                                                        } catch (ValueFormatException e) {
                                                            logger.warn("Failed to create restriction value", e);
                                                        }
                                                    }
                                                });
                                        }
                                    }
                                });
                        }
                    });
        }
        return map;
    }