Search in sources :

Example 11 with NamePathMapper

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

the class ACLTest method testGetPath.

@Test
public void testGetPath() {
    NameMapper nameMapper = new GlobalNameMapper(Collections.singletonMap("jr", "http://jackrabbit.apache.org"));
    NamePathMapper npMapper = new NamePathMapperImpl(nameMapper);
    // map of jcr-path to standard jcr-path
    Map<String, String> paths = new HashMap<String, String>();
    paths.put(null, null);
    paths.put(TEST_PATH, TEST_PATH);
    paths.put("/", "/");
    paths.put("/jr:testPath", "/jr:testPath");
    paths.put("/{http://jackrabbit.apache.org}testPath", "/jr:testPath");
    for (String path : paths.keySet()) {
        AbstractAccessControlList acl = createACL(path, Collections.<ACE>emptyList(), npMapper);
        assertEquals(paths.get(path), acl.getPath());
    }
}
Also used : AbstractAccessControlList(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlList) HashMap(java.util.HashMap) GlobalNameMapper(org.apache.jackrabbit.oak.namepath.GlobalNameMapper) NameMapper(org.apache.jackrabbit.oak.namepath.NameMapper) GlobalNameMapper(org.apache.jackrabbit.oak.namepath.GlobalNameMapper) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.NamePathMapperImpl) Test(org.junit.Test)

Example 12 with NamePathMapper

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

the class ACLTest method testGetOakPath.

@Test
public void testGetOakPath() {
    NamePathMapper npMapper = new NamePathMapperImpl(new LocalNameMapper(singletonMap("oak", "http://jackrabbit.apache.org"), singletonMap("jcr", "http://jackrabbit.apache.org")));
    // map of jcr-path to oak path
    Map<String, String> paths = new HashMap();
    paths.put(null, null);
    paths.put(TEST_PATH, TEST_PATH);
    paths.put("/", "/");
    String oakPath = "/oak:testPath";
    String jcrPath = "/jcr:testPath";
    paths.put(jcrPath, oakPath);
    jcrPath = "/{http://jackrabbit.apache.org}testPath";
    paths.put(jcrPath, oakPath);
    // test if oak-path is properly set.
    for (String path : paths.keySet()) {
        AbstractAccessControlList acl = createACL(path, Collections.<ACE>emptyList(), npMapper);
        assertEquals(paths.get(path), acl.getOakPath());
    }
}
Also used : AbstractAccessControlList(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlList) HashMap(java.util.HashMap) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) Test(org.junit.Test)

Example 13 with NamePathMapper

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

the class PrincipalConfigurationImplTest method testGetPrincipalProvider4.

@Test
public void testGetPrincipalProvider4() {
    PrincipalConfigurationImpl pc3 = new PrincipalConfigurationImpl();
    final SecurityProvider sp = new SecurityProvider() {

        @Nonnull
        @Override
        public ConfigurationParameters getParameters(@Nullable String name) {
            return ConfigurationParameters.EMPTY;
        }

        @Nonnull
        @Override
        public Iterable<? extends SecurityConfiguration> getConfigurations() {
            return ImmutableList.of();
        }

        @Nonnull
        @Override
        public <T> T getConfiguration(@Nonnull Class<T> configClass) {
            if (configClass.equals(UserConfiguration.class)) {
                return (T) new UserConfigurationImpl(this) {

                    @Nullable
                    @Override
                    public PrincipalProvider getUserPrincipalProvider(@Nonnull Root root, @Nonnull NamePathMapper namePathMapper) {
                        return null;
                    }
                };
            } else {
                throw new IllegalArgumentException();
            }
        }
    };
    pc3.setSecurityProvider(sp);
    PrincipalProvider pp = pc3.getPrincipalProvider(root, NamePathMapper.DEFAULT);
    assertTrue(pp instanceof PrincipalProviderImpl);
}
Also used : PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) UserConfigurationImpl(org.apache.jackrabbit.oak.security.user.UserConfigurationImpl) Nullable(javax.annotation.Nullable) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 14 with NamePathMapper

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

the class PrivilegeManagerImplTest method testGetPrivilegeRemappedNamespace.

@Test
public void testGetPrivilegeRemappedNamespace() throws Exception {
    NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(root, ImmutableMap.of("prefix", NamespaceRegistry.NAMESPACE_JCR)));
    Privilege p = create(root, mapper).getPrivilege("prefix:read");
    assertNotNull(p);
    assertNotEquals(Privilege.JCR_READ, p.getName());
    assertNotEquals(PrivilegeConstants.JCR_READ, p.getName());
    assertEquals("prefix:read", p.getName());
}
Also used : NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.NamePathMapperImpl) Privilege(javax.jcr.security.Privilege) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 15 with NamePathMapper

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

the class QueryUtilTest method testEscapeForQuery.

@Test
public void testEscapeForQuery() throws Exception {
    NamePathMapper namePathMapper = new NamePathMapperImpl(new LocalNameMapper(ImmutableMap.of(NamespaceRegistry.PREFIX_JCR, NamespaceRegistry.NAMESPACE_JCR), ImmutableMap.of("myPrefix", NamespaceRegistry.NAMESPACE_JCR)));
    String value = "'string\\value";
    assertEquals(QueryUtils.escapeForQuery("myPrefix:" + value), QueryUtil.escapeForQuery("jcr:" + value, namePathMapper));
}
Also used : NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) Test(org.junit.Test)

Aggregations

NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)17 Test (org.junit.Test)13 NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.NamePathMapperImpl)12 LocalNameMapper (org.apache.jackrabbit.oak.namepath.LocalNameMapper)11 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)6 HashMap (java.util.HashMap)4 Privilege (javax.jcr.security.Privilege)3 Tree (org.apache.jackrabbit.oak.api.Tree)3 GlobalNameMapper (org.apache.jackrabbit.oak.namepath.GlobalNameMapper)3 Nonnull (javax.annotation.Nonnull)2 PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)2 NameMapper (org.apache.jackrabbit.oak.namepath.NameMapper)2 AbstractAccessControlList (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlList)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 RepositoryException (javax.jcr.RepositoryException)1 NodeType (javax.jcr.nodetype.NodeType)1 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)1 Root (org.apache.jackrabbit.oak.api.Root)1