Search in sources :

Example 11 with Privilege

use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.

the class PrivilegeManagerImplTest method testGetPrivilege.

@Test
public void testGetPrivilege() throws Exception {
    Privilege p = privilegeManager.getPrivilege(PrivilegeConstants.JCR_VERSION_MANAGEMENT);
    assertNotNull(p);
    assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName());
}
Also used : Privilege(javax.jcr.security.Privilege) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 12 with Privilege

use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.

the class PrivilegeManagerImplTest method testGetPrivilegeExpandedNameMissingMapper.

@Test(expected = AccessControlException.class)
public void testGetPrivilegeExpandedNameMissingMapper() throws Exception {
    Privilege p = privilegeManager.getPrivilege(Privilege.JCR_VERSION_MANAGEMENT);
    assertNotNull(p);
    assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName());
}
Also used : Privilege(javax.jcr.security.Privilege) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 13 with Privilege

use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.

the class PrivilegeRegistrationTest method testRegisterCustomPrivileges.

@Test
public void testRegisterCustomPrivileges() throws RepositoryException {
    Workspace workspace = session.getWorkspace();
    workspace.getNamespaceRegistry().registerNamespace("test", "http://www.apache.org/jackrabbit/test");
    Map<String, String[]> newCustomPrivs = new HashMap<String, String[]>();
    newCustomPrivs.put("new", new String[0]);
    newCustomPrivs.put("test:new", new String[0]);
    for (String name : newCustomPrivs.keySet()) {
        boolean isAbstract = true;
        String[] aggrNames = newCustomPrivs.get(name);
        Privilege registered = privilegeManager.registerPrivilege(name, isAbstract, aggrNames);
        // validate definition
        Privilege privilege = privilegeManager.getPrivilege(name);
        assertNotNull(privilege);
        assertEquals(name, privilege.getName());
        assertTrue(privilege.isAbstract());
        assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
        assertContainsDeclared(privilegeManager.getPrivilege(PrivilegeConstants.JCR_ALL), name);
    }
    Map<String, String[]> newAggregates = new HashMap<String, String[]>();
    // a new aggregate of custom privileges
    newAggregates.put("newA2", getAggregateNames("test:new", "new"));
    // a new aggregate of custom and built-in privilege
    newAggregates.put("newA1", getAggregateNames("new", PrivilegeConstants.JCR_READ));
    // aggregating built-in privileges
    newAggregates.put("aggrBuiltIn", getAggregateNames(PrivilegeConstants.JCR_MODIFY_PROPERTIES, PrivilegeConstants.JCR_READ));
    for (String name : newAggregates.keySet()) {
        boolean isAbstract = false;
        String[] aggrNames = newAggregates.get(name);
        privilegeManager.registerPrivilege(name, isAbstract, aggrNames);
        Privilege p = privilegeManager.getPrivilege(name);
        assertNotNull(p);
        assertEquals(name, p.getName());
        assertFalse(p.isAbstract());
        for (String n : aggrNames) {
            assertContainsDeclared(p, n);
        }
        assertContainsDeclared(privilegeManager.getPrivilege(PrivilegeConstants.JCR_ALL), name);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Privilege(javax.jcr.security.Privilege) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 14 with Privilege

use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.

the class AbstractPrivilegeTest method assertContainsDeclared.

static void assertContainsDeclared(Privilege privilege, String aggrName) {
    boolean found = false;
    for (Privilege p : privilege.getDeclaredAggregatePrivileges()) {
        if (aggrName.equals(p.getName())) {
            found = true;
            break;
        }
    }
    assertTrue(found);
}
Also used : Privilege(javax.jcr.security.Privilege)

Example 15 with Privilege

use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.

the class PrivilegeManagerTest method testGetPrivilegeFromName.

@Test
public void testGetPrivilegeFromName() throws AccessControlException, RepositoryException {
    Privilege p = privilegeManager.getPrivilege(Privilege.JCR_VERSION_MANAGEMENT);
    assertTrue(p != null);
    assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName());
    assertFalse(p.isAggregate());
    p = privilegeManager.getPrivilege(Privilege.JCR_WRITE);
    assertTrue(p != null);
    assertEquals(PrivilegeConstants.JCR_WRITE, p.getName());
    assertTrue(p.isAggregate());
}
Also used : Privilege(javax.jcr.security.Privilege) Test(org.junit.Test)

Aggregations

Privilege (javax.jcr.security.Privilege)336 Test (org.junit.Test)95 AccessControlManager (javax.jcr.security.AccessControlManager)94 Session (javax.jcr.Session)80 Principal (java.security.Principal)63 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)60 Node (javax.jcr.Node)54 AccessControlEntry (javax.jcr.security.AccessControlEntry)52 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)39 Value (javax.jcr.Value)31 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)31 HashMap (java.util.HashMap)28 AccessDeniedException (javax.jcr.AccessDeniedException)26 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)26 AccessControlList (javax.jcr.security.AccessControlList)25 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)25 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)24 ArrayList (java.util.ArrayList)23 HashSet (java.util.HashSet)21 AccessControlException (javax.jcr.security.AccessControlException)21