Search in sources :

Example 16 with ExternalIdentity

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

the class LdapProviderTest method testGetUnknownUserByRef.

@Test
public void testGetUnknownUserByRef() throws Exception {
    ExternalIdentityRef ref = new ExternalIdentityRef("bla=foo," + TEST_USER1_DN, IDP_NAME);
    ExternalIdentity id = idp.getIdentity(ref);
    assertNull("Unknown user must return null", id);
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) Test(org.junit.Test)

Example 17 with ExternalIdentity

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

the class LdapProviderTest method testGetGroupByRef.

@Test
public void testGetGroupByRef() throws Exception {
    ExternalIdentityRef ref = new ExternalIdentityRef(TEST_GROUP1_DN, IDP_NAME);
    ExternalIdentity id = idp.getIdentity(ref);
    assertTrue("Group instance", id instanceof ExternalGroup);
    assertEquals("Group Name", TEST_GROUP1_NAME, id.getId());
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) Test(org.junit.Test)

Example 18 with ExternalIdentity

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

the class Delegatee method syncExternalUsers.

/**
     * @see SynchronizationMBean#syncExternalUsers(String[])
     */
@Nonnull
String[] syncExternalUsers(@Nonnull String[] externalIds) {
    List<String> list = new ArrayList<String>();
    context.setForceGroupSync(true).setForceUserSync(true);
    List<SyncResult> results = new ArrayList<SyncResult>(batchSize);
    for (String externalId : externalIds) {
        ExternalIdentityRef ref = ExternalIdentityRef.fromString(externalId);
        if (!idp.getName().equals(ref.getProviderName())) {
            results.add(new DefaultSyncResultImpl(new DefaultSyncedIdentity(ref.getId(), ref, false, -1), SyncResult.Status.FOREIGN));
        } else {
            try {
                ExternalIdentity id = idp.getIdentity(ref);
                if (id != null) {
                    results = syncUser(id, results, list);
                } else {
                    results.add(new DefaultSyncResultImpl(new DefaultSyncedIdentity("", ref, false, -1), SyncResult.Status.NO_SUCH_IDENTITY));
                }
            } catch (ExternalIdentityException e) {
                log.warn("error while fetching the external identity {}", externalId, e);
                results.add(new ErrorSyncResult(ref, e));
            }
        }
    }
    commit(list, results, NO_BATCH_SIZE);
    return list.toArray(new String[list.size()]);
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ArrayList(java.util.ArrayList) DefaultSyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) DefaultSyncResultImpl(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncResultImpl) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) Nonnull(javax.annotation.Nonnull)

Example 19 with ExternalIdentity

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

the class DefaultSyncContextTest method testIsExpiredSyncedUser.

@Test
public void testIsExpiredSyncedUser() throws Exception {
    ExternalIdentity externalUser = idp.listUsers().next();
    sync(externalUser);
    Authorizable a = userManager.getAuthorizable(externalUser.getId());
    assertFalse(syncCtx.isExpired(a, syncConfig.user().getExpirationTime(), "any"));
    assertTrue(syncCtx.isExpired(a, -1, "any"));
    // create a ctx with a newer 'now'
    DefaultSyncContext ctx = new DefaultSyncContext(syncConfig, idp, userManager, valueFactory);
    long expTime = ctx.now - syncCtx.now - 1;
    assertTrue(ctx.isExpired(a, expTime, "any"));
    // remove last-sync property
    a.removeProperty(DefaultSyncContext.REP_LAST_SYNCED);
    assertTrue(syncCtx.isExpired(a, syncConfig.user().getExpirationTime(), "any"));
}
Also used : ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 20 with ExternalIdentity

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

the class DefaultSyncContextTest method testGetIdentityRefSyncUser.

@Test
public void testGetIdentityRefSyncUser() throws Exception {
    ExternalIdentity externalUser = idp.listUsers().next();
    sync(externalUser);
    ExternalIdentityRef ref = DefaultSyncContext.getIdentityRef(userManager.getAuthorizable(externalUser.getId()));
    assertNotNull(ref);
    assertEquals(externalUser.getExternalId(), ref);
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

ExternalIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity)40 Test (org.junit.Test)34 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)20 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)18 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)9 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)7 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)7 SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)7 UserManager (org.apache.jackrabbit.api.security.user.UserManager)5 SyncedIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity)4 Group (org.apache.jackrabbit.api.security.user.Group)3 HashMap (java.util.HashMap)2 ExternalIdentityException (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException)2 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)2 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 User (org.apache.jackrabbit.api.security.user.User)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 DebugTimer (org.apache.jackrabbit.oak.commons.DebugTimer)1