Search in sources :

Example 36 with ExternalUser

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.

the class DynamicSyncContextTest method testSyncExternalUser.

@Test
public void testSyncExternalUser() throws Exception {
    ExternalUser externalUser = idp.getUser(USER_ID);
    sync(externalUser, SyncResult.Status.ADD);
    assertNotNull(userManager.getAuthorizable(USER_ID));
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 37 with ExternalUser

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.

the class DefaultSyncContext method sync.

/**
     * {@inheritDoc}
     */
@Nonnull
@Override
public SyncResult sync(@Nonnull String id) throws SyncException {
    try {
        DebugTimer timer = new DebugTimer();
        DefaultSyncResultImpl ret;
        // find authorizable
        Authorizable auth = userManager.getAuthorizable(id);
        if (auth == null) {
            return new DefaultSyncResultImpl(new DefaultSyncedIdentity(id, null, false, -1), SyncResult.Status.NO_SUCH_AUTHORIZABLE);
        }
        // check if we need to deal with this authorizable
        ExternalIdentityRef ref = getIdentityRef(auth);
        if (ref == null || !isSameIDP(ref)) {
            return new DefaultSyncResultImpl(new DefaultSyncedIdentity(id, ref, auth.isGroup(), -1), SyncResult.Status.FOREIGN);
        }
        if (auth.isGroup()) {
            ExternalGroup external = idp.getGroup(id);
            timer.mark("retrieve");
            if (external == null) {
                ret = handleMissingIdentity(id, auth, timer);
            } else {
                ret = syncGroup(external, (Group) auth);
                timer.mark("sync");
            }
        } else {
            ExternalUser external = idp.getUser(id);
            timer.mark("retrieve");
            if (external == null) {
                ret = handleMissingIdentity(id, auth, timer);
            } else {
                ret = syncUser(external, (User) auth);
                timer.mark("sync");
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("sync({}) -> {} {}", id, ref.getString(), timer.getString());
        }
        return ret;
    } catch (RepositoryException e) {
        throw new SyncException(e);
    } catch (ExternalIdentityException e) {
        throw new SyncException(e);
    }
}
Also used : DebugTimer(org.apache.jackrabbit.oak.commons.DebugTimer) Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException) SyncException(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncException) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) Nonnull(javax.annotation.Nonnull)

Example 38 with ExternalUser

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.

the class ExternalGroupPrincipalProviderTest method testFindPrincipalsContainingPercentSign.

@Test
public void testFindPrincipalsContainingPercentSign() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_WILDCARD_USER);
    sync(externalUser);
    Set<? extends Principal> expected = ImmutableSet.of(new PrincipalImpl("g%r%"));
    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 39 with ExternalUser

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.

the class ExternalGroupPrincipalTest method testIsMember.

@Test
public void testIsMember() throws Exception {
    ExternalUser externalUser = idp.getUser(USER_ID);
    java.security.acl.Group principal = getGroupPrincipal(externalUser.getDeclaredGroups().iterator().next());
    assertTrue(principal.isMember(new PrincipalImpl(externalUser.getPrincipalName())));
    assertTrue(principal.isMember(getUserManager(root).getAuthorizable(USER_ID).getPrincipal()));
}
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 40 with ExternalUser

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.

the class ExternalLoginModuleFactoryTest method testSyncCreateUser.

//~-------------------------------------------------------------< tests >---
@Test
public void testSyncCreateUser() throws Exception {
    setUpJaasFactoryWithInjection();
    UserManager userManager = getUserManager(root);
    ContentSession cs = null;
    try {
        assertNull(userManager.getAuthorizable(USER_ID));
        cs = login(new SimpleCredentials(USER_ID, new char[0]));
        root.refresh();
        Authorizable a = userManager.getAuthorizable(USER_ID);
        assertNotNull(a);
        ExternalUser user = idp.getUser(USER_ID);
        for (String prop : user.getProperties().keySet()) {
            assertTrue(a.hasProperty(prop));
        }
        assertEquals(TEST_CONSTANT_PROPERTY_VALUE, a.getProperty(TEST_CONSTANT_PROPERTY_NAME)[0].getString());
    } finally {
        if (cs != null) {
            cs.close();
        }
        options.clear();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Test(org.junit.Test)

Aggregations

ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)63 Test (org.junit.Test)56 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)28 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)23 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)19 User (org.apache.jackrabbit.api.security.user.User)12 SimpleCredentials (javax.jcr.SimpleCredentials)10 Group (org.apache.jackrabbit.api.security.user.Group)8 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)8 HashMap (java.util.HashMap)7 ExternalIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity)6 SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)6 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)6 Tree (org.apache.jackrabbit.oak.api.Tree)5 Principal (java.security.Principal)4 Nonnull (javax.annotation.Nonnull)4 Value (javax.jcr.Value)4 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 LdapIdentityProvider (org.apache.jackrabbit.oak.security.authentication.ldap.impl.LdapIdentityProvider)4 Collection (java.util.Collection)3