use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class AddMembersTest method beforeSuite.
@Override
public void beforeSuite() throws Exception {
super.beforeSuite();
Session s = loginAdministrative();
try {
UserManager userManager = ((JackrabbitSession) s).getUserManager();
for (int i = 0; i <= GROUP_CNT; i++) {
Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), REL_TEST_PATH);
groupPaths.add(g.getPath());
}
createUsers(userManager);
} finally {
s.save();
s.logout();
}
System.out.println("setup done");
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class AddMembersTest method runTest.
@Override
public void runTest() throws Exception {
Session s = null;
try {
// use system session login to avoid measuring the login-performance here
s = systemLogin();
UserManager userManager = ((JackrabbitSession) s).getUserManager();
String groupPath = groupPaths.get(random.nextInt(GROUP_CNT));
Group g = (Group) userManager.getAuthorizableByPath(groupPath);
addMembers(userManager, g, s);
} catch (RepositoryException e) {
if (s.hasPendingChanges()) {
s.refresh(false);
}
} finally {
if (s != null) {
s.logout();
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class ScalabilityNodeRelationshipSuite method beforeIteration.
/**
* Executes before each test run
*/
@Override
public void beforeIteration(ExecutionContext context) throws RepositoryException {
if (LOG.isDebugEnabled()) {
LOG.debug("Started beforeIteration()");
}
// Contextualize the node types being used
if (nodeTypes != null && !nodeTypes.isEmpty()) {
context.getMap().put(CTX_ACT_NODE_TYPE_PROP, nodeTypes.get(0));
context.getMap().put(CTX_REL_NODE_TYPE_PROP, nodeTypes.get(1));
}
Session session = loginWriter();
UserManager userMgr = ((JackrabbitSession) session).getUserManager();
context.getMap().put("PREV_ITER_USERS", users.size());
// Add users
for (int idx = 0; idx < NUM_USERS * context.getIncrement(); idx++) {
String name = String.valueOf((char) (random.nextInt(26) + 'a')) + CTX_USER + context.getIncrement() + "_" + idx;
User user = userMgr.createUser(name, name);
LOG.debug("User created : " + name);
users.add(user);
}
// Add groups and include random number of members
for (int idx = 0; idx < NUM_GROUPS * context.getIncrement(); idx++) {
String name = String.valueOf((char) (random.nextInt(26) + 'a')) + CTX_GROUP + context.getIncrement() + idx;
Group group = userMgr.createGroup(name);
groups.add(group);
int groupMembers = random.nextInt(users.size());
for (int i = 0; i < groupMembers; i++) {
group.addMember(users.get(random.nextInt(users.size())));
}
}
session.save();
// create the load for this iteration
createLoad(context);
long loadFinish = System.currentTimeMillis();
context.getMap().put(CTX_ROOT_NODE_NAME_PROP, ROOT_NODE_NAME);
context.getMap().put(CTX_USER, users);
context.getMap().put(CTX_GROUP, groups);
waitBeforeIterationFinish(loadFinish);
if (LOG.isDebugEnabled()) {
LOG.debug("Finished beforeIteration()");
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class AccessControlImporterBaseTest method mockJackrabbitSession.
Session mockJackrabbitSession() throws Exception {
JackrabbitSession s = Mockito.mock(JackrabbitSession.class);
when(s.getPrincipalManager()).thenReturn(getPrincipalManager(root));
when(s.getAccessControlManager()).thenReturn(getAccessControlManager(root));
return s;
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class L7_ImpersonationTest method testAdvancedImpersonationTest.
public void testAdvancedImpersonationTest() throws RepositoryException {
// EXERCISE: change the permission setup such that the test-user is allowed to make himself an impersonator of 'another' user.
Session testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testUser.getID()));
sessionList.add(testSession);
UserManager uMgr = ((JackrabbitSession) testSession).getUserManager();
User another = uMgr.getAuthorizable(anotherUser.getID(), User.class);
assertNotNull(another);
Principal princ = uMgr.getAuthorizable(testUser.getID()).getPrincipal();
another.getImpersonation().grantImpersonation(princ);
testSession.save();
testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])).logout();
try {
Session s = testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0]));
sessionList.add(s);
fail("Test user must no longer be able to edit the impersonation of the test user");
} catch (LoginException e) {
// success
}
}
Aggregations