Search in sources :

Example 1 with ImmutablePrivilegeDefinition

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

the class PrivilegeDefinitionWriter method getBuiltInDefinitions.

private static Collection<PrivilegeDefinition> getBuiltInDefinitions() {
    Map<String, PrivilegeDefinition> definitions = new LinkedHashMap<String, PrivilegeDefinition>();
    for (String privilegeName : NON_AGGREGATE_PRIVILEGES) {
        PrivilegeDefinition def = new ImmutablePrivilegeDefinition(privilegeName, false, null);
        definitions.put(privilegeName, def);
    }
    for (String privilegeName : AGGREGATE_PRIVILEGES.keySet()) {
        PrivilegeDefinition def = new ImmutablePrivilegeDefinition(privilegeName, false, asList(AGGREGATE_PRIVILEGES.get(privilegeName)));
        definitions.put(privilegeName, def);
    }
    PrivilegeDefinition all = new ImmutablePrivilegeDefinition(JCR_ALL, false, definitions.keySet());
    definitions.put(JCR_ALL, all);
    return definitions.values();
}
Also used : 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) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ImmutablePrivilegeDefinition

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

the class PrivilegeDefinitionWriterTest method testNameCollision.

@Test
public void testNameCollision() {
    try {
        PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(root);
        writer.writeDefinition(new ImmutablePrivilegeDefinition(JCR_READ, true, null));
        fail("name collision");
    } catch (RepositoryException e) {
    // success
    }
}
Also used : ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with ImmutablePrivilegeDefinition

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

the class PrivilegeDefinitionWriterTest method testMissingPrivilegeRoot.

@Test
public void testMissingPrivilegeRoot() throws Exception {
    ContentRepository repo = new Oak().with(new OpenSecurityProvider()).createContentRepository();
    Root tmpRoot = repo.login(null, null).getLatestRoot();
    try {
        PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(tmpRoot);
        writer.writeDefinition(new ImmutablePrivilegeDefinition("newName", true, null));
        fail("missing privilege root");
    } catch (RepositoryException e) {
    // success
    } finally {
        tmpRoot.getContentSession().close();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) RepositoryException(javax.jcr.RepositoryException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with ImmutablePrivilegeDefinition

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

the class PrivilegeDefinitionWriterTest method testWriteDefinition.

@Test
public void testWriteDefinition() throws Exception {
    PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(root);
    writer.writeDefinition(new ImmutablePrivilegeDefinition("tmp", true, asList(JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL)));
    Tree privRoot = root.getTree(PRIVILEGES_PATH);
    assertTrue(privRoot.hasChild("tmp"));
    Tree tmpTree = privRoot.getChild("tmp");
    assertTrue(TreeUtil.getBoolean(tmpTree, REP_IS_ABSTRACT));
    assertArrayEquals(new String[] { JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL }, Iterables.toArray(TreeUtil.getStrings(tmpTree, REP_AGGREGATES), String.class));
}
Also used : ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) Tree(org.apache.jackrabbit.oak.api.Tree) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with ImmutablePrivilegeDefinition

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

the class PrivilegeDefinitionWriterTest method testCommitFails.

@Test(expected = RepositoryException.class)
public void testCommitFails() throws Exception {
    Root r = Mockito.spy(root);
    doThrow(new CommitFailedException(CommitFailedException.OAK, 1, "msg")).when(r).commit();
    PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(r);
    writer.writeDefinition(new ImmutablePrivilegeDefinition("tmp", true, asList(JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL)));
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

ImmutablePrivilegeDefinition (org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition)6 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)4 Test (org.junit.Test)4 RepositoryException (javax.jcr.RepositoryException)3 Root (org.apache.jackrabbit.oak.api.Root)2 PrivilegeDefinition (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition)2 LinkedHashMap (java.util.LinkedHashMap)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 Oak (org.apache.jackrabbit.oak.Oak)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)1