Search in sources :

Example 6 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class CompositeRestrictionProviderTest method testWriteRestrictions.

@Test
public void testWriteRestrictions() throws Exception {
    NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
    Set<Restriction> restrictions = ImmutableSet.of(provider.createRestriction("/test", "boolean", vf.createValue(true)), provider.createRestriction("/test", "longs"), provider.createRestriction("/test", REP_GLOB, vf.createValue("*")), provider.createRestriction("/test", REP_NT_NAMES, vf.createValue("nt:base", PropertyType.NAME), vf.createValue("nt:version", PropertyType.NAME)));
    provider.writeRestrictions("/test", aceNode.getTree(), restrictions);
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 7 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class AbstractRestrictionProviderTest method testReadRestrictions.

@Test
public void testReadRestrictions() throws Exception {
    Restriction r = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
    Tree aceTree = getAceTree(r);
    Set<Restriction> restrictions = restrictionProvider.readRestrictions(testPath, aceTree);
    assertEquals(1, restrictions.size());
    assertTrue(restrictions.contains(r));
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Tree(org.apache.jackrabbit.oak.api.Tree) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 8 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class AbstractRestrictionProviderTest method testWriteRestrictions.

@Test
public void testWriteRestrictions() throws Exception {
    Restriction r = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
    Tree aceTree = getAceTree();
    restrictionProvider.writeRestrictions(testPath, aceTree, ImmutableSet.<Restriction>of(r));
    assertTrue(aceTree.hasChild(REP_RESTRICTIONS));
    Tree restr = aceTree.getChild(REP_RESTRICTIONS);
    assertEquals(r.getProperty(), restr.getProperty(REP_GLOB));
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Tree(org.apache.jackrabbit.oak.api.Tree) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 9 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class AbstractRestrictionProviderTest method testValidateRestrictions.

@Test
public void testValidateRestrictions() throws Exception {
    Restriction glob = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
    Restriction ntNames = restrictionProvider.createRestriction(testPath, REP_NT_NAMES, nameValues);
    Restriction mand = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(true));
    restrictionProvider.validateRestrictions(testPath, getAceTree(mand));
    restrictionProvider.validateRestrictions(testPath, getAceTree(mand, glob));
    restrictionProvider.validateRestrictions(testPath, getAceTree(mand, ntNames));
    restrictionProvider.validateRestrictions(testPath, getAceTree(mand, glob, ntNames));
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 10 with Restriction

use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.

the class CompositeRestrictionProviderTest method testWriteUnsupportedRestrictions.

@Test
public void testWriteUnsupportedRestrictions() throws Exception {
    NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
    Restriction invalid = new RestrictionImpl(PropertyStates.createProperty("invalid", vf.createValue(true)), false);
    try {
        provider.writeRestrictions("/test", aceNode.getTree(), ImmutableSet.<Restriction>of(invalid));
        fail("AccessControlException expected");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) AccessControlException(javax.jcr.security.AccessControlException) RestrictionImpl(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionImpl) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)39 Test (org.junit.Test)33 Value (javax.jcr.Value)12 ACE (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 AccessControlException (javax.jcr.security.AccessControlException)6 Tree (org.apache.jackrabbit.oak.api.Tree)6 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)5 Nonnull (javax.annotation.Nonnull)2 RestrictionImpl (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionImpl)2 RestrictionPattern (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AccessControlEntry (javax.jcr.security.AccessControlEntry)1 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)1 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)1 Privilege (javax.jcr.security.Privilege)1 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 ImmutableACL (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ImmutableACL)1