use of org.apache.jackrabbit.api.security.principal.PrincipalManager in project jackrabbit-oak by apache.
the class CompositePrincipalConfigurationTest method testSingleGetPrincipalManager.
@Test
public void testSingleGetPrincipalManager() {
PrincipalConfiguration testConfig = new TestPrincipalConfiguration();
addConfiguration(testConfig);
PrincipalManager pMgr = getComposite().getPrincipalManager(root, NamePathMapper.DEFAULT);
assertTrue(pMgr instanceof PrincipalManagerImpl);
}
use of org.apache.jackrabbit.api.security.principal.PrincipalManager 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.security.principal.PrincipalManager in project jackrabbit-oak by apache.
the class UserPrincipalProviderWithCacheTest method testPrincipalManagerGetGroupMembershipPopulatesCache.
@Test
public void testPrincipalManagerGetGroupMembershipPopulatesCache() throws Exception {
PrincipalManager principalManager = getPrincipalManager(systemRoot);
PrincipalIterator principalIterator = principalManager.getGroupMembership(getTestUser().getPrincipal());
assertPrincipals(ImmutableSet.copyOf(principalIterator), EveryonePrincipal.getInstance(), testGroup.getPrincipal());
root.refresh();
Tree principalCache = getCacheTree(root);
assertTrue(principalCache.exists());
assertEquals(CacheConstants.NT_REP_CACHE, TreeUtil.getPrimaryTypeName(principalCache));
assertNotNull(principalCache.getProperty(CacheConstants.REP_EXPIRATION));
PropertyState ps = principalCache.getProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES);
assertNotNull(ps);
String val = ps.getValue(Type.STRING);
assertEquals(testGroup.getPrincipal().getName(), val);
}
use of org.apache.jackrabbit.api.security.principal.PrincipalManager in project jackrabbit-oak by apache.
the class L13_SystemUserTest method testSystemUserPrincipal.
@Test
public void testSystemUserPrincipal() throws RepositoryException {
Authorizable authorizable = getUserManager(root).getAuthorizable(systemUser.getID());
// EXERCISE: what is the nature of the principal of the system user? Assert your expectedation.
Principal principal = authorizable.getPrincipal();
PrincipalManager principalManager = getPrincipalManager(root);
PrincipalIterator pIter = principalManager.getGroupMembership(principal);
// EXERCISE
int expectedSize = -1;
assertEquals(expectedSize, pIter.getSize());
// EXERCISE
List<Principal> expectedGroupPrincipals = null;
while (pIter.hasNext()) {
Principal group = pIter.nextPrincipal();
assertTrue(expectedGroupPrincipals.remove(group));
}
assertTrue(expectedGroupPrincipals.isEmpty());
}
use of org.apache.jackrabbit.api.security.principal.PrincipalManager in project jackrabbit-oak by apache.
the class CompositePrincipalConfigurationTest method testEmptyGetPrincipalManager.
@Test
public void testEmptyGetPrincipalManager() {
PrincipalManager pMgr = getComposite().getPrincipalManager(root, NamePathMapper.DEFAULT);
assertTrue(pMgr instanceof PrincipalManagerImpl);
}
Aggregations