Search in sources :

Example 56 with Privilege

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

the class PrivilegeManagerImplTest method testGetRegisteredPrivileges.

public void testGetRegisteredPrivileges() throws RepositoryException {
    Privilege[] registered = privilegeMgr.getRegisteredPrivileges();
    Set<Privilege> set = new HashSet<Privilege>();
    Privilege all = privilegeMgr.getPrivilege(Privilege.JCR_ALL);
    set.add(all);
    set.addAll(Arrays.asList(all.getAggregatePrivileges()));
    for (Privilege p : registered) {
        assertTrue(set.remove(p));
    }
    assertTrue(set.isEmpty());
}
Also used : Privilege(javax.jcr.security.Privilege) HashSet(java.util.HashSet)

Example 57 with Privilege

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

the class PrivilegeManagerImplTest method testGetBits.

public void testGetBits() throws RepositoryException {
    Privilege p1 = privilegeMgr.getPrivilege(Privilege.JCR_ADD_CHILD_NODES);
    Privilege p2 = privilegeMgr.getPrivilege(Privilege.JCR_REMOVE_CHILD_NODES);
    Privilege[] privs = new Privilege[] { p1, p2 };
    PrivilegeBits bits = getPrivilegeManagerImpl().getBits(privs);
    assertFalse(bits.isEmpty());
    PrivilegeBits other = PrivilegeBits.getInstance(getPrivilegeManagerImpl().getBits(p1));
    other.add(getPrivilegeManagerImpl().getBits(p2));
    assertEquals(bits, other);
}
Also used : Privilege(javax.jcr.security.Privilege)

Example 58 with Privilege

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

the class PrivilegeManagerImplTest method testGetBitsFromCustomAggregatePrivilege.

public void testGetBitsFromCustomAggregatePrivilege() throws RepositoryException {
    Privilege p = buildCustomPrivilege("anyName", privilegeMgr.getPrivilege(Privilege.JCR_WRITE));
    try {
        getPrivilegeManagerImpl().getBits(p);
        fail("Retrieving bits from unknown privilege should fail.");
    } catch (AccessControlException e) {
    // ok
    }
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Example 59 with Privilege

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

the class EntryTest method testUnknownPrivilege.

/**
     * @since oak 1.0 ACE doesn't validate privileges.
     */
@Test
public void testUnknownPrivilege() throws Exception {
    Privilege invalidPriv = new Privilege() {

        public String getName() {
            return "";
        }

        public boolean isAbstract() {
            return false;
        }

        public boolean isAggregate() {
            return false;
        }

        public Privilege[] getDeclaredAggregatePrivileges() {
            return new Privilege[0];
        }

        public Privilege[] getAggregatePrivileges() {
            return new Privilege[0];
        }
    };
    Privilege[] privs = new Privilege[] { invalidPriv, acMgr.privilegeFromName(PrivilegeConstants.JCR_READ) };
    ACE entry = createEntry(testPrincipal, privs, true);
    assertEquals(getBitsProvider().getBits(PrivilegeConstants.JCR_READ), entry.getPrivilegeBits());
}
Also used : ACE(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE) Privilege(javax.jcr.security.Privilege) Test(org.junit.Test)

Example 60 with Privilege

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

the class AccessControlManagerImplTest method setupPolicy.

@Nonnull
private ACL setupPolicy(@Nullable String path, @Nullable Privilege... privileges) throws RepositoryException {
    Privilege[] privs = (privileges == null || privileges.length == 0) ? testPrivileges : privileges;
    ACL policy = getApplicablePolicy(path);
    if (path == null) {
        policy.addAccessControlEntry(testPrincipal, privs);
    } else {
        policy.addEntry(testPrincipal, privs, true, getGlobRestriction("*"));
    }
    acMgr.setPolicy(path, policy);
    return policy;
}
Also used : TestACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL) Privilege(javax.jcr.security.Privilege) Nonnull(javax.annotation.Nonnull)

Aggregations

Privilege (javax.jcr.security.Privilege)316 Test (org.junit.Test)95 AccessControlManager (javax.jcr.security.AccessControlManager)82 Session (javax.jcr.Session)76 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)59 Principal (java.security.Principal)57 Node (javax.jcr.Node)53 AccessControlEntry (javax.jcr.security.AccessControlEntry)47 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)37 Value (javax.jcr.Value)30 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)28 HashMap (java.util.HashMap)26 AccessDeniedException (javax.jcr.AccessDeniedException)25 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)25 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)24 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)24 ArrayList (java.util.ArrayList)21 AccessControlException (javax.jcr.security.AccessControlException)21 AccessControlList (javax.jcr.security.AccessControlList)21 Group (org.apache.jackrabbit.api.security.user.Group)20