use of javax.jcr.Session in project jackrabbit by apache.
the class TokenBasedLoginTest method testConcurrentLoginOfDifferentUsers.
/**
* Tests concurrent login of 3 different users on the Repository including
* token creation.
* Test copied and slightly adjusted from org.apache.jackrabbit.core.ConcurrentLoginTest
*/
public void testConcurrentLoginOfDifferentUsers() throws RepositoryException, NotExecutableException {
final Exception[] exception = new Exception[1];
List<Thread> testRunner = new ArrayList<Thread>();
for (int i = 0; i < 10; i++) {
testRunner.add(new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 100; i++) {
try {
SimpleCredentials c;
double rand = 3 * Math.random();
int index = (int) Math.floor(rand);
switch(index) {
case 0:
c = new SimpleCredentials(testuser.getID(), testuser.getID().toCharArray());
break;
case 1:
c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_SUPERUSER_PWD).toCharArray());
break;
default:
c = new SimpleCredentials(getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_NAME), getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + RepositoryStub.PROP_READONLY_PWD).toCharArray());
break;
}
c.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
Session s = getHelper().getRepository().login(c);
try {
Set<TokenCredentials> tcs = ((SessionImpl) s).getSubject().getPublicCredentials(TokenCredentials.class);
assertFalse(tcs.isEmpty());
} finally {
s.logout();
}
} catch (Exception e) {
exception[0] = e;
break;
}
}
}
}));
}
// start threads
for (Object aTestRunner : testRunner) {
((Thread) aTestRunner).start();
}
// join threads
for (Object aTestRunner : testRunner) {
try {
((Thread) aTestRunner).join();
} catch (InterruptedException e) {
fail(e.toString());
}
}
if (exception[0] != null) {
fail(exception[0].toString());
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class AccessManagerTest method testIsGrantedOnNewNode.
public void testIsGrantedOnNewNode() throws RepositoryException, NotExecutableException {
Session s = getHelper().getReadWriteSession();
try {
AccessManager acMgr = getAccessManager(s);
Node newNode = ((Node) s.getItem(testRoot)).addNode(nodeName2, testNodeType);
NodeId id = (NodeId) getItemId(newNode);
assertTrue(acMgr.isGranted(id, AccessManager.READ));
assertTrue(acMgr.isGranted(id, AccessManager.WRITE));
assertTrue(acMgr.isGranted(id, AccessManager.WRITE | AccessManager.REMOVE));
} finally {
s.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class AccessManagerTest method testCanAccessDeniedWorkspace.
public void testCanAccessDeniedWorkspace() throws RepositoryException, NotExecutableException {
Session s = getHelper().getReadOnlySession();
try {
Set<String> allAccessibles = new HashSet<String>(Arrays.asList(superuser.getWorkspace().getAccessibleWorkspaceNames()));
Set<String> sWorkspaceNames = new HashSet<String>(Arrays.asList(s.getWorkspace().getAccessibleWorkspaceNames()));
if (!allAccessibles.removeAll(sWorkspaceNames) || allAccessibles.isEmpty()) {
throw new NotExecutableException("No workspace name found that exists but is not accessible for ReadOnly session.");
}
String notAccessibleName = allAccessibles.iterator().next();
assertFalse(getAccessManager(s).canAccess(notAccessibleName));
} finally {
s.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class AccessManagerTest method testCanAccess.
public void testCanAccess() throws RepositoryException, NotExecutableException {
Session s = getHelper().getReadOnlySession();
try {
String wspName = s.getWorkspace().getName();
assertTrue(getAccessManager(s).canAccess(wspName));
} finally {
s.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class AccessManagerTest method testCanReadNewId.
public void testCanReadNewId() throws Exception {
Session s = getHelper().getReadOnlySession();
try {
NodeImpl n = (NodeImpl) testRootNode.addNode(nodeName1);
PropertyImpl p = (PropertyImpl) n.setProperty(propertyName1, "somevalue");
try {
AccessManager acMgr = getAccessManager(s);
acMgr.canRead(null, n.getId());
fail("expected repositoryexception");
} catch (RepositoryException e) {
// success
}
try {
AccessManager acMgr = getAccessManager(s);
acMgr.canRead(null, p.getId());
fail("expected repositoryexception");
} catch (RepositoryException e) {
// success
}
} finally {
s.logout();
}
}
Aggregations