@Override public void validateRestrictions(String oakPath, @NotNull Tree aceTree) throws RepositoryException { base.validateRestrictions(oakPath, aceTree); }
@Override public void validateRestrictions(String oakPath, @NotNull Tree aceTree) throws RepositoryException { base.validateRestrictions(oakPath, aceTree); }
@Override public void validateRestrictions(String oakPath, @Nonnull Tree aceTree) throws RepositoryException { base.validateRestrictions(oakPath, aceTree); }
@Override public void validateRestrictions(@Nullable String oakPath, @NotNull Tree aceTree) throws RepositoryException { getProvider().validateRestrictions(oakPath, aceTree); }
@Override public void validateRestrictions(@Nullable String oakPath, @NotNull Tree aceTree) throws RepositoryException { getProvider().validateRestrictions(oakPath, aceTree); }
@Override public void validateRestrictions(@Nullable String oakPath, @Nonnull Tree aceTree) throws RepositoryException { getProvider().validateRestrictions(oakPath, aceTree); }
@Test public void testValidateRestrictions() throws Exception { RestrictionProvider.EMPTY.validateRestrictions(null, Mockito.mock(Tree.class)); RestrictionProvider.EMPTY.validateRestrictions("/any/path", Mockito.mock(Tree.class)); }
private void checkValidRestrictions(@NotNull Tree aceTree) throws CommitFailedException { String path; Tree aclTree = checkNotNull(aceTree.getParent()); String aclPath = aclTree.getPath(); if (REP_REPO_POLICY.equals(Text.getName(aclPath))) { path = null; } else { path = Text.getRelativeParent(aclPath, 1); } try { restrictionProvider.validateRestrictions(path, aceTree); } catch (AccessControlException e) { throw new CommitFailedException(ACCESS_CONTROL, 1, "Access control violation", e); } catch (RepositoryException e) { throw new CommitFailedException(OAK, 13, "Internal error", e); } }
private void checkValidRestrictions(@Nonnull Tree aceTree) throws CommitFailedException { String path; Tree aclTree = checkNotNull(aceTree.getParent()); String aclPath = aclTree.getPath(); if (REP_REPO_POLICY.equals(Text.getName(aclPath))) { path = null; } else { path = Text.getRelativeParent(aclPath, 1); } try { restrictionProvider.validateRestrictions(path, aceTree); } catch (AccessControlException e) { throw new CommitFailedException(ACCESS_CONTROL, 1, "Access control violation", e); } catch (RepositoryException e) { throw new CommitFailedException(OAK, 13, "Internal error", e); } }
private void checkValidRestrictions(@NotNull Tree aceTree) throws CommitFailedException { String path; Tree aclTree = checkNotNull(aceTree.getParent()); String aclPath = aclTree.getPath(); if (REP_REPO_POLICY.equals(Text.getName(aclPath))) { path = null; } else { path = Text.getRelativeParent(aclPath, 1); } try { restrictionProvider.validateRestrictions(path, aceTree); } catch (AccessControlException e) { throw new CommitFailedException(ACCESS_CONTROL, 1, "Access control violation", e); } catch (RepositoryException e) { throw new CommitFailedException(OAK, 13, "Internal error", e); } }
@Test(expected = AccessControlException.class) public void testValidateRestrictionsMissingMandatory() throws Exception { Tree aceTree = getAceTree(GLOB_RESTRICTION); provider.validateRestrictions("/test", aceTree); }
@Test(expected = AccessControlException.class) public void testValidateRestrictionsUnsupported() throws Exception { Tree aceTree = getAceTree(UNKNOWN_RESTRICTION, MANDATORY_BOOLEAN_RESTRICTION); RestrictionProvider rp = new AbstractRestrictionProvider(ImmutableMap.of(REP_GLOB, GLOB_RESTRICTION.getDefinition())) { @NotNull @Override public Set<Restriction> readRestrictions(String oakPath, @NotNull Tree aceTree) { return ImmutableSet.of(UNKNOWN_RESTRICTION); } @NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree) { throw new UnsupportedOperationException(); } @NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) { throw new UnsupportedOperationException(); } }; RestrictionProvider cp = CompositeRestrictionProvider.newInstance(rp, rp2); cp.validateRestrictions("/test", aceTree); }
@Test(expected = AccessControlException.class) public void testValidateRestrictionsInvalidDefinition() throws Exception { Restriction rWithInvalidDefinition = new RestrictionImpl(PropertyStates.createProperty(REP_GLOB, ImmutableList.of("str", "str2"), Type.STRINGS), false); Tree aceTree = getAceTree(rWithInvalidDefinition, MANDATORY_BOOLEAN_RESTRICTION); RestrictionProvider rp = new AbstractRestrictionProvider(ImmutableMap.of(REP_GLOB, GLOB_RESTRICTION.getDefinition())) { @NotNull @Override public Set<Restriction> readRestrictions(String oakPath, @NotNull Tree aceTree) { return ImmutableSet.of(rWithInvalidDefinition); } @NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree) { throw new UnsupportedOperationException(); } @NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) { throw new UnsupportedOperationException(); } }; RestrictionProvider cp = CompositeRestrictionProvider.newInstance(rp, rp2); cp.validateRestrictions("/test", aceTree); }
@Test(expected = AccessControlException.class) public void testValidateRestrictionsWrongType() throws Exception { Tree aceTree = getAceTree(new RestrictionImpl(PropertyStates.createProperty(MANDATORY_BOOLEAN_RESTRICTION.getDefinition().getName(), "string"), true)); provider.validateRestrictions("/test", aceTree); }
provider.validateRestrictions("/test", aceNode.getTree()); provider.validateRestrictions("/test", aceNode.getTree()); fail("validation should detect missing mandatory restrictions"); } catch (AccessControlException e) { provider.validateRestrictions("/test", aceNode.getTree()); fail("validation should detect wrong restriction type"); } catch (AccessControlException e) { provider.validateRestrictions("/test", aceNode.getTree()); fail("validation should detect wrong restriction type (multi vs single valued)"); } catch (AccessControlException e) {
@Test public void testValidateUnsupportedRestriction() throws Exception { RestrictionProvider rp = CompositeRestrictionProvider.newInstance(rp1, rp3); NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setString("unsupported", "value"); try { rp.validateRestrictions("/test", aceNode.getTree()); fail("Validation must detect unsupported restriction"); } catch (AccessControlException e) { // success } }
@Test public void testValidateRestrictionsAtEntryNode() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); aceNode.setBoolean("boolean", true); aceNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); aceNode.setString(REP_GLOB, "*"); aceNode.setNames(REP_NT_NAMES); // empty array provider.validateRestrictions("/test", aceNode.getTree()); }
@Test public void testValidateInvalidRestrictionDef() throws Exception { RestrictionProvider rp = CompositeRestrictionProvider.newInstance(rp1, rp3); NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setValues(REP_GLOB, new Value[]{vf.createValue(10), vf.createValue(290)}); try { rp.validateRestrictions("/test", aceNode.getTree()); fail("Validation must detect invalid restriction definition"); } catch (AccessControlException e) { // success } }