Search in sources :

Example 1 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class NodeCorruptionTest method testCopyMultiSingleValue.

public void testCopyMultiSingleValue() throws Exception {
    Node root = superuser.getRootNode();
    String nodeName = "testCopyMulti" + System.currentTimeMillis();
    if (root.hasNode(nodeName)) {
        root.getNode(nodeName).remove();
        superuser.save();
    }
    Node test = root.addNode(nodeName);
    test.setProperty("x", "Hi");
    superuser.save();
    String wsp = superuser.getWorkspace().getName();
    String workspace2 = getAlternativeWorkspaceName();
    if (workspace2 == null) {
        throw new NotExecutableException();
    }
    Session s2 = getHelper().getSuperuserSession(workspace2);
    s2.getWorkspace().clone(wsp, "/" + nodeName, "/" + nodeName, true);
    Node test2 = s2.getRootNode().getNode(nodeName);
    test2.setProperty("x", (Value) null);
    test2.setProperty("x", new String[] {});
    s2.save();
    test.update(workspace2);
    try {
        Value[] values = test.getProperty("x").getValues();
        assertEquals(0, values.length);
    } catch (RepositoryException e) {
        // if we get here, it's a bug, as it is a multi-valued property now
        // anyway, let's see what happens if we try to read it as a single valued property
        test.getProperty("x").getValue();
        // even if that works: it's still a bug
        throw e;
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 2 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class WriteTest method testEditor2.

public void testEditor2() throws NotExecutableException, RepositoryException {
    UserManager uMgr = getUserManager(superuser);
    User u = null;
    User u2 = null;
    try {
        u = uMgr.createUser("t", "t");
        u2 = uMgr.createUser("tt", "tt", new TestPrincipal("tt"), "t/tt");
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        Principal p = u.getPrincipal();
        Principal p2 = u2.getPrincipal();
        if (p instanceof ItemBasedPrincipal && p2 instanceof ItemBasedPrincipal && Text.isDescendant(((ItemBasedPrincipal) p).getPath(), ((ItemBasedPrincipal) p2).getPath())) {
            JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
            JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p2);
            acMgr.setPolicy(acls[0].getPath(), acls[0]);
            acls = acMgr.getApplicablePolicies(p);
            String path = acls[0].getPath();
            Node n = superuser.getNode(path);
            assertEquals("rep:PrincipalAccessControl", n.getPrimaryNodeType().getName());
        } else {
            throw new NotExecutableException();
        }
    } finally {
        superuser.refresh(false);
        if (u2 != null)
            u2.remove();
        if (u != null)
            u.remove();
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) User(org.apache.jackrabbit.api.security.user.User) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Node(javax.jcr.Node) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 3 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class WriteTest method testInvalidPrincipal.

public void testInvalidPrincipal() throws Exception {
    PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
    String unknown = "unknown";
    while (pMgr.hasPrincipal(unknown)) {
        unknown = unknown + "_";
    }
    Principal principal = new PrincipalImpl(unknown);
    if (acMgr instanceof JackrabbitAccessControlManager) {
        // first try applicable policies
        try {
            AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acMgr).getApplicablePolicies(principal);
            assertNotNull(policies);
            assertEquals(0, policies.length);
        } catch (AccessControlException e) {
        // success
        }
        // second existing policies
        try {
            AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acMgr).getPolicies(principal);
            assertNotNull(policies);
            assertEquals(0, policies.length);
        } catch (AccessControlException e) {
        // success
        }
    } else {
        throw new NotExecutableException();
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl)

Example 4 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AdministratorTest method testAdminNodeCollidingWithAuthorizableFolder.

/**
     * Test for collisions that would prevent from recreate the admin user.
     * - an intermediate rep:AuthorizableFolder node with the same name
     */
public void testAdminNodeCollidingWithAuthorizableFolder() throws RepositoryException, NotExecutableException {
    Authorizable admin = userMgr.getAuthorizable(adminId);
    if (admin == null || !(admin instanceof AuthorizableImpl)) {
        throw new NotExecutableException();
    }
    // access the node corresponding to the admin user and remove it
    NodeImpl adminNode = ((AuthorizableImpl) admin).getNode();
    String adminPath = adminNode.getPath();
    String adminNodeName = adminNode.getName();
    Node parentNode = adminNode.getParent();
    Session s = adminNode.getSession();
    adminNode.remove();
    // use session obtained from the node as usermgr may point to a dedicated
    // system workspace different from the superusers workspace.
    s.save();
    Session s2 = null;
    String collidingPath = null;
    try {
        // now create a colliding node:
        Node n = parentNode.addNode(adminNodeName, "rep:AuthorizableFolder");
        collidingPath = n.getPath();
        s.save();
        // force recreation of admin user.
        s2 = getHelper().getSuperuserSession();
        admin = userMgr.getAuthorizable(adminId);
        assertNotNull(admin);
        assertEquals(adminNodeName, ((AuthorizableImpl) admin).getNode().getName());
        assertFalse(adminPath.equals(((AuthorizableImpl) admin).getNode().getPath()));
    } finally {
        if (s2 != null) {
            s2.logout();
        }
        // remove the extra folder and the admin user (created underneath) again.
        if (collidingPath != null) {
            s.getNode(collidingPath).remove();
            s.save();
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeImpl(org.apache.jackrabbit.core.NodeImpl) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Session(javax.jcr.Session)

Example 5 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AuthorizableActionTest method assertAcAction.

private static void assertAcAction(Authorizable a, UserManagerImpl umgr) throws RepositoryException, NotExecutableException {
    Session s = umgr.getSession();
    AccessControlManager acMgr = s.getAccessControlManager();
    boolean hasACL = false;
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/");
    while (it.hasNext()) {
        if (it.nextAccessControlPolicy() instanceof AccessControlList) {
            hasACL = true;
            break;
        }
    }
    if (!hasACL) {
        for (AccessControlPolicy p : acMgr.getPolicies("/")) {
            if (p instanceof AccessControlList) {
                hasACL = true;
                break;
            }
        }
    }
    if (!hasACL) {
        throw new NotExecutableException("No ACLs in workspace containing users.");
    }
    String path = a.getPath();
    assertEquals(1, acMgr.getPolicies(path).length);
    assertTrue(acMgr.getPolicies(path)[0] instanceof AccessControlList);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Session(javax.jcr.Session)

Aggregations

NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)381 Node (javax.jcr.Node)149 NodeType (javax.jcr.nodetype.NodeType)84 Value (javax.jcr.Value)81 RepositoryException (javax.jcr.RepositoryException)64 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)61 Session (javax.jcr.Session)59 Property (javax.jcr.Property)47 NodeDefinition (javax.jcr.nodetype.NodeDefinition)29 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)28 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)25 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)23 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)22 Test (org.junit.Test)22 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)21 User (org.apache.jackrabbit.api.security.user.User)19 Principal (java.security.Principal)18 NodeIterator (javax.jcr.NodeIterator)18 UserManager (org.apache.jackrabbit.api.security.user.UserManager)17 ItemExistsException (javax.jcr.ItemExistsException)16