Search in sources :

Example 56 with NodeImpl

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

the class AccessControlImporterTest method testImportRepoACLAtTestNode.

/**
 * Make sure repo-level acl is not imported below any other node than the
 * root node.
 *
 * @throws Exception
 */
public void testImportRepoACLAtTestNode() throws Exception {
    NodeImpl target = (NodeImpl) testRootNode.addNode("test");
    target.addMixin("rep:RepoAccessControllable");
    AccessControlManager acMgr = sImpl.getAccessControlManager();
    try {
        InputStream in = new ByteArrayInputStream(XML_REPO_POLICY_TREE.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(null);
        assertEquals(0, policies.length);
        assertTrue(target.hasNode("rep:repoPolicy"));
        assertFalse(target.hasNode("rep:repoPolicy/allow0"));
        Node n = target.getNode("rep:repoPolicy");
        assertEquals("rep:RepoAccessControllable", n.getDefinition().getDeclaringNodeType().getName());
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) 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) Node(javax.jcr.Node)

Example 57 with NodeImpl

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

the class AccessControlImporterTest method testImportACLUnknown.

/**
 * Imports a resource-based ACL containing a single entry.
 *
 * @throws Exception
 */
public void testImportACLUnknown() throws Exception {
    try {
        NodeImpl target = (NodeImpl) testRootNode.addNode(nodeName1);
        target.addMixin("rep:AccessControllable");
        InputStream in = new ByteArrayInputStream(XML_POLICY_TREE_4.getBytes("UTF-8"));
        SessionImporter importer = new SessionImporter(target, sImpl, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new PseudoConfig());
        ImportHandler ih = new ImportHandler(importer, sImpl);
        new ParsingContentHandler(ih).parse(in);
        String path = target.getPath();
        AccessControlManager acMgr = sImpl.getAccessControlManager();
        AccessControlPolicy[] policies = acMgr.getPolicies(path);
        assertEquals(1, policies.length);
        assertTrue(policies[0] instanceof JackrabbitAccessControlList);
        AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
        assertEquals(2, entries.length);
        AccessControlEntry entry = entries[0];
        assertEquals("unknownprincipal", entry.getPrincipal().getName());
        assertEquals(1, entry.getPrivileges().length);
        assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
        entry = entries[1];
        assertEquals("admin", entry.getPrincipal().getName());
        assertEquals(1, entry.getPrivileges().length);
        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) 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) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 58 with NodeImpl

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

the class AccessControlImporterTest method testImportRepoACLAtRoot.

/**
 * Repo level acl must be imported underneath the root node.
 *
 * @throws Exception
 */
public void testImportRepoACLAtRoot() throws Exception {
    NodeImpl target = (NodeImpl) sImpl.getRootNode();
    AccessControlManager acMgr = sImpl.getAccessControlManager();
    try {
        // need to add mixin. in contrast to only using JCR API to retrieve
        // and set the policies the protected item import only is called if
        // the node to be imported is defined to be protected. however, if
        // the root node doesn't have the mixin assigned the defining node
        // type of the imported policy nodes will be rep:root (unstructured)
        // and the items will not be detected as being protected.
        target.addMixin("rep:RepoAccessControllable");
        InputStream in = new ByteArrayInputStream(XML_REPO_POLICY_TREE.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(null);
        assertEquals(1, policies.length);
        assertTrue(policies[0] instanceof JackrabbitAccessControlList);
        AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
        assertEquals(1, entries.length);
        assertEquals(1, entries[0].getPrivileges().length);
        assertEquals(acMgr.privilegeFromName("jcr:workspaceManagement"), entries[0].getPrivileges()[0]);
        assertTrue(target.hasNode("rep:repoPolicy"));
        assertTrue(target.hasNode("rep:repoPolicy/allow"));
        // clean up again
        acMgr.removePolicy(null, policies[0]);
        assertFalse(target.hasNode("rep:repoPolicy"));
        assertFalse(target.hasNode("rep:repoPolicy/allow"));
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) 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) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 59 with NodeImpl

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

the class UserAccessControlProviderTest method testAnonymousAccessDenied2.

public void testAnonymousAccessDenied2() throws Exception {
    Map<String, String> config = new HashMap<String, String>();
    config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
    config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ID, "abc");
    AccessControlProvider p2 = new UserAccessControlProvider();
    try {
        p2.init(s, config);
        Principal princ = new Principal() {

            public String getName() {
                return "abc";
            }
        };
        Set<Principal> anonymousPrincipals = Collections.singleton(princ);
        assertFalse(p2.canAccessRoot(anonymousPrincipals));
        CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
        try {
            assertEquals(CompiledPermissions.NO_PERMISSION, cp);
            assertFalse(cp.canReadAll());
            assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
        } finally {
            cp.close();
        }
    } finally {
        p2.close();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) HashMap(java.util.HashMap) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Example 60 with NodeImpl

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

the class UserAccessControlProviderTest method testAnonymousAccessDenied.

public void testAnonymousAccessDenied() throws Exception {
    Map<String, String> config = new HashMap<String, String>();
    config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
    AccessControlProvider p2 = new UserAccessControlProvider();
    try {
        p2.init(s, config);
        Set<Principal> anonymousPrincipals = getAnonymousPrincipals();
        assertFalse(p2.canAccessRoot(anonymousPrincipals));
        CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
        try {
            assertEquals(CompiledPermissions.NO_PERMISSION, cp);
            assertFalse(cp.canReadAll());
            assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
        } finally {
            cp.close();
        }
    } finally {
        p2.close();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) HashMap(java.util.HashMap) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

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