Search in sources :

Example 1 with NamePathMapper

use of org.apache.jackrabbit.oak.namepath.NamePathMapper 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.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with NamePathMapper

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

the class QueryEngineImpl method parseQuery.

/**
     * Parse the query.
     * 
     * @param statement the statement
     * @param language the language
     * @param context the context
     * @param mappings the mappings
     * @return the list of queries, where the first is the original, and all
     *         others are alternatives (for example, a "union" query)
     */
private static List<Query> parseQuery(String statement, String language, ExecutionContext context, Map<String, String> mappings) throws ParseException {
    boolean isInternal = SQL2Parser.isInternal(statement);
    if (isInternal) {
        LOG.trace("Parsing {} statement: {}", language, statement);
    } else {
        LOG.debug("Parsing {} statement: {}", language, statement);
    }
    NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(context.getRoot(), mappings));
    NodeTypeInfoProvider nodeTypes = context.getNodeTypeInfoProvider();
    QueryEngineSettings settings = context.getSettings();
    SQL2Parser parser = new SQL2Parser(mapper, nodeTypes, settings);
    if (language.endsWith(NO_LITERALS)) {
        language = language.substring(0, language.length() - NO_LITERALS.length());
        parser.setAllowNumberLiterals(false);
        parser.setAllowTextLiterals(false);
    }
    ArrayList<Query> queries = new ArrayList<Query>();
    Query q;
    if (SQL2.equals(language) || JQOM.equals(language)) {
        q = parser.parse(statement, false);
    } else if (SQL.equals(language)) {
        parser.setSupportSQL1(true);
        q = parser.parse(statement, false);
    } else if (XPATH.equals(language)) {
        XPathToSQL2Converter converter = new XPathToSQL2Converter();
        String sql2 = converter.convert(statement);
        LOG.debug("XPath > SQL2: {}", sql2);
        try {
            // OAK-874: No artificial XPath selector name in wildcards
            parser.setIncludeSelectorNameInWildcardColumns(false);
            q = parser.parse(sql2, false);
        } catch (ParseException e) {
            ParseException e2 = new ParseException(statement + " converted to SQL-2 " + e.getMessage(), 0);
            e2.initCause(e);
            throw e2;
        }
    } else {
        throw new ParseException("Unsupported language: " + language, 0);
    }
    queries.add(q);
    if (settings.isSql2Optimisation()) {
        if (q.isInternal()) {
            LOG.trace("Skipping optimisation as internal query.");
        } else {
            LOG.trace("Attempting optimisation");
            Query q2 = q.buildAlternativeQuery();
            if (q2 != q) {
                LOG.debug("Alternative query available: {}", q2);
                queries.add(q2);
            }
        }
    }
    // initialising all the queries.
    for (Query query : queries) {
        try {
            query.init();
        } catch (Exception e) {
            ParseException e2 = new ParseException(query.getStatement() + ": " + e.getMessage(), 0);
            e2.initCause(e);
            throw e2;
        }
    }
    return queries;
}
Also used : NamePathMapper(org.apache.jackrabbit.oak.namepath.NamePathMapper) ArrayList(java.util.ArrayList) NamePathMapperImpl(org.apache.jackrabbit.oak.namepath.NamePathMapperImpl) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) ParseException(java.text.ParseException) XPathToSQL2Converter(org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter) ParseException(java.text.ParseException)

Example 3 with NamePathMapper

use of org.apache.jackrabbit.oak.namepath.NamePathMapper 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.NamePathMapperImpl) Privilege(javax.jcr.security.Privilege) ReadWriteNamespaceRegistry(org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with NamePathMapper

use of org.apache.jackrabbit.oak.namepath.NamePathMapper 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.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with NamePathMapper

use of org.apache.jackrabbit.oak.namepath.NamePathMapper 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.NamePathMapperImpl) LocalNameMapper(org.apache.jackrabbit.oak.namepath.LocalNameMapper) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) 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