Search in sources :

Example 1 with ReadWriteNamespaceRegistry

use of org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry in project jackrabbit-oak by apache.

the class AccessControlManagerImplTest method registerNamespace.

private void registerNamespace(String prefix, String uri) throws Exception {
    NamespaceRegistry nsRegistry = new ReadWriteNamespaceRegistry(root) {

        @Override
        protected Root getWriteRoot() {
            return root;
        }
    };
    nsRegistry.registerNamespace(prefix, uri);
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) ReadWriteNamespaceRegistry(org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry) ReadWriteNamespaceRegistry(org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry)

Example 2 with ReadWriteNamespaceRegistry

use of org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry 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)

Aggregations

ReadWriteNamespaceRegistry (org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry)2 NamespaceRegistry (javax.jcr.NamespaceRegistry)1 Privilege (javax.jcr.security.Privilege)1 PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)1 LocalNameMapper (org.apache.jackrabbit.oak.namepath.impl.LocalNameMapper)1 NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.impl.NamePathMapperImpl)1 Test (org.junit.Test)1