Search in sources :

Example 11 with TreeLocation

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

the class UserContextTest method testNotDefinesLocation.

@Test
public void testNotDefinesLocation() {
    List<String> paths = ImmutableList.of(PathUtils.ROOT_PATH, NodeTypeConstants.NODE_TYPES_PATH, "/content", "");
    for (String path : paths) {
        TreeLocation location = Mockito.mock(TreeLocation.class);
        when(location.getPath()).thenReturn(path);
        assertFalse(path, ctx.definesLocation(location));
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Test(org.junit.Test)

Example 12 with TreeLocation

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

the class PermissionsTest method testActionRemove.

@Test
public void testActionRemove() {
    TreeLocation treeLocation = TreeLocation.create(existingTree);
    assertNull(treeLocation.getProperty());
    assertEquals(Permissions.REMOVE_NODE, Permissions.getPermissions(Session.ACTION_REMOVE, treeLocation, false));
    assertEquals(Permissions.MODIFY_ACCESS_CONTROL, Permissions.getPermissions(Session.ACTION_REMOVE, treeLocation, true));
    TreeLocation nonExistingTree = createNonExistingTreeLocation("/nonExisting");
    assertNull(nonExistingTree.getProperty());
    assertEquals(Permissions.REMOVE, Permissions.getPermissions(Session.ACTION_REMOVE, nonExistingTree, false));
    assertEquals(Permissions.MODIFY_ACCESS_CONTROL, Permissions.getPermissions(Session.ACTION_REMOVE, nonExistingTree, true));
    TreeLocation nonExistingProp = createNonExistingTreeLocation("/nonExisting").getChild("nonExisting");
    assertNull(nonExistingProp.getProperty());
    assertEquals(Permissions.REMOVE, Permissions.getPermissions(Session.ACTION_REMOVE, nonExistingProp, false));
    assertEquals(Permissions.MODIFY_ACCESS_CONTROL, Permissions.getPermissions(Session.ACTION_REMOVE, nonExistingProp, true));
    TreeLocation existingProp = treeLocation.getChild(JcrConstants.JCR_PRIMARYTYPE);
    assertNotNull(existingProp.getProperty());
    assertEquals(Permissions.REMOVE_PROPERTY, Permissions.getPermissions(Session.ACTION_REMOVE, existingProp, false));
    assertEquals(Permissions.MODIFY_ACCESS_CONTROL, Permissions.getPermissions(Session.ACTION_SET_PROPERTY, existingProp, true));
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Test(org.junit.Test)

Example 13 with TreeLocation

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

the class PermissionsTest method testGetPermissionsFromJackrabbitActions.

@Test
public void testGetPermissionsFromJackrabbitActions() {
    TreeLocation tl = TreeLocation.create(existingTree);
    Map<String, Long> map = new HashMap<String, Long>();
    map.put(Session.ACTION_ADD_NODE, Permissions.ADD_NODE);
    map.put(JackrabbitSession.ACTION_ADD_PROPERTY, Permissions.ADD_PROPERTY);
    map.put(JackrabbitSession.ACTION_MODIFY_PROPERTY, Permissions.MODIFY_PROPERTY);
    map.put(JackrabbitSession.ACTION_REMOVE_PROPERTY, Permissions.REMOVE_PROPERTY);
    map.put(JackrabbitSession.ACTION_REMOVE_NODE, Permissions.REMOVE_NODE);
    map.put(JackrabbitSession.ACTION_NODE_TYPE_MANAGEMENT, Permissions.NODE_TYPE_MANAGEMENT);
    map.put(JackrabbitSession.ACTION_LOCKING, Permissions.LOCK_MANAGEMENT);
    map.put(JackrabbitSession.ACTION_VERSIONING, Permissions.VERSION_MANAGEMENT);
    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_USER_MANAGEMENT, Permissions.USER_MANAGEMENT);
    for (Map.Entry<String, Long> entry : map.entrySet()) {
        assertEquals(entry.getValue().longValue(), Permissions.getPermissions(entry.getKey(), tl, false));
    }
}
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)

Example 14 with TreeLocation

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

the class PermissionsTest method testGetPermissionsFromInvalidActions.

@Test
public void testGetPermissionsFromInvalidActions() {
    TreeLocation tl = TreeLocation.create(existingTree);
    List<String> l = ImmutableList.of(Session.ACTION_READ + ",invalid", "invalid", "invalid," + Session.ACTION_REMOVE);
    for (String invalid : l) {
        try {
            Permissions.getPermissions(invalid, tl, false);
            fail();
        } catch (IllegalArgumentException e) {
        // success
        }
    }
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) Test(org.junit.Test)

Example 15 with TreeLocation

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

the class PermissionsTest method testGetPermissionsFromPermissionNameActions.

@Test
public void testGetPermissionsFromPermissionNameActions() {
    TreeLocation tl = TreeLocation.create(existingTree);
    long permissions = Permissions.NODE_TYPE_MANAGEMENT | Permissions.LOCK_MANAGEMENT | Permissions.VERSION_MANAGEMENT;
    Set<String> names = Permissions.getNames(permissions);
    String jcrActions = Text.implode(names.toArray(new String[names.size()]), ",");
    assertEquals(permissions, Permissions.getPermissions(jcrActions, tl, false));
}
Also used : TreeLocation(org.apache.jackrabbit.oak.plugins.tree.TreeLocation) 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