Search in sources :

Example 6 with PrivilegeDefinition

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.

the class PrivilegeManagerImpl method registerPrivilege.

@Override
public Privilege registerPrivilege(String privilegeName, boolean isAbstract, String[] declaredAggregateNames) throws RepositoryException {
    if (root.hasPendingChanges()) {
        throw new InvalidItemStateException("Attempt to register a new privilege while there are pending changes.");
    }
    if (privilegeName == null || privilegeName.isEmpty()) {
        throw new RepositoryException("Invalid privilege name " + privilegeName);
    }
    PrivilegeDefinition definition = new ImmutablePrivilegeDefinition(getOakName(privilegeName), isAbstract, getOakNames(declaredAggregateNames));
    PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(getWriteRoot());
    writer.writeDefinition(definition);
    // refresh the current root to make sure the definition is visible
    root.refresh();
    return getPrivilege(definition);
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) PrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition) ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException)

Example 7 with PrivilegeDefinition

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.

the class PrivilegeDefinitionReader method readDefinitions.

/**
     * Read all registered privilege definitions from the content.
     *
     * @return All privilege definitions stored in the content.
     */
@Nonnull
Map<String, PrivilegeDefinition> readDefinitions() {
    Map<String, PrivilegeDefinition> definitions = new HashMap();
    for (Tree child : privilegesTree.getChildren()) {
        if (isPrivilegeDefinition(child)) {
            PrivilegeDefinition def = PrivilegeUtil.readDefinition(child);
            definitions.put(def.getName(), def);
        }
    }
    return definitions;
}
Also used : HashMap(java.util.HashMap) PrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition) Tree(org.apache.jackrabbit.oak.api.Tree) Nonnull(javax.annotation.Nonnull)

Example 8 with PrivilegeDefinition

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.

the class PrivilegeImplTest method testNotEquals.

@Test
public void testNotEquals() throws Exception {
    assertNotEquals(privilege, aggrPrivilege);
    assertNotEquals(allPrivilege, privilege);
    final PrivilegeDefinition def = new PrivilegeDefinitionReader(root).readDefinition(privilege.getName());
    assertNotNull(def);
    assertNotEquals(privilege, new Privilege() {

        @Override
        public String getName() {
            return def.getName();
        }

        @Override
        public boolean isAbstract() {
            return def.isAbstract();
        }

        @Override
        public boolean isAggregate() {
            return !def.getDeclaredAggregateNames().isEmpty();
        }

        @Override
        public Privilege[] getDeclaredAggregatePrivileges() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Privilege[] getAggregatePrivileges() {
            throw new UnsupportedOperationException();
        }
    });
}
Also used : PrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition) Privilege(javax.jcr.security.Privilege) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 9 with PrivilegeDefinition

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.

the class L5_PrivilegeContentTest method testPrivilegeDefinition.

@Test
public void testPrivilegeDefinition() throws RepositoryException {
    Tree repWriteTree = PrivilegeUtil.getPrivilegesTree(root).getChild(PrivilegeConstants.REP_WRITE);
    PrivilegeDefinition def = PrivilegeUtil.readDefinition(repWriteTree);
    // EXERCISE
    String expectedName = null;
    assertEquals(expectedName, def.getName());
    // EXERCISE
    boolean isAbstract = false;
    assertEquals(isAbstract, def.isAbstract());
    // EXERCISE
    Set<String> expectedAggregates = null;
    assertEquals(expectedAggregates, def.getDeclaredAggregateNames());
    // EXERCISE: compare the internal privilege definition (and it's tree representation) with the privilege itself.
    Privilege repWritePrivilege = getPrivilegeManager(root).getPrivilege(PrivilegeConstants.REP_WRITE);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition) Privilege(javax.jcr.security.Privilege) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) L4_PrivilegesAndPermissionsTest(org.apache.jackrabbit.oak.exercise.security.authorization.permission.L4_PrivilegesAndPermissionsTest) Test(org.junit.Test) L7_PermissionContentTest(org.apache.jackrabbit.oak.exercise.security.authorization.permission.L7_PermissionContentTest)

Aggregations

PrivilegeDefinition (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition)9 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)3 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)3 Tree (org.apache.jackrabbit.oak.api.Tree)3 ImmutablePrivilegeDefinition (org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition)3 Test (org.junit.Test)3 RepositoryException (javax.jcr.RepositoryException)2 Privilege (javax.jcr.security.Privilege)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Nonnull (javax.annotation.Nonnull)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 L4_PrivilegesAndPermissionsTest (org.apache.jackrabbit.oak.exercise.security.authorization.permission.L4_PrivilegesAndPermissionsTest)1 L7_PermissionContentTest (org.apache.jackrabbit.oak.exercise.security.authorization.permission.L7_PermissionContentTest)1 PrivilegeBits (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits)1