CompositeRestrictionProvider implements RestrictionProvider { @Override public void validateRestrictions(@Nullable String oakPath, @NotNull Tree aceTree) throws RepositoryException { Map<String,RestrictionDefinition> supported = getSupported(oakPath); Set<String> rNames = new HashSet<>(); for (Restriction r : readRestrictions(oakPath, aceTree)) { String name = getName(r); rNames.add(name); if (!supported.containsKey(name)) { throw new AccessControlException("Unsupported restriction: " + name + " at " + oakPath); } if (!r.getDefinition().equals(supported.get(name))) { throw new AccessControlException("Invalid restriction: " + name + " at " + oakPath); } } for (RestrictionDefinition def : supported.values()) { String defName = def.getName(); if (hasRestrictionProperty(aceTree, defName) && !rNames.contains(defName)) { throw new AccessControlException("Invalid restriction " + defName + " at " + oakPath); } if (def.isMandatory() && !rNames.contains(defName)) { throw new AccessControlException("Mandatory restriction " + defName + " is missing."); } } } private  CompositeRestrictionProvider(@NotNull Collection<? extends RestrictionProvider> providers); static RestrictionProvider newInstance(@NotNull RestrictionProvider... providers); static RestrictionProvider newInstance(@NotNull Collection<? extends RestrictionProvider> providers); @NotNull @Override Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath); @NotNull @Override Restriction createRestriction(@Nullable String oakPath, @NotNull String oakName, @NotNull Value value); @NotNull @Override Restriction createRestriction(@Nullable String oakPath, @NotNull String oakName, @NotNull Value... values); @NotNull @Override Set<Restriction> readRestrictions(@Nullable String oakPath, @NotNull Tree aceTree); @Override void writeRestrictions(String oakPath, Tree aceTree, Set<Restriction> restrictions); @Override void validateRestrictions(@Nullable String oakPath, @NotNull Tree aceTree); @NotNull @Override RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree); @NotNull @Override RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions);  }
@Test(expected = AccessControlException.class) public void testValidateRestrictionsMissingMandatory() throws Exception { Tree aceTree = getAceTree(GLOB_RESTRICTION); provider.validateRestrictions("/test", aceTree); }
@Test public void testValidateRestrictions() throws Exception { Tree aceTree = getAceTree(LONGS_RESTRICTION, MANDATORY_BOOLEAN_RESTRICTION); provider.validateRestrictions("/test", aceTree); }
@Test public void testValidateRestrictionsOnAceNode() throws Exception { List<PropertyState> properties = new ArrayList<>(); Tree aceTree = getAceTree(); properties.add(aceTree.getProperty(JcrConstants.JCR_PRIMARYTYPE)); when(aceTree.getChild(REP_RESTRICTIONS).exists()).thenReturn(false); when(aceTree.hasProperty(NAME_BOOLEAN)).thenReturn(true); when(aceTree.getProperty(NAME_BOOLEAN)).thenReturn(MANDATORY_BOOLEAN_RESTRICTION.getProperty()); properties.add(MANDATORY_BOOLEAN_RESTRICTION.getProperty()); when(aceTree.getProperties()).thenReturn((Iterable)properties); provider.validateRestrictions("/test", aceTree); }