Search in sources :

Example 21 with AccessDeniedException

use of javax.jcr.AccessDeniedException in project jackrabbit by apache.

the class AbstractNodeTypeManagementTest method testWorkspaceImportXML.

public void testWorkspaceImportXML() throws RepositoryException, NotExecutableException, IOException {
    Workspace wsp = getTestSession().getWorkspace();
    String parentPath = childNode.getPath();
    checkReadOnly(parentPath);
    try {
        wsp.importXML(parentPath, getXmlForImport(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        fail("Missing write privilege.");
    } catch (AccessDeniedException e) {
    // success
    }
    // with simple write privilege moving a node is not allowed.
    modifyPrivileges(parentPath, Privilege.JCR_WRITE, true);
    try {
        wsp.importXML(parentPath, getXmlForImport(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        fail("Missing privilege jcr:nodeTypeManagement.");
    } catch (AccessDeniedException e) {
    // success
    }
    // adding jcr:nodeTypeManagement privilege will grant permission to move.
    modifyPrivileges(parentPath, PrivilegeRegistry.REP_WRITE, true);
    wsp.importXML(parentPath, getXmlForImport(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Workspace(javax.jcr.Workspace)

Example 22 with AccessDeniedException

use of javax.jcr.AccessDeniedException in project jackrabbit by apache.

the class AbstractRepositoryOperationTest method testWorkspaceDeletion.

public void testWorkspaceDeletion() throws Exception {
    assertDefaultPrivileges(NameConstants.JCR_WORKSPACE_MANAGEMENT);
    assertPermission(Permission.WORKSPACE_MNGMT, false);
    Workspace wsp = superuser.getWorkspace();
    String workspaceName = getNewWorkspaceName(wsp);
    wsp.createWorkspace(workspaceName);
    try {
        Workspace testWsp = getTestWorkspace();
        List<String> wspNames = Arrays.asList(testWsp.getAccessibleWorkspaceNames());
        if (wspNames.contains(workspaceName)) {
            testWsp.deleteWorkspace(workspaceName);
            fail("Workspace deletion should be denied.");
        }
    } catch (AccessDeniedException e) {
    // success
    } finally {
        // clean up (not supported by jackrabbit-core)
        try {
            superuser.getWorkspace().deleteWorkspace(workspaceName);
        } catch (Exception e) {
        // workspace removal is not supported by jackrabbit-core.
        }
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) AccessDeniedException(javax.jcr.AccessDeniedException) RepositoryException(javax.jcr.RepositoryException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Example 23 with AccessDeniedException

use of javax.jcr.AccessDeniedException in project jackrabbit by apache.

the class AbstractLockManagementTest method testReadLockContent.

public void testReadLockContent() throws RepositoryException, NotExecutableException {
    Node n = createLockedNode(testRootNode);
    Node childN = n.addNode(nodeName2);
    modifyPrivileges(n.getPath(), Privilege.JCR_READ, false);
    modifyPrivileges(childN.getPath(), Privilege.JCR_READ, true);
    Node childN2 = (Node) getTestSession().getItem(childN.getPath());
    try {
        childN2.getLock();
        fail("TestUser doesn't have permission to read the jcr:lockIsDeep property.");
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node)

Example 24 with AccessDeniedException

use of javax.jcr.AccessDeniedException in project jackrabbit by apache.

the class AbstractLockManagementTest method testLock3.

public void testLock3() throws RepositoryException, NotExecutableException {
    Node n = createLockableNode(testRootNode);
    Node trn = getTestNode();
    modifyPrivileges(trn.getPath(), Privilege.JCR_READ, true);
    modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
    Node n2 = trn.getNode(n.getName());
    n2.lock(true, true);
    Lock l = n2.getLock();
    // withdraw lock-mgmt -> must not be able to refresh the lock or
    // unlock the node
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, false);
    try {
        l.refresh();
        fail("TestUser doesn't have permission to refresh the lock.");
    } catch (AccessDeniedException e) {
    // success
    }
    try {
        n2.unlock();
        fail("TestUser doesn't have permission to unlock the node.");
    } catch (AccessDeniedException e) {
    // success
    }
    // make sure the lock can be removed upon session.logout.
    modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock)

Example 25 with AccessDeniedException

use of javax.jcr.AccessDeniedException in project jackrabbit by apache.

the class AbstractRepositoryOperationTest method testRegisterNodeType.

public void testRegisterNodeType() throws Exception {
    assertDefaultPrivileges(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT);
    assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);
    Workspace testWsp = getTestWorkspace();
    NodeTypeManager ntm = testWsp.getNodeTypeManager();
    NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
    ntd.setName("testNodeType");
    ntd.setMixin(true);
    try {
        ntm.registerNodeType(ntd, true);
        fail("Node type registration should be denied.");
    } catch (AccessDeniedException e) {
    // success
    }
    try {
        ntm.registerNodeType(ntd, false);
        fail("Node type registration should be denied.");
    } catch (AccessDeniedException e) {
    // success
    }
    NodeTypeTemplate[] ntds = new NodeTypeTemplate[2];
    ntds[0] = ntd;
    ntds[1] = ntm.createNodeTypeTemplate();
    ntds[1].setName("anotherNodeType");
    ntds[1].setDeclaredSuperTypeNames(new String[] { "nt:file" });
    try {
        ntm.registerNodeTypes(ntds, true);
        fail("Node type registration should be denied.");
    } catch (AccessDeniedException e) {
    // success
    }
    try {
        ntm.registerNodeTypes(ntds, false);
        fail("Node type registration should be denied.");
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) AccessDeniedException(javax.jcr.AccessDeniedException) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Aggregations

AccessDeniedException (javax.jcr.AccessDeniedException)189 Node (javax.jcr.Node)80 Test (org.junit.Test)68 Session (javax.jcr.Session)33 RepositoryException (javax.jcr.RepositoryException)23 Privilege (javax.jcr.security.Privilege)22 UserManager (org.apache.jackrabbit.api.security.user.UserManager)19 Workspace (javax.jcr.Workspace)18 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)15 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 PathNotFoundException (javax.jcr.PathNotFoundException)13 Path (org.apache.jackrabbit.spi.Path)13 Principal (java.security.Principal)11 User (org.apache.jackrabbit.api.security.user.User)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)10 AccessControlManager (javax.jcr.security.AccessControlManager)9 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)9 Property (javax.jcr.Property)8 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)8 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)7