Search in sources :

Example 86 with Workspace

use of javax.jcr.Workspace in project jackrabbit-oak by apache.

the class PrivilegeManagementTest method testRegisterPrivilege.

@Test
public void testRegisterPrivilege() throws Exception {
    try {
        Workspace testWsp = testSession.getWorkspace();
        ((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) Test(org.junit.Test)

Example 87 with Workspace

use of javax.jcr.Workspace in project jackrabbit-oak by apache.

the class NodeTypeManagementTest method testCopy.

@Test
public void testCopy() throws Exception {
    Workspace wsp = testSession.getWorkspace();
    String parentPath = childNode.getParent().getPath();
    String srcPath = childNode.getPath();
    String destPath = parentPath + "/destination";
    try {
        wsp.copy(srcPath, destPath);
        fail("Missing write privilege.");
    } catch (AccessDeniedException e) {
    // success
    }
    // with simple write privilege copying a node is not allowed.
    modify(parentPath, Privilege.JCR_WRITE, true);
    try {
        wsp.copy(srcPath, destPath);
        fail("Missing privilege jcr:nodeTypeManagement.");
    } catch (AccessDeniedException e) {
    // success
    }
    // adding jcr:nodeTypeManagement privilege will grant permission to copy.
    modify(parentPath, REP_WRITE, true);
    wsp.copy(srcPath, destPath);
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 88 with Workspace

use of javax.jcr.Workspace in project jackrabbit-oak by apache.

the class NamespaceManagementTest method testUnregisterNamespace.

@Test
public void testUnregisterNamespace() throws Exception {
    Workspace wsp = superuser.getWorkspace();
    String pfx = getNewNamespacePrefix(wsp);
    wsp.getNamespaceRegistry().registerNamespace(pfx, getNewNamespaceURI(wsp));
    try {
        Workspace testWsp = testSession.getWorkspace();
        testWsp.getNamespaceRegistry().unregisterNamespace(pfx);
        fail("Namespace unregistration should be denied.");
    } catch (AccessDeniedException e) {
    // success
    } finally {
        // clean up (not supported by jackrabbit-core)
        try {
            superuser.getWorkspace().getNamespaceRegistry().unregisterNamespace(pfx);
        } catch (Exception e) {
        // ns unregistration is not supported by jackrabbit-core.
        }
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) RepositoryException(javax.jcr.RepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 89 with Workspace

use of javax.jcr.Workspace in project jackrabbit-oak by apache.

the class PrivilegeRegistrationTest method testRegisterCustomPrivilegesVisibleInContent.

/**
     * @since oak
     */
@Test
public void testRegisterCustomPrivilegesVisibleInContent() throws RepositoryException {
    Workspace workspace = session.getWorkspace();
    workspace.getNamespaceRegistry().registerNamespace("test", "http://www.apache.org/jackrabbit/test");
    Map<String, String[]> newCustomPrivs = new HashMap<String, String[]>();
    newCustomPrivs.put("new", new String[0]);
    newCustomPrivs.put("test:new", new String[0]);
    for (String name : newCustomPrivs.keySet()) {
        boolean isAbstract = true;
        String[] aggrNames = newCustomPrivs.get(name);
        Privilege registered = privilegeManager.registerPrivilege(name, isAbstract, aggrNames);
        Node privilegeRoot = session.getNode(PrivilegeConstants.PRIVILEGES_PATH);
        assertTrue(privilegeRoot.hasNode(name));
        Node privNode = privilegeRoot.getNode(name);
        assertTrue(privNode.getProperty(PrivilegeConstants.REP_IS_ABSTRACT).getBoolean());
        assertFalse(privNode.hasProperty(PrivilegeConstants.REP_AGGREGATES));
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(javax.jcr.Node) Privilege(javax.jcr.security.Privilege) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 90 with Workspace

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

the class ShareableNodeTest method testRemoveAncestorOfSharedNode.

/**
     * Verify that a shared node is removed when the ancestor is removed.
     * See also JCR-2257.
     */
public void testRemoveAncestorOfSharedNode() throws Exception {
    Node a1 = testRootNode.addNode("a1");
    Node a2 = a1.addNode("a2");
    Node b1 = a1.addNode("b1");
    ensureMixinType(b1, mixShareable);
    testRootNode.save();
    //now we have a shareable node N with path a1/b1
    Workspace workspace = testRootNode.getSession().getWorkspace();
    String path = a2.getPath() + "/b2";
    workspace.clone(workspace.getName(), b1.getPath(), path, false);
    testRootNode.save();
    //now we have another shareable node N' in the same shared set as N with path a1/a2/b2
    a2.remove();
    testRootNode.save();
    // assert b2 is removed from index
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    String stmt = testPath + "//b2";
    NodeIterator it = qm.createQuery(stmt, Query.XPATH).execute().getNodes();
    assertFalse(it.hasNext());
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Workspace(javax.jcr.Workspace)

Aggregations

Workspace (javax.jcr.Workspace)105 Node (javax.jcr.Node)51 Session (javax.jcr.Session)25 AccessDeniedException (javax.jcr.AccessDeniedException)18 Test (org.junit.Test)18 RepositoryException (javax.jcr.RepositoryException)16 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)16 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)10 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)8 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ObservationManager (javax.jcr.observation.ObservationManager)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 FileOutputStream (java.io.FileOutputStream)5 NodeIterator (javax.jcr.NodeIterator)4 Version (javax.jcr.version.Version)4