Search in sources :

Example 26 with Restriction

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsMissingMandatory.

@Test
public void testValidateRestrictionsMissingMandatory() throws Exception {
    Restriction glob = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
    try {
        restrictionProvider.validateRestrictions(testPath, getAceTree(glob));
        fail("missing mandatory restriction");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) AccessControlException(javax.jcr.security.AccessControlException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 27 with Restriction

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsUnsupportedPath.

@Test
public void testValidateRestrictionsUnsupportedPath() throws Exception {
    // empty restrictions => must succeed
    restrictionProvider.validateRestrictions(null, getAceTree());
    // non-empty restrictions => must fail
    try {
        Restriction restr = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
        restrictionProvider.validateRestrictions(null, getAceTree(restr));
        fail();
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) AccessControlException(javax.jcr.security.AccessControlException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 28 with Restriction

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsWrongType.

@Test
public void testValidateRestrictionsWrongType() throws Exception {
    Restriction mand = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(true));
    try {
        Tree ace = getAceTree(mand);
        new NodeUtil(ace).getChild(REP_RESTRICTIONS).setBoolean(REP_GLOB, true);
        restrictionProvider.validateRestrictions(testPath, ace);
        fail("wrong type with restriction 'rep:glob");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlException(javax.jcr.security.AccessControlException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 29 with Restriction

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsUnsupportedRestriction.

@Test
public void testValidateRestrictionsUnsupportedRestriction() throws Exception {
    Restriction mand = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(true));
    try {
        Tree ace = getAceTree(mand);
        new NodeUtil(ace).getChild(REP_RESTRICTIONS).setString("Unsupported", "value");
        restrictionProvider.validateRestrictions(testPath, ace);
        fail("wrong type with restriction 'rep:glob");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlException(javax.jcr.security.AccessControlException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 30 with Restriction

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

the class SlingRestrictionProviderImpl method getPattern.

@Nonnull
@Override
public RestrictionPattern getPattern(@Nullable String oakPath, @Nonnull Set<Restriction> restrictions) {
    if (oakPath != null && !restrictions.isEmpty()) {
        for (Restriction r : restrictions) {
            String name = r.getDefinition().getName();
            if (SLING_RESOURCE_TYPES.equals(name)) {
                ResourceTypePattern resourceTypePattern = new ResourceTypePattern(r.getProperty().getValue(Type.STRINGS), oakPath, false);
                LOG.trace("Returning resourceTypePattern={} for rep:slingResourceTypes in getPattern(String,Set<Restriction>)", resourceTypePattern);
                return resourceTypePattern;
            } else if (SLING_RESOURCE_TYPES_WITH_DESCENDANTS.equals(name)) {
                ResourceTypePattern resourceTypePattern = new ResourceTypePattern(r.getProperty().getValue(Type.STRINGS), oakPath, true);
                LOG.trace("Returning resourceTypePattern={} for rep:slingResourceTypesWithChildren in getPattern(String,Set<Restriction>)", resourceTypePattern);
                return resourceTypePattern;
            }
        }
    }
    return RestrictionPattern.EMPTY;
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Nonnull(javax.annotation.Nonnull)

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