Search in sources :

Example 31 with NodeImpl

use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.

the class CachingHierarchyManagerConsistencyTest method replaceNodes.

private void replaceNodes(Session session, int i) throws RepositoryException {
    String nodeName = "node-" + (i % 100);
    Node root = JcrUtils.getOrCreateByPath(testRoot + TEST_PATH, ntUnstructured, session);
    String uuid = UUID.randomUUID().toString();
    if (root.hasNode(nodeName)) {
        Node n = root.getNode(nodeName);
        uuid = n.getIdentifier();
        n.remove();
    }
    Node n = ((NodeImpl) root).addNodeWithUuid(nodeName, ntUnstructured, uuid);
    n.addMixin("mix:referenceable");
    n.addNode("foo").addNode("bar");
    n.addNode("qux");
    session.save();
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Node(javax.jcr.Node)

Example 32 with NodeImpl

use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.

the class EntryTest method testRestrictions.

public void testRestrictions() throws RepositoryException, NotExecutableException {
    // test if restrictions with expanded name are properly resolved
    Map<String, Value> restrictions = new HashMap<String, Value>();
    restrictions.put(ACLTemplate.P_GLOB.toString(), superuser.getValueFactory().createValue("*/test"));
    acl = getPolicy(acMgr, testPath, testUser.getPrincipal());
    acl.addEntry(testUser.getPrincipal(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) }, true, restrictions);
    acMgr.setPolicy(testPath, acl);
    superuser.save();
    Map<String, Boolean> toMatch = new HashMap<String, Boolean>();
    toMatch.put(acl.getPath(), false);
    toMatch.put(acl.getPath() + "test", false);
    toMatch.put(acl.getPath() + "/test", true);
    toMatch.put(acl.getPath() + "/something/test", true);
    toMatch.put(acl.getPath() + "de/test", true);
    NodeImpl aclNode = (NodeImpl) superuser.getNode(acl.getPath() + "/rep:policy");
    List<Entry> entries = Entry.readEntries(aclNode, testRootNode.getPath());
    assertTrue(!entries.isEmpty());
    assertEquals(1, entries.size());
    Entry entry = entries.iterator().next();
    for (String str : toMatch.keySet()) {
        assertEquals("Path to match : " + str, toMatch.get(str).booleanValue(), entry.matches(str));
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) HashMap(java.util.HashMap) Value(javax.jcr.Value)

Example 33 with NodeImpl

use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.

the class EntryTest method testIsLocal.

public void testIsLocal() throws NotExecutableException, RepositoryException {
    acl = getPolicy(acMgr, testPath, testUser.getPrincipal());
    modifyPrivileges(testPath, Privilege.JCR_READ, true);
    NodeImpl aclNode = (NodeImpl) superuser.getNode(acl.getPath() + "/rep:policy");
    List<Entry> entries = Entry.readEntries(aclNode, testRootNode.getPath());
    assertTrue(!entries.isEmpty());
    assertEquals(1, entries.size());
    Entry entry = entries.iterator().next();
    // false since acl has been created from path only -> no id
    assertTrue(entry.isLocal(((NodeImpl) testRootNode).getNodeId()));
    // false since internal id is null -> will never match.
    assertFalse(entry.isLocal(NodeId.randomId()));
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl)

Example 34 with NodeImpl

use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.

the class HierarchyConstraint method getBaseNodeId.

/**
     * Returns the id of the base node or <code>null</code> if there is no node
     * at the base path.
     *
     * @param context the evaluation context.
     * @return the id or <code>null</code> if it doesn't exist.
     */
protected final NodeId getBaseNodeId(EvaluationContext context) {
    if (id == null) {
        try {
            NodeImpl node = (NodeImpl) context.getSession().getNode(path);
            id = (NodeId) node.getId();
        } catch (RepositoryException e) {
            return null;
        }
    }
    return id;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) RepositoryException(javax.jcr.RepositoryException)

Example 35 with NodeImpl

use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.

the class UserImporterTest method testImportSelfAsGroupAbort.

public void testImportSelfAsGroupAbort() throws Exception {
    // uuid of the group itself
    String invalidId = "0120a4f9-196a-3f9e-b9f5-23f31f914da7";
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<sv:node sv:name=\"gFolder\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" + "<sv:node sv:name=\"g1\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Group</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>" + invalidId + "</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g1</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:members\" sv:type=\"WeakReference\"><sv:value>" + invalidId + "</sv:value></sv:property>" + "</sv:node>" + "</sv:node>";
    NodeImpl target = (NodeImpl) sImpl.getNode(umgr.getGroupsPath());
    try {
        doImport(target, xml, UserImporter.ImportBehavior.ABORT);
        fail("Importing self as group with ImportBehavior.ABORT must fail.");
    } catch (SAXException e) {
    // success.
    } finally {
        sImpl.refresh(false);
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) SAXException(org.xml.sax.SAXException)

Aggregations

NodeImpl (org.apache.jackrabbit.core.NodeImpl)161 RepositoryException (javax.jcr.RepositoryException)34 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 NodeId (org.apache.jackrabbit.core.id.NodeId)25 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)18 ArrayList (java.util.ArrayList)17 Value (javax.jcr.Value)16 Name (org.apache.jackrabbit.spi.Name)16 AccessControlEntry (javax.jcr.security.AccessControlEntry)15 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)13 AccessControlManager (javax.jcr.security.AccessControlManager)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 InputStream (java.io.InputStream)12 NodeIterator (javax.jcr.NodeIterator)12 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Principal (java.security.Principal)10 Node (javax.jcr.Node)10 ParsingContentHandler (org.apache.jackrabbit.commons.xml.ParsingContentHandler)10 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)9