Search in sources :

Example 61 with NodeImpl

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

the class UserImporterTest method testImportGroup.

public void testImportGroup() throws RepositoryException, IOException, SAXException, NotExecutableException {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"g\" 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:Group</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>b2f5ff47-4366-31b6-a533-d8dc3614845d</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>g</sv:value></sv:property>" + "</sv:node>";
    NodeImpl target = (NodeImpl) sImpl.getNode(umgr.getGroupsPath());
    try {
        doImport(target, xml);
        assertTrue(target.isModified());
        assertTrue(sImpl.hasPendingChanges());
        Authorizable newGroup = umgr.getAuthorizable("g");
        assertNotNull(newGroup);
        assertTrue(newGroup.isGroup());
        assertEquals("g", newGroup.getPrincipal().getName());
        assertEquals("g", newGroup.getID());
        NodeImpl n = ((GroupImpl) newGroup).getNode();
        assertTrue(n.isNew());
        assertTrue(n.getParent().isSame(target));
        assertEquals("g", n.getName());
        assertEquals("g", n.getProperty(UserConstants.P_PRINCIPAL_NAME).getString());
        // saving changes of the import -> must succeed. add mandatory
        // props should have been created.
        sImpl.save();
    } finally {
        sImpl.refresh(false);
        if (target.hasNode("g")) {
            target.getNode("g").remove();
            sImpl.save();
        }
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 62 with NodeImpl

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

the class AccessControlImporterTest method testImportPolicyExists.

/**
 * Imports a resource-based ACL containing a single entry for a policy that
 * already exists.
 *
 * @throws Exception
 */
public void testImportPolicyExists() throws Exception {
    // all ACEs for an import. maybe control this behavior via uuid-flag.
    if (true) {
        return;
    }
    NodeImpl target = (NodeImpl) testRootNode;
    target = (NodeImpl) target.addNode("test", "test:sameNameSibsFalseChildNodeDefinition");
    AccessControlManager acMgr = sImpl.getAccessControlManager();
    for (AccessControlPolicyIterator it = acMgr.getApplicablePolicies(target.getPath()); it.hasNext(); ) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        if (policy instanceof AccessControlList) {
            Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_LOCK_MANAGEMENT) };
            ((AccessControlList) policy).addAccessControlEntry(sImpl.getPrincipalManager().getEveryone(), privs);
            acMgr.setPolicy(target.getPath(), policy);
        }
    }
    try {
        InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_2.getBytes("UTF-8"));
        SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, new PseudoConfig());
        ImportHandler ih = new ImportHandler(importer, sImpl);
        new ParsingContentHandler(ih).parse(in);
        AccessControlPolicy[] policies = acMgr.getPolicies(target.getPath());
        assertEquals(1, policies.length);
        assertTrue(policies[0] instanceof JackrabbitAccessControlList);
        AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
        assertEquals(1, entries.length);
        AccessControlEntry entry = entries[0];
        assertEquals("everyone", entry.getPrincipal().getName());
        List<Privilege> privs = Arrays.asList(entry.getPrivileges());
        assertEquals(2, privs.size());
        assertTrue(privs.contains(acMgr.privilegeFromName(Privilege.JCR_WRITE)) && privs.contains(acMgr.privilegeFromName(Privilege.JCR_LOCK_MANAGEMENT)));
        assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
        if (entry instanceof JackrabbitAccessControlEntry) {
            assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
        }
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) ByteArrayInputStream(java.io.ByteArrayInputStream) Privilege(javax.jcr.security.Privilege)

Example 63 with NodeImpl

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

the class AccessControlImporterTest method testImportACLUnknownFail.

/**
 * Imports a resource-based ACL containing a single entry.
 *
 * @throws Exception
 */
public void testImportACLUnknownFail() throws Exception {
    try {
        NodeImpl target = (NodeImpl) testRootNode.addNode(nodeName1);
        target.addMixin("rep:AccessControllable");
        InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_4.getBytes("UTF-8"));
        PseudoConfig config = new PseudoConfig();
        ((AccessControlImporter) config.getProtectedItemImporters().get(0)).setImportBehavior("default");
        SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, config);
        ImportHandler ih = new ImportHandler(importer, sImpl);
        try {
            new ParsingContentHandler(ih).parse(in);
            fail("importing unknown principal should fail based on configuration.");
        } catch (Exception e) {
        // ok
        }
    } finally {
        superuser.refresh(false);
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 64 with NodeImpl

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

the class NodeIteratorImpl method nextNode.

/**
 * Returns the next <code>Node</code> in the result set.
 * @return the next <code>Node</code> in the result set.
 * @throws NoSuchElementException if iteration has no more
 *   <code>Node</code>s.
 */
public Node nextNode() throws NoSuchElementException {
    initialize();
    if (next == null) {
        throw new NoSuchElementException();
    }
    NodeImpl n = next;
    fetchNext();
    return n;
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) NoSuchElementException(java.util.NoSuchElementException)

Example 65 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)

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