Search in sources :

Example 1 with NamePathMapperImpl

use of org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl in project jackrabbit-oak by apache.

the class AccessControlManagerImplTest method testGetSupportedPrivilegesIncludingPathConversion.

@Test
public void testGetSupportedPrivilegesIncludingPathConversion() throws Exception {
    List<Privilege> allPrivileges = Arrays.asList(getPrivilegeManager(root).getRegisteredPrivileges());
    List<String> testPaths = new ArrayList();
    testPaths.add('/' + TEST_LOCAL_PREFIX + ":testRoot");
    testPaths.add("/{" + TEST_URI + "}testRoot");
    NameMapper remapped = new LocalNameMapper(root, singletonMap(TEST_LOCAL_PREFIX, TEST_URI));
    AccessControlManager acMgr = createAccessControlManager(root, new NamePathMapperImpl(remapped));
    for (String path : testPaths) {
        Privilege[] supported = acMgr.getSupportedPrivileges(path);
        assertNotNull(supported);
        assertEquals(allPrivileges.size(), supported.length);
        assertTrue(allPrivileges.containsAll(Arrays.asList(supported)));
    }
}
Also used : AbstractAccessControlManager(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlManager) AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) ArrayList(java.util.ArrayList) NameMapper(org.apache.jackrabbit.oak.namepath.NameMapper) LocalNameMapper(org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper) GlobalNameMapper(org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper) Privilege(javax.jcr.security.Privilege) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with NamePathMapperImpl

use of org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl in project jackrabbit-oak by apache.

the class PrivilegeManagerImplTest method testRegisterPrivilegeReservedRemappedNamespace.

@Test(expected = RepositoryException.class)
public void testRegisterPrivilegeReservedRemappedNamespace() throws Exception {
    NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(root, ImmutableMap.of("prefix", NamespaceRegistry.NAMESPACE_JCR)));
    PrivilegeManager pmgr = create(root, mapper);
    pmgr.registerPrivilege("prefix:customPrivilege", true, new String[] { "prefix:read", "prefix:write" });
}
Also used : PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with NamePathMapperImpl

use of org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl in project jackrabbit-oak by apache.

the class PrivilegeManagerImplTest method testRegisterPrivilegeRemappedNamespace.

@Test
public void testRegisterPrivilegeRemappedNamespace() throws Exception {
    ReadWriteNamespaceRegistry nsRegistry = new ReadWriteNamespaceRegistry(root) {

        @Override
        protected Root getWriteRoot() {
            return root;
        }
    };
    nsRegistry.registerNamespace("ns", "http://jackrabbit.apache.org/oak/ns");
    Map<String, String> localMapping = ImmutableMap.of("prefix", NamespaceRegistry.NAMESPACE_JCR, "prefix2", "http://jackrabbit.apache.org/oak/ns");
    NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(root, localMapping));
    PrivilegeManager pmgr = create(root, mapper);
    Privilege p = pmgr.registerPrivilege("prefix2:customPrivilege", true, new String[] { "prefix:read", "prefix:write" });
    assertEquals("prefix2:customPrivilege", p.getName());
    assertEquals(2, p.getDeclaredAggregatePrivileges().length);
    Tree privilegesTree = root.getTree(PrivilegeConstants.PRIVILEGES_PATH);
    assertFalse(privilegesTree.hasChild("prefix2:customPrivilege"));
    Tree privTree = privilegesTree.getChild("ns:customPrivilege");
    assertTrue(privTree.exists());
    assertTrue(TreeUtil.getBoolean(privTree, PrivilegeConstants.REP_IS_ABSTRACT));
    Iterable<String> aggr = TreeUtil.getStrings(privTree, PrivilegeConstants.REP_AGGREGATES);
    assertNotNull(aggr);
    assertEquals(ImmutableSet.of("jcr:read", "jcr:write"), ImmutableSet.copyOf(aggr));
}
Also used : PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) Tree(org.apache.jackrabbit.oak.api.Tree) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl) Privilege(javax.jcr.security.Privilege) ReadWriteNamespaceRegistry(org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry) LocalNameMapper(org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with NamePathMapperImpl

use of org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl in project jackrabbit-oak by apache.

the class PrivilegeManagerImplTest method testGetPrivilegeInvalidRemappedNamespace.

@Test(expected = AccessControlException.class)
public void testGetPrivilegeInvalidRemappedNamespace() throws Exception {
    NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(root, ImmutableMap.of("prefix", "unknownUri")));
    create(root, mapper).getPrivilege("prefix:read");
}
Also used : NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with NamePathMapperImpl

use of org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl in project jackrabbit-oak by apache.

the class CugPolicyImplTest method testGetPathWithRemapping.

@Test
public void testGetPathWithRemapping() {
    String oakPath = "/oak:testPath";
    NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(root, ImmutableMap.of("quercus", "http://jackrabbit.apache.org/oak/ns/1.0")));
    CugPolicy empty = new CugPolicyImpl(oakPath, mapper, principalManager, ImportBehavior.ABORT);
    assertEquals("/quercus:testPath", empty.getPath());
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl)14 LocalNameMapper (org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper)11 Test (org.junit.Test)11 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)10 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)7 GlobalNameMapper (org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper)6 Privilege (javax.jcr.security.Privilege)4 NameMapper (org.apache.jackrabbit.oak.namepath.NameMapper)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)2 ValueFactoryImpl (org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl)2 AbstractAccessControlList (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlList)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ParseException (java.text.ParseException)1 NamespaceRegistry (javax.jcr.NamespaceRegistry)1 ValueFactory (javax.jcr.ValueFactory)1 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1