@Test public void testGetPrincipal() throws Exception { assertEquals(EveryonePrincipal.getInstance(), everyoneGroup.getPrincipal()); assertEquals(EveryonePrincipal.NAME, everyoneGroup.getPrincipal().getName()); assertTrue(everyoneGroup.getPrincipal() instanceof ItemBasedPrincipal); }
protected void createPrincipals() throws Exception { if (principals.isEmpty()) { for (int i = 0; i < 10; i++) { Group gr = getUserManager(root).createGroup("testGroup" + i); principals.add(gr.getPrincipal()); } root.commit(); } }
@Test public void testUserMemberOfContainsEveryone() throws Exception { User testUser = getTestUser(superuser); boolean memberOfEveryone = false; Iterator<Group> groups = testUser.memberOf(); while (groups.hasNext() && !memberOfEveryone) { Group g = groups.next(); memberOfEveryone = (EveryonePrincipal.NAME.equals(g.getPrincipal().getName())); } assertTrue(memberOfEveryone); } }
@Test public void testGetGroupMembershipGroupPrincipal2() throws Exception { Set<Principal> grPrincipals = principalProvider.getMembershipPrincipals(testGroup2.getPrincipal()); assertNotNull(grPrincipals); assertEquals(2, grPrincipals.size()); assertTrue(grPrincipals.contains(testGroup.getPrincipal())); assertTrue(grPrincipals.contains(EveryonePrincipal.getInstance())); }
@Test public void testGetGroupMembershipLocalGroupPrincipal() throws Exception { Group gr = createTestGroup(); Set<? extends Principal> principals = principalProvider.getMembershipPrincipals(gr.getPrincipal()); assertTrue(principals.isEmpty()); // same if the principal is not marked as 'GroupPrincipal' and not tree-based-principal principals = principalProvider.getMembershipPrincipals(new PrincipalImpl(gr.getPrincipal().getName())); assertTrue(principals.isEmpty()); }
public void testGroupNode() throws RepositoryException { Node node = getAuthorizableNode(testGroup); String idPropertyName = null; // EXERCISE assertEquals(testGroup.getID(), node.getProperty(idPropertyName).getString()); String principalPropertyName = null; // EXERCISE assertEquals(testGroup.getPrincipal().getName(), node.getProperty(principalPropertyName).getString()); String expectedNodeTypeName = null; // EXERCISE assertEquals(expectedNodeTypeName, node.getPrimaryNodeType().getName()); }
@Test public void testGroupPrincipal() throws Exception { Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName()); assertNotNull(principal); assertTrue(principal instanceof GroupPrincipal); }
@Test public void testGetGroupMembership() throws Exception { Set<Principal> grPrincipals = principalProvider.getMembershipPrincipals(userPrincipal); assertEquals(2, grPrincipals.size()); assertTrue(grPrincipals.contains(EveryonePrincipal.getInstance())); assertTrue(grPrincipals.contains(testGroup.getPrincipal())); }
@Test public void testGetPrincipalLocalGroup() throws Exception { Group gr = createTestGroup(); assertNull(principalProvider.getPrincipal(gr.getPrincipal().getName())); }
Principal getTestGroupPrincipal() throws Exception { UserManager uMgr = getUserManager(root); Group g = uMgr.getAuthorizable(TEST_GROUP_ID, Group.class); if (g == null) { g = uMgr.createGroup(TEST_GROUP_ID); root.commit(); } return g.getPrincipal(); }
@Override protected void setUp() throws Exception { super.setUp(); acMgr = superuser.getAccessControlManager(); testPrincipal = ExerciseUtility.createTestGroup(((JackrabbitSession) superuser).getUserManager()).getPrincipal(); superuser.save(); acl = AccessControlUtils.getAccessControlList(superuser, testRoot); if (acl == null) { throw new NotExecutableException(); } }
@Test public void testFindPrincipalsByTypeGroup() throws Exception { Iterator<? extends Principal> res = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_GROUP); assertFalse(Iterators.contains(res, userAutoMembershipGroup.getPrincipal())); assertFalse(Iterators.contains(res, groupAutoMembershipGroup.getPrincipal())); assertFalse(Iterators.contains(res, new PrincipalImpl(NON_EXISTING_GROUP_ID))); } }
@Override protected void setUp() throws Exception { super.setUp(); acMgr = superuser.getAccessControlManager(); testPrincipal = ExerciseUtility.createTestGroup(((JackrabbitSession) superuser).getUserManager()).getPrincipal(); superuser.save(); acl = AccessControlUtils.getAccessControlList(superuser, testRoot); if (acl == null) { throw new NotExecutableException(); } testPrivileges = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_WRITE); }
@Test public void testGetAutoMembershipPrincipal() throws Exception { assertNull(principalProvider.getPrincipal(userAutoMembershipGroup.getPrincipal().getName())); assertNull(principalProvider.getPrincipal(groupAutoMembershipGroup.getPrincipal().getName())); assertNull(principalProvider.getPrincipal(USER_AUTO_MEMBERSHIP_GROUP_PRINCIPAL_NAME)); assertNull(principalProvider.getPrincipal(USER_AUTO_MEMBERSHIP_GROUP_ID)); assertNull(principalProvider.getPrincipal(GROUP_AUTO_MEMBERSHIP_GROUP_PRINCIPAL_NAME)); assertNull(principalProvider.getPrincipal(GROUP_AUTO_MEMBERSHIP_GROUP_ID)); assertNull(principalProvider.getPrincipal(NON_EXISTING_GROUP_ID)); }
@Test public void testGrantGroupPrincipal() throws Exception { Group group = getUserManager(root).createGroup("testGroup"); try { assertFalse(impersonation.grantImpersonation(group.getPrincipal())); } finally { group.remove(); } }
@Test public void testAllowUserDenyGroup() throws Exception { /* allow READ privilege for testUser at 'path' */ allow(path, testUser.getPrincipal(), readPrivileges); /* deny READ privilege for group at 'path' */ deny(path, getTestGroup().getPrincipal(), readPrivileges); assertTrue(testSession.nodeExists(path)); }
@Test public void testAllowEveryonePathDenyGroupChildPath() throws Exception { /* allow READ privilege for everyone at 'path' */ allow(path, EveryonePrincipal.getInstance(), readPrivileges); /* deny READ privilege for group at 'childNPath' */ deny(childNPath, getTestGroup().getPrincipal(), readPrivileges); assertFalse(testSession.nodeExists(childNPath)); }
@Test public void testAllowUserPathDenyGroupChildPath() throws Exception { /* allow READ privilege for testUser at 'path' */ allow(path, testUser.getPrincipal(), readPrivileges); /* deny READ privilege for group at 'childPath' */ deny(path, getTestGroup().getPrincipal(), readPrivileges); assertTrue(testSession.nodeExists(childNPath)); }
@Test public void testDenyUserPathAllowGroupChildPath() throws Exception { /* deny READ privilege for testUser at 'path' */ deny(path, testUser.getPrincipal(), readPrivileges); /* allow READ privilege for group at 'childNPath' */ allow(path, getTestGroup().getPrincipal(), readPrivileges); assertFalse(testSession.nodeExists(childNPath)); }
@Test public void testExtractPrincipalsFromCache() throws Exception { // a) force the cache to be created PrincipalProvider pp = createPrincipalProvider(systemRoot); // set of principals that read from user + membership-provider. Set<? extends Principal> principals = pp.getPrincipals(userId); assertPrincipals(principals, EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal()); // b) retrieve principals again (this time from the cache) Set<? extends Principal> principalsAgain = pp.getPrincipals(userId); // make sure both sets are equal assertEquals(principals, principalsAgain); }