use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class ConcurrentCreateUserTest method testCreateUsers.
public void testCreateUsers() throws Exception {
log.println("ConcurrentCreateUserTest.testCreateUsers: c=" + CONCURRENCY);
log.flush();
runTask(new Task() {
public void execute(Session session, Node test) throws RepositoryException {
JackrabbitSession s = null;
try {
s = (JackrabbitSession) getHelper().getSuperuserSession();
String name = "newname-" + UUID.randomUUID();
Authorizable authorizable = null;
int maxtries = RETRIES;
RepositoryException lastex = null;
while (authorizable == null && maxtries > 0) {
try {
maxtries -= 1;
authorizable = s.getUserManager().createUser(name, "password1", new TestPrincipal(name), INTERMEDIATE_PATH);
s.save();
} catch (InvalidItemStateException ex) {
lastex = ex;
log.println("got " + ex + ", retrying");
}
}
if (authorizable == null) {
throw new RepositoryException("user " + name + " not created in " + RETRIES + " attempts.", lastex);
}
userIDs.add(authorizable.getID());
log.println(authorizable + " created");
} finally {
s.logout();
}
}
}, CONCURRENCY, "/" + testPath);
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testAccessibleWorkspaceNames.
public void testAccessibleWorkspaceNames() throws Exception {
String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
Session s = getHelper().getSuperuserSession(altWsp);
User u = null;
Session us = null;
try {
// other users created in the default workspace...
u = ((JackrabbitSession) superuser).getUserManager().createUser("testUser", "testUser");
superuser.save();
us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()));
String[] wspNames = us.getWorkspace().getAccessibleWorkspaceNames();
assertFalse(Arrays.asList(wspNames).contains(altWsp));
} finally {
s.logout();
if (us != null) {
us.logout();
}
if (u != null) {
u.remove();
superuser.save();
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testNewUsersCanLogin.
public void testNewUsersCanLogin() throws Exception {
Session s = null;
User u = null;
try {
// other users created in the default workspace...
u = ((JackrabbitSession) superuser).getUserManager().createUser("testUser", "testUser");
superuser.save();
// the new user must be able to login to the repo
s = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()));
} finally {
if (s != null) {
s.logout();
}
if (u != null) {
u.remove();
superuser.save();
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testSystemUserCreation.
public void testSystemUserCreation() throws Exception {
String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
// system users must be automatically be created -> login with admin
// must therefore succeed.
Session s = getHelper().getSuperuserSession(altWsp);
try {
// admin/anonymous must be present
String adminId = ((UserPerWorkspaceSecurityManager) secMgr).adminId;
assertEquals(adminId, s.getUserID());
UserManager umgr = ((JackrabbitSession) s).getUserManager();
assertNotNull(umgr.getAuthorizable(adminId));
assertNotNull(umgr.getAuthorizable(((UserPerWorkspaceSecurityManager) secMgr).anonymousId));
} finally {
s.logout();
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.
the class SkipDeniedNodesTest method getPrincipal.
private static Principal getPrincipal(Session session) throws NotExecutableException {
UserManager userMgr;
if (!(session instanceof JackrabbitSession)) {
throw new NotExecutableException();
}
try {
userMgr = ((JackrabbitSession) session).getUserManager();
User user = (User) userMgr.getAuthorizable(session.getUserID());
if (user == null) {
throw new NotExecutableException("cannot get user for userID : " + session.getUserID());
}
return user.getPrincipal();
} catch (RepositoryException e) {
throw new NotExecutableException();
}
}
Aggregations