Search in sources :

Example 11 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ExternalGroupPrincipalProviderTest method testFindPrincipalsContainingUnderscore.

@Test
public void testFindPrincipalsContainingUnderscore() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_WILDCARD_USER);
    sync(externalUser);
    Set<? extends Principal> expected = ImmutableSet.of(new PrincipalImpl("_gr_u_"));
    Set<? extends Principal> res = ImmutableSet.copyOf(principalProvider.findPrincipals("_", PrincipalManager.SEARCH_TYPE_ALL));
    assertEquals(expected, res);
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 12 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ExternalGroupPrincipalProviderTest method collectExpectedPrincipals.

private void collectExpectedPrincipals(Set<Principal> grPrincipals, @Nonnull Iterable<ExternalIdentityRef> declaredGroups, long depth) throws Exception {
    if (depth <= 0) {
        return;
    }
    for (ExternalIdentityRef ref : declaredGroups) {
        ExternalIdentity ei = idp.getIdentity(ref);
        grPrincipals.add(new PrincipalImpl(ei.getPrincipalName()));
        collectExpectedPrincipals(grPrincipals, ei.getDeclaredGroups(), depth - 1);
    }
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)

Example 13 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class ExternalGroupPrincipalProviderTest method testFindPrincipalsByHintTypeGroup.

@Test
public void testFindPrincipalsByHintTypeGroup() throws Exception {
    Set<? extends Principal> expected = ImmutableSet.of(new PrincipalImpl("a"));
    Set<? extends Principal> res = ImmutableSet.copyOf(principalProvider.findPrincipals("a", PrincipalManager.SEARCH_TYPE_GROUP));
    assertEquals(expected, res);
}
Also used : PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 14 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class XPathConditionVisitor method visit.

@Override
public void visit(Condition.Impersonation condition) {
    String principalName = condition.getName();
    boolean isAdmin = false;
    try {
        Authorizable authorizable = userMgr.getAuthorizable(new PrincipalImpl(principalName));
        isAdmin = authorizable != null && !authorizable.isGroup() && ((User) authorizable).isAdmin();
    } catch (RepositoryException e) {
    // unable to retrieve authorizable
    }
    if (isAdmin) {
        statement.append('@').append(QueryUtil.escapeForQuery(JcrConstants.JCR_PRIMARYTYPE, namePathMapper)).append("='").append(QueryUtil.escapeForQuery(UserConstants.NT_REP_USER, namePathMapper)).append('\'');
    } else {
        statement.append('@').append(QueryUtil.escapeForQuery(UserConstants.REP_IMPERSONATORS, namePathMapper)).append("='").append(condition.getName()).append('\'');
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)

Example 15 with PrincipalImpl

use of org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl in project jackrabbit-oak by apache.

the class IsMemberTest method beforeSuite.

@Override
protected void beforeSuite() throws Exception {
    super.beforeSuite();
    Session s = loginAdministrative();
    try {
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        Group gr = userManager.createGroup(new PrincipalImpl(GROUP + 0), REL_TEST_PATH);
        gPaths.add(gr.getPath());
        for (int i = 1; i < GROUP_CNT; i++) {
            Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), REL_TEST_PATH);
            if (nestedGroups) {
                g.addMember(gr);
            }
            gr = g;
            gPaths.add(gr.getPath());
        }
        int cnt = 0;
        for (int i = 0; i <= numberOfUsers; i++) {
            User u = userManager.createUser(USER + i, null, new PrincipalImpl(USER + i), REL_TEST_PATH);
            uPaths.add(u.getPath());
            getRandomGroup(userManager).addMember(u);
            if (++cnt == 20000) {
                s.save();
            }
        }
    } finally {
        s.save();
        s.logout();
    }
    System.out.println("setup done");
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)96 Test (org.junit.Test)66 Principal (java.security.Principal)40 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)24 Group (org.apache.jackrabbit.api.security.user.Group)22 User (org.apache.jackrabbit.api.security.user.User)20 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)20 UserManager (org.apache.jackrabbit.api.security.user.UserManager)16 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)15 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)12 GroupPrincipal (org.apache.jackrabbit.api.security.principal.GroupPrincipal)11 Session (javax.jcr.Session)9 SimpleCredentials (javax.jcr.SimpleCredentials)7 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)6 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)6 CugPolicy (org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy)6 HashSet (java.util.HashSet)5 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)5 AuthorizationConfiguration (org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration)5 EmptyPermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.EmptyPermissionProvider)5