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();
}
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);
}
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());
}
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));
}
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
}
Aggregations