Search in sources :

Example 21 with TreeLocation

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

the class PermissionProviderImpl 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);
    return isGranted(location, oakPath, permissions);
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation)

Example 22 with TreeLocation

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

the class CompositeProviderFullScopeTest method testIsGrantedAction.

@Test
public void testIsGrantedAction() throws Exception {
    for (String p : defActionsGranted.keySet()) {
        String[] actions = defActionsGranted.get(p);
        if (ImmutableList.copyOf(actions).contains(Session.ACTION_READ)) {
            TreeLocation tl = TreeLocation.create(readOnlyRoot, p);
            assertEquals(p, tl.getTree() != null, cppTestUser.isGranted(p, Session.ACTION_READ));
        } else {
            assertFalse(p, cppTestUser.isGranted(p, Session.ACTION_READ));
        }
        if (actions.length > 1) {
            assertFalse(p, cppTestUser.isGranted(p, getActionString(actions)));
        }
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Test(org.junit.Test)

Example 23 with TreeLocation

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

the class PermissionProviderImplTest method testIsGrantedNonExistingVersionStoreLocation.

@Test
public void testIsGrantedNonExistingVersionStoreLocation() {
    TreeLocation location = TreeLocation.create(root, VersionConstants.VERSION_STORE_PATH + "/non/existing/tree");
    PermissionProvider pp = createPermissionProvider(adminSession);
    assertTrue(pp instanceof PermissionProviderImpl);
    assertFalse(((PermissionProviderImpl) pp).isGranted(location, Permissions.ALL));
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) PermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 24 with TreeLocation

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

the class UserContextTest method testPropertyDefinesLocation.

@Test
public void testPropertyDefinesLocation() {
    Map<String, Collection<String>> m = ImmutableMap.of(NT_REP_GROUP, GROUP_PROPERTY_NAMES, NT_REP_USER, USER_PROPERTY_NAMES, NT_REP_PASSWORD, PWD_PROPERTY_NAMES, NT_REP_MEMBER_REFERENCES, ImmutableList.of(REP_MEMBERS));
    for (String ntName : m.keySet()) {
        Tree t = mockTree("anyName", ntName);
        TreeLocation location = Mockito.mock(TreeLocation.class);
        when(location.getTree()).thenReturn(t);
        when(location.exists()).thenReturn(true);
        for (String propName : m.get(ntName)) {
            PropertyState property = PropertyStates.createProperty(propName, "value");
            when(location.getProperty()).thenReturn(property);
            assertTrue(ctx.definesLocation(location));
        }
        PropertyState property = PropertyStates.createProperty("anyName", "value");
        when(location.getProperty()).thenReturn(property);
        assertFalse(ctx.definesLocation(location));
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Collection(java.util.Collection) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 25 with TreeLocation

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

the class PermissionsTest method testGetPermissionsOnAccessControlledNode.

@Test
public void testGetPermissionsOnAccessControlledNode() {
    TreeLocation tl = createNonExistingTreeLocation(PathUtils.ROOT_PATH + AccessControlConstants.REP_POLICY);
    Map<String, Long> map = new HashMap<String, Long>();
    // read -> mapped to read-access-control
    map.put(Session.ACTION_READ, Permissions.READ_ACCESS_CONTROL);
    // all regular write -> mapped to modify-access-control (compatible and in
    // accordance to the previous behavior, where specifying an explicit
    // modify_access_control action was not possible.
    map.put(Session.ACTION_ADD_NODE, Permissions.MODIFY_ACCESS_CONTROL);
    map.put(Session.ACTION_REMOVE, Permissions.MODIFY_ACCESS_CONTROL);
    map.put(Session.ACTION_SET_PROPERTY, Permissions.MODIFY_ACCESS_CONTROL);
    map.put(JackrabbitSession.ACTION_ADD_PROPERTY, Permissions.MODIFY_ACCESS_CONTROL);
    map.put(JackrabbitSession.ACTION_MODIFY_PROPERTY, Permissions.MODIFY_ACCESS_CONTROL);
    map.put(JackrabbitSession.ACTION_REMOVE_PROPERTY, Permissions.MODIFY_ACCESS_CONTROL);
    map.put(JackrabbitSession.ACTION_REMOVE_NODE, Permissions.MODIFY_ACCESS_CONTROL);
    // all other actions are mapped to the corresponding permission without
    // testing for item being ac-content
    map.put(JackrabbitSession.ACTION_READ_ACCESS_CONTROL, Permissions.READ_ACCESS_CONTROL);
    map.put(JackrabbitSession.ACTION_MODIFY_ACCESS_CONTROL, Permissions.MODIFY_ACCESS_CONTROL);
    map.put(JackrabbitSession.ACTION_LOCKING, Permissions.LOCK_MANAGEMENT);
    map.put(JackrabbitSession.ACTION_VERSIONING, Permissions.VERSION_MANAGEMENT);
    map.put(JackrabbitSession.ACTION_USER_MANAGEMENT, Permissions.USER_MANAGEMENT);
    for (Map.Entry<String, Long> entry : map.entrySet()) {
        assertEquals(entry.getKey(), entry.getValue().longValue(), Permissions.getPermissions(entry.getKey(), tl, true));
    }
}
Also used : HashMap(java.util.HashMap) TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) 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