Search in sources :

Example 96 with AccessDeniedException

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

the class AbstractVersionManagementTest method testWriteVersionStore.

public void testWriteVersionStore() throws RepositoryException, NotExecutableException {
    Node trn = getTestNode();
    modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
    modifyPrivileges(trn.getPath(), Privilege.JCR_VERSION_MANAGEMENT, false);
    Node n = createVersionableNode(testRootNode);
    try {
        Node n2 = trn.getNode(nodeName1);
        n2.checkin();
        fail("No write permission in the version storage.");
    } catch (AccessDeniedException e) {
        // success
        log.debug(e.getMessage());
        // ... but the property must not be modified nor indicating
        // checkedIn status
        Property p = n.getProperty("jcr:isCheckedOut");
        assertFalse(p.isModified());
        assertTrue(n.getProperty("jcr:isCheckedOut").getValue().getBoolean());
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 97 with AccessDeniedException

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

the class AbstractRepositoryOperationTest method testRegisterPrivilege.

public void testRegisterPrivilege() throws Exception {
    assertDefaultPrivileges(PrivilegeRegistry.REP_PRIVILEGE_MANAGEMENT_NAME);
    assertPermission(Permission.PRIVILEGE_MNGMT, false);
    try {
        Workspace testWsp = getTestWorkspace();
        ((JackrabbitWorkspace) testWsp).getPrivilegeManager().registerPrivilege(getNewPrivilegeName(testWsp), false, new String[0]);
        fail("Privilege registration should be denied.");
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Example 98 with AccessDeniedException

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

the class AbstractRepositoryOperationTest method testUnRegisterNodeType.

public void testUnRegisterNodeType() throws Exception {
    assertDefaultPrivileges(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT);
    assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);
    NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
    ntd.setName("testNodeType");
    ntd.setMixin(true);
    ntm.registerNodeType(ntd, true);
    Workspace testWsp = getTestWorkspace();
    try {
        try {
            NodeTypeManager testNtm = testWsp.getNodeTypeManager();
            testNtm.unregisterNodeType(ntd.getName());
            fail("Namespace unregistration should be denied.");
        } catch (AccessDeniedException e) {
        // success
        }
        try {
            NodeTypeManager testNtm = testWsp.getNodeTypeManager();
            testNtm.unregisterNodeTypes(new String[] { ntd.getName() });
            fail("Namespace unregistration should be denied.");
        } catch (AccessDeniedException e) {
        // success
        }
    } finally {
        // clean up (not supported by jackrabbit-core)
        try {
            ntm.unregisterNodeType(ntd.getName());
        } catch (Exception e) {
        // ns unregistration is not supported by jackrabbit-core.
        }
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) AccessDeniedException(javax.jcr.AccessDeniedException) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) 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 99 with AccessDeniedException

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

the class AbstractNodeTypeManagementTest method testSessionImportXML.

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

Example 100 with AccessDeniedException

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

the class AbstractNodeTypeManagementTest method testSessionMove.

public void testSessionMove() throws RepositoryException, NotExecutableException {
    Session s = getTestSession();
    String parentPath = childNode.getParent().getPath();
    String srcPath = childNode.getPath();
    String destPath = parentPath + "/" + nodeName3;
    checkReadOnly(parentPath);
    try {
        s.move(srcPath, destPath);
        s.save();
        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 {
        s.move(srcPath, destPath);
        s.save();
        fail("Missing privilege jcr:nodeTypeManagement.");
    } catch (AccessDeniedException e) {
    // success
    }
    // adding jcr:nodeTypeManagement privilege will grant permission to move.
    modifyPrivileges(parentPath, PrivilegeRegistry.REP_WRITE, true);
    s.move(srcPath, destPath);
    s.save();
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Session(javax.jcr.Session)

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