Search in sources :

Example 16 with GroupPrincipal

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);
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 17 with GroupPrincipal

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);
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 18 with GroupPrincipal

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);
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 19 with GroupPrincipal

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);
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 20 with GroupPrincipal

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);
    }
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Test(org.junit.Test)

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