Search in sources :

Example 66 with Session

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

the class RemoveVersionTest method testRemoveVersionAndCheckinXA.

/**
     * Removes a version in 1 transaction and tries to commit afterwards the
     * versionable node using a 2nd transaction.
     *
     * Tests error reported in JCR-2613
     *
     * @throws Exception if an error occurs
     */
public void testRemoveVersionAndCheckinXA() throws Exception {
    UserTransaction tx = new UserTransactionImpl(superuser);
    tx.begin();
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    n.addMixin(mixReferenceable);
    testRootNode.save();
    String uuid = n.getUUID();
    // create two versions
    String v1 = n.checkin().getName();
    n.checkout();
    n.checkin();
    n.checkout();
    tx.commit();
    tx = new UserTransactionImpl(superuser);
    tx.begin();
    // remove one version
    n = superuser.getNodeByUUID(uuid);
    n.getVersionHistory().removeVersion(v1);
    n.save();
    tx.commit();
    // new session
    Session session = getHelper().getSuperuserSession();
    tx = new UserTransactionImpl(session);
    tx.begin();
    n = session.getNodeByUUID(uuid);
    n.checkin();
    tx.commit();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl) Session(javax.jcr.Session)

Example 67 with Session

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

the class HasPermissionTest method testReadOnlyPermission.

/**
     * Tests if <code>Session.hasPermission(String, String)</code> returns
     * <ul>
     * <li><code>true</code> for READ.</li>
     * <li><code>false</code> for all other actions.</li>
     * </ul>
     */
public void testReadOnlyPermission() throws Exception {
    Node n = testRootNode.addNode(nodeName2, testNodeType);
    superuser.save();
    Session readOnly = getHelper().getReadOnlySession();
    try {
        String path = n.getPath();
        assertTrue(readOnly.hasPermission(path, Session.ACTION_READ));
        assertFalse(readOnly.hasPermission(path + "newNode", Session.ACTION_ADD_NODE));
        assertFalse(readOnly.hasPermission(path, Session.ACTION_REMOVE));
        assertFalse(readOnly.hasPermission(path, Session.ACTION_SET_PROPERTY));
        assertFalse(readOnly.hasPermission(path, ACTION_ALL));
        assertFalse(readOnly.hasPermission(path, Session.ACTION_REMOVE + "," + Session.ACTION_SET_PROPERTY));
    } finally {
        readOnly.logout();
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 68 with Session

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

the class CheckPermissionTest method testCheckPermission.

/**
     * Tests if <code>Session.checkPermission(String, String)</code> works
     * properly: <ul> <li>Returns quietly if access is permitted.</li>
     * <li>Throws an {@link java.security.AccessControlException} if access is
     * denied.</li> </ul>
     */
public void testCheckPermission() throws Exception {
    testRootNode.addNode(nodeName2, testNodeType);
    superuser.save();
    Session readOnly = getHelper().getReadOnlySession();
    try {
        permissionCheckReadOnly(readOnly);
        permissionCheckReadWrite(superuser);
    } finally {
        readOnly.logout();
    }
}
Also used : Session(javax.jcr.Session)

Example 69 with Session

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

the class HasPermissionTest method testReadWritePermission.

/**
     * Tests if <code>Session.hasPermission(String, String)</code> returns
     * <ul>
     * <li><code>true</code> for all actions.</li>
     * </ul>
     */
public void testReadWritePermission() throws Exception {
    Node n = testRootNode.addNode(nodeName2, testNodeType);
    superuser.save();
    String path = n.getPath();
    Session rwSession = getHelper().getReadWriteSession();
    try {
        assertTrue(rwSession.hasPermission(path, Session.ACTION_READ));
        assertTrue(rwSession.hasPermission(path + "newNode", Session.ACTION_ADD_NODE));
        assertTrue(rwSession.hasPermission(path, Session.ACTION_REMOVE));
        assertTrue(rwSession.hasPermission(path, Session.ACTION_SET_PROPERTY));
        assertTrue(rwSession.hasPermission(path, ACTION_ALL));
    } finally {
        rwSession.logout();
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 70 with Session

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

the class NodeAddMixinTest method testAddSuccessfully.

/**
     * Tests if <code>Node.addMixin(String mixinName)</code> adds the requested
     * mixin and stores it in property <code>jcr:mixinTypes</code>
     */
public void testAddSuccessfully() throws NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
    if (mixinName == null) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    node.addMixin(mixinName);
    // test if mixin is written to property jcr:mixinTypes immediately
    Value[] mixinValues = node.getProperty(jcrMixinTypes).getValues();
    boolean found = false;
    for (int i = 0; i < mixinValues.length; i++) {
        found |= mixinName.equals(mixinValues[i].getString());
    }
    if (!found) {
        fail("Mixin type must be added to property " + jcrMixinTypes + " immediately.");
    }
    // it is implementation-specific if a added mixin is available
    // before or after save therefore save before further tests
    testRootNode.getSession().save();
    // test if added mixin is available by node.getMixinNodeTypes()
    NodeType[] mixins = node.getMixinNodeTypes();
    found = false;
    for (int i = 0; i < mixins.length; i++) {
        found |= mixinName.equals(mixins[i].getName());
    }
    if (!found) {
        fail("Mixin '" + mixinName + "' type not added.");
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) Session(javax.jcr.Session)

Aggregations

Session (javax.jcr.Session)1177 Node (javax.jcr.Node)645 Test (org.junit.Test)359 RepositoryException (javax.jcr.RepositoryException)206 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)158 SimpleCredentials (javax.jcr.SimpleCredentials)86 Property (javax.jcr.Property)78 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)77 Privilege (javax.jcr.security.Privilege)76 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)64 Value (javax.jcr.Value)63 Query (javax.jcr.query.Query)58 NodeIterator (javax.jcr.NodeIterator)55 QueryManager (javax.jcr.query.QueryManager)53 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)48 AccessControlManager (javax.jcr.security.AccessControlManager)47 HashMap (java.util.HashMap)44 UserManager (org.apache.jackrabbit.api.security.user.UserManager)43 ArrayList (java.util.ArrayList)41