Search in sources :

Example 36 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class GarbageCollectorTest method testGC.

public void testGC() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    deleteMyNodes();
    runGC(session, true);
    root.addNode("node1");
    Node node2 = root.addNode("node2");
    Node n = node2.addNode("nodeWithBlob").addNode("sub");
    ValueFactory vf = session.getValueFactory();
    Binary b = vf.createBinary(new RandomInputStream(20, 1000));
    n.setProperty("test", b);
    session.save();
    n = node2.addNode("nodeWithTemporaryBlob");
    n.setProperty("test", vf.createBinary(new RandomInputStream(11, 1000)));
    session.save();
    n.remove();
    session.save();
    GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
    gc.getDataStore().clearInUse();
    gc.setPersistenceManagerScan(false);
    gc.setMarkEventListener(this);
    if (gc.getDataStore() instanceof FileDataStore) {
        // make sure the file is old (access time resolution is 2 seconds)
        Thread.sleep(2000);
    }
    LOG.debug("scanning...");
    gc.mark();
    int count = listIdentifiers(gc);
    LOG.debug("stop scanning; currently " + count + " identifiers");
    LOG.debug("deleting...");
    gc.getDataStore().clearInUse();
    assertTrue(gc.sweep() > 0);
    int count2 = listIdentifiers(gc);
    assertEquals(count - 1, count2);
    // verify the node was moved, and that the binary is still there
    n = root.getNode("node1").getNode("nodeWithBlob").getNode("sub");
    b = n.getProperty("test").getValue().getBinary();
    InputStream in = b.getStream();
    InputStream in2 = new RandomInputStream(20, 1000);
    verifyInputStream(in, in2);
    deleteMyNodes();
    gc.close();
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) Binary(javax.jcr.Binary) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Session(javax.jcr.Session) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 37 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class CompatTokenProviderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    if (superuser instanceof SessionImpl) {
        UserManager umgr = ((SessionImpl) superuser).getUserManager();
        if (!umgr.isAutoSave()) {
            umgr.autoSave(true);
        }
        String uid = "test";
        while (umgr.getAuthorizable(uid) != null) {
            uid += "_";
        }
        testuser = umgr.createUser(uid, uid);
        userId = testuser.getID();
    } else {
        throw new NotExecutableException();
    }
    if (superuser.nodeExists(((ItemBasedPrincipal) testuser.getPrincipal()).getPath())) {
        session = (SessionImpl) superuser;
    } else {
        session = (SessionImpl) getHelper().getSuperuserSession("security");
    }
    tokenProvider = new CompatTokenProvider((SessionImpl) session, TokenBasedAuthentication.TOKEN_EXPIRATION);
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 38 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class EntryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    if (superuser instanceof NameResolver) {
        NameResolver resolver = (NameResolver) superuser;
        nodePath = resolver.getJCRName(ACLTemplate.P_NODE_PATH);
        glob = resolver.getJCRName(ACLTemplate.P_GLOB);
    } else {
        throw new NotExecutableException();
    }
    restrictions = new HashMap<String, Value>(2);
    restrictions.put(nodePath, superuser.getValueFactory().createValue("/a/b/c/d", PropertyType.PATH));
    restrictions.put(glob, superuser.getValueFactory().createValue("*"));
    acl = new ACLTemplate(testPrincipal, testPath, (SessionImpl) superuser, superuser.getValueFactory());
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) BooleanValue(org.apache.jackrabbit.value.BooleanValue) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) SessionImpl(org.apache.jackrabbit.core.SessionImpl) NameResolver(org.apache.jackrabbit.spi.commons.conversion.NameResolver)

Example 39 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class WriteTest method testCanReadOnCombinedPolicies.

public void testCanReadOnCombinedPolicies() throws RepositoryException, NotExecutableException {
    Group testGroup = getTestGroup();
    Session testSession = getTestSession();
    /*
          precondition:
          testuser must have READ-only permission on test-node and below
        */
    checkReadOnly(path);
    Privilege[] readPrivs = privilegesFromName(Privilege.JCR_READ);
    // nodebased: remove READ privilege for 'testUser' at 'path'
    withdrawPrivileges(path, readPrivs, getRestrictions(superuser, path));
    // principalbased: add READ privilege for 'testGroup'
    givePrivileges(path, testGroup.getPrincipal(), readPrivs, getPrincipalBasedRestrictions(path), false);
    /*
         expected result:
         - nodebased wins over principalbased -> READ is denied
         */
    NodeId nodeId = ((NodeImpl) superuser.getNode(path)).getNodeId();
    assertFalse(((SessionImpl) testSession).getAccessManager().canRead(null, nodeId));
    /* allow again on child N -> should be allowed */
    givePrivileges(childNPath, testGroup.getPrincipal(), readPrivs, getPrincipalBasedRestrictions(path), false);
    NodeId childId = ((NodeImpl) superuser.getNode(childNPath)).getNodeId();
    assertTrue(((SessionImpl) testSession).getAccessManager().canRead(null, childId));
    // remove the nodebased policy
    JackrabbitAccessControlList policy = getPolicy(acMgr, path, testUser.getPrincipal());
    acMgr.removePolicy(policy.getPath(), policy);
    superuser.save();
    /*
         expected result:
         - READ privilege is present again.
         */
    assertTrue(((SessionImpl) testSession).getAccessManager().canRead(null, nodeId));
    // nodebased: remove READ privilege for 'testUser' at 'path'
    givePrivileges(path, readPrivs, getRestrictions(superuser, path));
    // principalbased: add READ privilege for 'testGroup'
    withdrawPrivileges(path, testGroup.getPrincipal(), readPrivs, getPrincipalBasedRestrictions(path), false);
    /*
         expected result:
         - nodebased wins over principalbased -> READ is allowed
         */
    assertTrue(((SessionImpl) testSession).getAccessManager().canRead(null, nodeId));
    /* allow again on child N -> should be allowed */
    withdrawPrivileges(childNPath, testGroup.getPrincipal(), readPrivs, getPrincipalBasedRestrictions(path), false);
    assertFalse(((SessionImpl) testSession).getAccessManager().canRead(null, childId));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) NodeImpl(org.apache.jackrabbit.core.NodeImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Session(javax.jcr.Session)

Example 40 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class AccessControlImporterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    if (!(superuser instanceof SessionImpl)) {
        throw new NotExecutableException("SessionImpl expected");
    }
    sImpl = (SessionImpl) superuser;
    // make sure the repository provides resource based policies.
    AccessControlPolicyIterator it = sImpl.getAccessControlManager().getApplicablePolicies("/");
    if (!it.hasNext()) {
        AccessControlPolicy[] pcs = sImpl.getAccessControlManager().getPolicies("/");
        if (pcs == null || pcs.length == 0) {
            throw new NotExecutableException();
        }
    }
// ok resource based acl
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Aggregations

SessionImpl (org.apache.jackrabbit.core.SessionImpl)63 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)12 Value (javax.jcr.Value)11 Name (org.apache.jackrabbit.spi.Name)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Session (javax.jcr.Session)9 NodeImpl (org.apache.jackrabbit.core.NodeImpl)8 NodeId (org.apache.jackrabbit.core.id.NodeId)8 Principal (java.security.Principal)7 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)7 NodeIterator (javax.jcr.NodeIterator)6 Privilege (javax.jcr.security.Privilege)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)6 Path (org.apache.jackrabbit.spi.Path)6 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 InvalidItemStateException (javax.jcr.InvalidItemStateException)4 LockException (javax.jcr.lock.LockException)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4