Search in sources :

Example 1 with GroupPrincipal

use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.

the class AbstractPrincipalProviderTest method testGroupPrincipal.

@Test
public void testGroupPrincipal() throws Exception {
    Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName());
    assertNotNull(principal);
    assertTrue(principal instanceof GroupPrincipal);
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) SystemUserPrincipal(org.apache.jackrabbit.oak.spi.security.principal.SystemUserPrincipal) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with GroupPrincipal

use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.

the class PrincipalProviderImplTest method testEveryoneMembers.

@Test
public void testEveryoneMembers() throws Exception {
    Principal everyone = principalProvider.getPrincipal(EveryonePrincipal.NAME);
    assertTrue(everyone instanceof EveryonePrincipal);
    Group everyoneGroup = null;
    try {
        UserManager userMgr = getUserManager(root);
        everyoneGroup = userMgr.createGroup(EveryonePrincipal.NAME);
        root.commit();
        Principal ep = principalProvider.getPrincipal(EveryonePrincipal.NAME);
        Set<? extends Principal> everyoneMembers = ImmutableSet.copyOf(Collections.list(((GroupPrincipal) ep).members()));
        Iterator<? extends Principal> all = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
        while (all.hasNext()) {
            Principal p = all.next();
            if (everyone.equals(p)) {
                assertFalse(everyoneMembers.contains(p));
            } else {
                assertTrue(everyoneMembers.contains(p));
            }
        }
    } finally {
        if (everyoneGroup != null) {
            everyoneGroup.remove();
            root.commit();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test)

Example 3 with GroupPrincipal

use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.

the class UserPrincipalProviderTest method testGroupMembers.

@Test
public void testGroupMembers() throws Exception {
    Group group = getUserManager(root).createGroup("testGroup" + UUID.randomUUID());
    group.addMember(getTestUser());
    root.commit();
    try {
        Principal principal = principalProvider.getPrincipal(group.getPrincipal().getName());
        assertTrue(principal instanceof GroupPrincipal);
        boolean found = false;
        Enumeration<? extends Principal> members = ((GroupPrincipal) principal).members();
        while (members.hasMoreElements() && !found) {
            found = members.nextElement().equals(getTestUser().getPrincipal());
        }
        assertTrue(found);
    } finally {
        group.remove();
        root.commit();
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest)

Example 4 with GroupPrincipal

use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.

the class UserPrincipalProviderWithCacheTest method testGroupPrincipalNameEscape.

@Test
public void testGroupPrincipalNameEscape() throws Exception {
    String gId = null;
    try {
        Principal groupPrincipal = new PrincipalImpl(groupId + ",,%,%%");
        Group gr = getUserManager(root).createGroup(groupPrincipal);
        gId = gr.getID();
        gr.addMember(getTestUser());
        root.commit();
        systemRoot.refresh();
        PrincipalProvider pp = createPrincipalProvider(systemRoot);
        Set<? extends Principal> principals = pp.getPrincipals(userId);
        assertTrue(principals.contains(groupPrincipal));
        principals = pp.getPrincipals(userId);
        assertTrue(principals.contains(groupPrincipal));
    } finally {
        root.refresh();
        if (gId != null) {
            getUserManager(root).getAuthorizable(gId).remove();
            root.commit();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) PrincipalProvider(org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest) Test(org.junit.Test)

Example 5 with GroupPrincipal

use of org.apache.jackrabbit.api.security.principal.GroupPrincipal 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 = ((GroupPrincipal) p).members();
                while (en.hasMoreElements()) {
                    Principal memb = en.nextElement();
                    assertTrue(principalMgr.hasPrincipal(memb.getName()));
                }
            }
        }
    } finally {
        if (gr != null) {
            gr.remove();
            superuser.save();
        }
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Aggregations

GroupPrincipal (org.apache.jackrabbit.api.security.principal.GroupPrincipal)33 Principal (java.security.Principal)25 Test (org.junit.Test)23 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)12 Group (org.apache.jackrabbit.api.security.user.Group)9 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)8 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)6 AbstractPrincipalProviderTest (org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest)6 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)4 AdminPrincipal (org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)3 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)3 PrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider)3 AbstractJCRTest (org.apache.jackrabbit.test.AbstractJCRTest)3 Privilege (javax.jcr.security.Privilege)2 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)2 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)2 User (org.apache.jackrabbit.api.security.user.User)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2