use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit by apache.
the class DefaultPrincipalProviderTest method testPrincipalCache.
/**
* Test if cache is properly updated.
*
* @throws Exception
*/
public void testPrincipalCache() throws Exception {
Principal testPrincipal = getTestPrincipal();
String testName = testPrincipal.getName();
assertNull(principalProvider.getPrincipal(testName));
// create a user with the given principal name -> cache must be updated.
Authorizable a = userMgr.createUser(testName, "pw");
save(superuser);
try {
assertNotNull(principalProvider.getPrincipal(testName));
} finally {
a.remove();
save(superuser);
}
// after removal -> entry must be removed from the cache.
assertNull(principalProvider.getPrincipal(testName));
// create a group with that name
a = userMgr.createGroup(testPrincipal);
save(superuser);
try {
Principal p = principalProvider.getPrincipal(testName);
assertNotNull(p);
assertTrue(p instanceof GroupPrincipal);
} finally {
a.remove();
save(superuser);
}
// recreate user again without filling cache with 'null' value
a = userMgr.createUser(testName, "pw");
save(superuser);
try {
Principal p = principalProvider.getPrincipal(testName);
assertNotNull(p);
assertFalse(p instanceof GroupPrincipal);
} finally {
a.remove();
save(superuser);
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit by apache.
the class GroupImplTest method testEveryoneGroupPrincipal.
public void testEveryoneGroupPrincipal() throws Exception {
Group g = null;
try {
g = userMgr.createGroup(EveryonePrincipal.NAME);
save(superuser);
GroupPrincipal principal = (GroupPrincipal) g.getPrincipal();
assertTrue(principal.isMember(new Principal() {
public String getName() {
return "test";
}
}));
assertFalse(principal.isMember(principal));
} finally {
if (g != null) {
g.remove();
save(superuser);
}
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit by apache.
the class ACLTemplateTest method testMultiplePrincipals.
public void testMultiplePrincipals() throws RepositoryException, NotExecutableException {
PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
Principal everyone = pMgr.getEveryone();
Principal grPrincipal = null;
PrincipalIterator it = pMgr.findPrincipals("", PrincipalManager.SEARCH_TYPE_GROUP);
while (it.hasNext()) {
GroupPrincipal gr = (GroupPrincipal) it.nextPrincipal();
if (!everyone.equals(gr)) {
grPrincipal = gr;
}
}
if (grPrincipal == null || grPrincipal.equals(everyone)) {
throw new NotExecutableException();
}
Privilege[] privs = privilegesFromName(Privilege.JCR_READ);
JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
pt.addAccessControlEntry(testPrincipal, privs);
assertFalse(pt.addAccessControlEntry(testPrincipal, privs));
// add same privileges for another principal -> must modify as well.
assertTrue(pt.addAccessControlEntry(everyone, privs));
// .. 2 entries must be present.
assertTrue(pt.getAccessControlEntries().length == 2);
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit by apache.
the class ACLTemplateTest method testSetEntryForGroupPrincipal.
public void testSetEntryForGroupPrincipal() throws RepositoryException, NotExecutableException {
JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
Privilege[] privs = privilegesFromName(Privilege.JCR_READ);
GroupPrincipal grPrincipal = (GroupPrincipal) principalMgr.getEveryone();
// adding allow-entry must succeed
assertTrue(pt.addAccessControlEntry(grPrincipal, privs));
// adding deny-entry must succeed
pt.addEntry(grPrincipal, privs, false, null);
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class PrincipalProviderDeepNestingTest method testGetPrincipalDynamicGroup.
@Override
@Test
public void testGetPrincipalDynamicGroup() throws Exception {
for (ExternalIdentityRef ref : idp.getUser(USER_ID).getDeclaredGroups()) {
String princName = idp.getIdentity(ref).getPrincipalName();
Principal principal = principalProvider.getPrincipal(princName);
assertNotNull(principal);
assertTrue(principal instanceof GroupPrincipal);
}
}
Aggregations