use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class FindAuthorizablesTest method testFindAuthorizable.
@Test
public void testFindAuthorizable() throws RepositoryException, NotExecutableException {
Set<Principal> principals = new HashSet<Principal>();
PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
Principal p = pMgr.getPrincipal(superuser.getUserID());
if (p != null) {
principals.add(p);
PrincipalIterator principalIterator = pMgr.getGroupMembership(p);
while (principalIterator.hasNext()) {
principals.add(principalIterator.nextPrincipal());
}
}
Authorizable auth;
for (Principal principal : principals) {
auth = userMgr.getAuthorizable(principal);
if (auth != null) {
if (!auth.isGroup() && auth.hasProperty(UserConstants.REP_PRINCIPAL_NAME)) {
String val = auth.getProperty(UserConstants.REP_PRINCIPAL_NAME)[0].getString();
Iterator<Authorizable> users = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, val);
// the result must contain 1 authorizable
assertTrue(users.hasNext());
Authorizable first = users.next();
assertEquals(first.getID(), val);
// since id is unique -> there should be no more users in
// the iterator left
assertFalse(users.hasNext());
}
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class PrincipalManagerTest method testMembers2.
@Test
public void testMembers2() throws Exception {
Authorizable gr = null;
try {
gr = ((JackrabbitSession) superuser).getUserManager().createGroup(getClass().getName());
superuser.save();
PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
while (it.hasNext()) {
Principal p = it.nextPrincipal();
if (p.equals(principalMgr.getEveryone())) {
continue;
}
if (isGroup(p)) {
Enumeration<? extends Principal> en = ((java.security.acl.Group) p).members();
while (en.hasMoreElements()) {
Principal memb = en.nextElement();
assertTrue(principalMgr.hasPrincipal(memb.getName()));
}
}
}
} finally {
if (gr != null) {
gr.remove();
superuser.save();
}
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class UserImporterBaseTest method mockJackrabbitSession.
Session mockJackrabbitSession() throws Exception {
JackrabbitSession s = Mockito.mock(JackrabbitSession.class);
when(s.getUserManager()).thenReturn(getUserManager(root));
return s;
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class L3_PrecedenceRulesTest method tearDown.
@Override
protected void tearDown() throws Exception {
try {
if (testSession != null && testSession.isLive()) {
testSession.logout();
}
UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
Authorizable testUser = uMgr.getAuthorizable(testPrincipal);
if (testUser != null) {
testUser.remove();
}
Authorizable testGroup = uMgr.getAuthorizable(testGroupPrincipal);
if (testGroup != null) {
testGroup.remove();
}
superuser.save();
} finally {
super.tearDown();
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class L5_SpecialPermissionsTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Property p = testRootNode.setProperty(propertyName1, "val");
propertyPath = p.getPath();
Node child = testRootNode.addNode(nodeName1);
childPath = child.getPath();
p = child.setProperty(propertyName2, "val");
childPropertyPath = p.getPath();
Node grandChild = child.addNode(nodeName2);
grandChildPath = grandChild.getPath();
testUser = ExerciseUtility.createTestUser(((JackrabbitSession) superuser).getUserManager());
testUser2 = ExerciseUtility.createTestUser(((JackrabbitSession) superuser).getUserManager());
Group testGroup = ExerciseUtility.createTestGroup(((JackrabbitSession) superuser).getUserManager());
testGroup.addMember(testUser);
superuser.save();
testPrincipal = testUser.getPrincipal();
testGroupPrincipal = testGroup.getPrincipal();
}
Aggregations