Search in sources :

Example 1 with RestrictionDefinition

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

the class PrincipalRestrictionProvider method getSupportedRestrictions.

@Nonnull
@Override
public Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath) {
    Set<RestrictionDefinition> definitions = new HashSet<RestrictionDefinition>(base.getSupportedRestrictions(oakPath));
    definitions.add(new RestrictionDefinitionImpl(REP_NODE_PATH, Type.PATH, true));
    return definitions;
}
Also used : RestrictionDefinitionImpl(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinitionImpl) RestrictionDefinition(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition) HashSet(java.util.HashSet) Nonnull(javax.annotation.Nonnull)

Example 2 with RestrictionDefinition

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

the class AbstractRestrictionProviderTest method before.

@Before
@Override
public void before() throws Exception {
    super.before();
    valueFactory = new ValueFactoryImpl(root, namePathMapper);
    globValue = valueFactory.createValue("*");
    nameValue = valueFactory.createValue("nt:file", PropertyType.NAME);
    nameValues = new Value[] { valueFactory.createValue("nt:folder", PropertyType.NAME), valueFactory.createValue("nt:file", PropertyType.NAME) };
    RestrictionDefinition glob = new RestrictionDefinitionImpl(REP_GLOB, Type.STRING, false);
    RestrictionDefinition nts = new RestrictionDefinitionImpl(REP_NT_NAMES, Type.NAMES, false);
    RestrictionDefinition mand = new RestrictionDefinitionImpl("mandatory", Type.BOOLEAN, true);
    supported = ImmutableMap.of(glob.getName(), glob, nts.getName(), nts, mand.getName(), mand);
    restrictionProvider = new TestProvider(supported);
}
Also used : ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) RestrictionDefinitionImpl(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinitionImpl) RestrictionDefinition(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition) Before(org.junit.Before)

Example 3 with RestrictionDefinition

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

the class SlingRestrictionProviderImpl method supportedRestrictions.

private static Map<String, RestrictionDefinition> supportedRestrictions() {
    RestrictionDefinition slingResourceTypes = new RestrictionDefinitionImpl(SLING_RESOURCE_TYPES, Type.STRINGS, false);
    RestrictionDefinition slingResourceTypesWithChildren = new RestrictionDefinitionImpl(SLING_RESOURCE_TYPES_WITH_DESCENDANTS, Type.STRINGS, false);
    Map<String, RestrictionDefinition> supportedRestrictions = new HashMap<String, RestrictionDefinition>();
    supportedRestrictions.put(slingResourceTypes.getName(), slingResourceTypes);
    supportedRestrictions.put(slingResourceTypesWithChildren.getName(), slingResourceTypesWithChildren);
    return Collections.unmodifiableMap(supportedRestrictions);
}
Also used : HashMap(java.util.HashMap) RestrictionDefinitionImpl(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinitionImpl) RestrictionDefinition(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition)

Example 4 with RestrictionDefinition

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

the class ACL method addEntry.

// ----------------------------------------< JackrabbitAccessControlList >---
@Override
public boolean addEntry(Principal principal, Privilege[] privileges, boolean isAllow, Map<String, Value> restrictions, Map<String, Value[]> mvRestrictions) throws RepositoryException {
    if (privileges == null || privileges.length == 0) {
        throw new AccessControlException("Privileges may not be null nor an empty array");
    }
    for (Privilege p : privileges) {
        Privilege pv = getPrivilegeManager().getPrivilege(p.getName());
        if (pv.isAbstract()) {
            throw new AccessControlException("Privilege " + p + " is abstract.");
        }
    }
    if (!checkValidPrincipal(principal)) {
        return false;
    }
    for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(getOakPath())) {
        String jcrName = getNamePathMapper().getJcrName(def.getName());
        if (def.isMandatory() && (restrictions == null || !restrictions.containsKey(jcrName))) {
            throw new AccessControlException("Mandatory restriction " + jcrName + " is missing.");
        }
    }
    Set<Restriction> rs;
    if (restrictions == null && mvRestrictions == null) {
        rs = Collections.emptySet();
    } else {
        rs = new HashSet<Restriction>();
        if (restrictions != null) {
            for (String jcrName : restrictions.keySet()) {
                String oakName = getNamePathMapper().getOakName(jcrName);
                rs.add(getRestrictionProvider().createRestriction(getOakPath(), oakName, restrictions.get(oakName)));
            }
        }
        if (mvRestrictions != null) {
            for (String jcrName : mvRestrictions.keySet()) {
                String oakName = getNamePathMapper().getOakName(jcrName);
                rs.add(getRestrictionProvider().createRestriction(getOakPath(), oakName, mvRestrictions.get(oakName)));
            }
        }
    }
    ACE entry = createACE(principal, getPrivilegeBits(privileges), isAllow, rs);
    if (entries.contains(entry)) {
        log.debug("Entry is already contained in policy -> no modification.");
        return false;
    } else {
        return internalAddEntry(entry);
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) ACE(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege) RestrictionDefinition(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition)

Example 5 with RestrictionDefinition

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

the class AbstractAccessControlListTest method testIsMultiValueRestriction.

@Test
public void testIsMultiValueRestriction() throws RepositoryException {
    AbstractAccessControlList acl = createEmptyACL();
    for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(getTestPath())) {
        boolean isMv = acl.isMultiValueRestriction(getNamePathMapper().getJcrName(def.getName()));
        assertEquals(def.getRequiredType().isArray(), isMv);
    }
}
Also used : RestrictionDefinition(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition) Test(org.junit.Test)

Aggregations

RestrictionDefinition (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition)12 Test (org.junit.Test)6 RestrictionDefinitionImpl (org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinitionImpl)5 HashMap (java.util.HashMap)2 Nonnull (javax.annotation.Nonnull)2 AbstractAccessControlList (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlList)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 AccessControlException (javax.jcr.security.AccessControlException)1 Privilege (javax.jcr.security.Privilege)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 ValueFactoryImpl (org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl)1 ACE (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE)1 AbstractRestrictionProvider (org.apache.jackrabbit.oak.spi.security.authorization.restriction.AbstractRestrictionProvider)1 Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)1 Before (org.junit.Before)1