Search in sources :

Example 1 with TreeLocation

use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.

the class CugPermissionProviderTest method testSupportedPermissionsByLocation.

/**
     * @see org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider#supportedPermissions(org.apache.jackrabbit.oak.plugins.tree.TreeLocation, long)
     */
@Test
public void testSupportedPermissionsByLocation() {
    for (String path : PATH_INCUG_MAP.keySet()) {
        boolean isInCug = PATH_INCUG_MAP.get(path);
        TreeLocation location = TreeLocation.create(root, path);
        if (isInCug) {
            assertEquals(path, Permissions.READ, cugPermProvider.supportedPermissions(location, Permissions.READ));
            assertEquals(path, Permissions.READ_NODE, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE));
            assertEquals(path, Permissions.READ_PROPERTY, cugPermProvider.supportedPermissions(location, Permissions.READ_PROPERTY));
            assertEquals(path, Permissions.READ, cugPermProvider.supportedPermissions(location, Permissions.ALL));
            assertEquals(path, Permissions.READ_NODE, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL));
        } else {
            assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ));
            assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE));
            assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_PROPERTY));
            assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.ALL));
            assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL));
        }
        assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_ACCESS_CONTROL));
        assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.MODIFY_ACCESS_CONTROL));
        assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.ADD_NODE));
        assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.WRITE));
        assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(TreeLocation.create(root, "/path/to/no-existing/tree"), Permissions.READ));
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Test(org.junit.Test)

Example 2 with TreeLocation

use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.

the class CompositePermissionProvider method isGranted.

@Override
public boolean isGranted(@Nonnull String oakPath, @Nonnull String jcrActions) {
    TreeLocation location = TreeLocation.create(immutableRoot, oakPath);
    boolean isAcContent = ctx.definesLocation(location);
    long permissions = Permissions.getPermissions(jcrActions, location, isAcContent);
    PropertyState property = location.getProperty();
    Tree tree = (property == null) ? location.getTree() : location.getParent().getTree();
    if (tree != null) {
        return isGranted(tree, property, permissions);
    } else {
        boolean isGranted = false;
        long coveredPermissions = Permissions.NO_PERMISSION;
        for (AggregatedPermissionProvider aggregatedPermissionProvider : pps) {
            long supportedPermissions = aggregatedPermissionProvider.supportedPermissions(location, permissions);
            if (doEvaluate(supportedPermissions)) {
                isGranted = aggregatedPermissionProvider.isGranted(location, supportedPermissions);
                coveredPermissions |= supportedPermissions;
                if (!isGranted) {
                    break;
                }
            }
        }
        return isGranted && coveredPermissions == permissions;
    }
}
Also used : AggregatedPermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider) TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Tree(org.apache.jackrabbit.oak.api.Tree) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 3 with TreeLocation

use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.

the class AuthorizablePropertiesImpl method getNames.

//---------------------------------------------< AuthorizableProperties >---
@Nonnull
@Override
public Iterator<String> getNames(@Nonnull String relPath) throws RepositoryException {
    String oakPath = getOakPath(relPath);
    Tree tree = getTree();
    TreeLocation location = getLocation(tree, oakPath);
    Tree parent = location.getTree();
    if (parent != null && Text.isDescendantOrEqual(tree.getPath(), parent.getPath())) {
        List<String> l = new ArrayList<String>();
        for (PropertyState property : parent.getProperties()) {
            String propName = property.getName();
            if (isAuthorizableProperty(tree, location.getChild(propName), false)) {
                l.add(namePathMapper.getJcrName(propName));
            }
        }
        return l.iterator();
    } else {
        throw new RepositoryException("Relative path " + relPath + " refers to non-existing tree or tree outside of scope of authorizable.");
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) RepositoryException(javax.jcr.RepositoryException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

Example 4 with TreeLocation

use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.

the class AuthorizablePropertiesImpl method removeProperty.

/**
     * @see org.apache.jackrabbit.api.security.user.Authorizable#removeProperty(String)
     */
@Override
public boolean removeProperty(@Nonnull String relPath) throws RepositoryException {
    String oakPath = getOakPath(relPath);
    Tree node = getTree();
    TreeLocation propertyLocation = getLocation(node, oakPath);
    if (propertyLocation.getProperty() != null) {
        if (isAuthorizableProperty(node, propertyLocation, true)) {
            return propertyLocation.remove();
        } else {
            throw new ConstraintViolationException("Property " + relPath + " isn't a modifiable authorizable property");
        }
    } else {
        checkScope(node.getPath(), propertyLocation.getPath(), relPath);
    }
    // no such property or wasn't a property of this authorizable.
    return false;
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Tree(org.apache.jackrabbit.oak.api.Tree) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 5 with TreeLocation

use of org.apache.jackrabbit.oak.plugins.tree.TreeLocation in project jackrabbit-oak by apache.

the class UserContextTest method testNonExistingTreeDefinesLocation.

@Test
public void testNonExistingTreeDefinesLocation() {
    for (String ntName : NT_NAMES) {
        Tree t = mockTree("anyName", ntName);
        TreeLocation location = Mockito.mock(TreeLocation.class);
        when(location.getTree()).thenReturn(t);
        when(location.exists()).thenReturn(false);
        when(location.getPath()).thenReturn("/somePath");
        assertFalse(ctx.definesLocation(location));
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Tree(org.apache.jackrabbit.oak.api.Tree) Test(org.junit.Test)

Aggregations

TreeLocation (org.apache.jackrabbit.oak.plugins.tree.TreeLocation)27 Test (org.junit.Test)21 Tree (org.apache.jackrabbit.oak.api.Tree)7 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)2 Root (org.apache.jackrabbit.oak.api.Root)2 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Nonnull (javax.annotation.Nonnull)1 GuestCredentials (javax.jcr.GuestCredentials)1 RepositoryException (javax.jcr.RepositoryException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 ImmutableTree (org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree)1 AggregatedPermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider)1 PermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider)1