Search in sources :

Example 1 with SyncResult

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

the class Delegatee method syncUser.

@Nonnull
private List<SyncResult> syncUser(@Nonnull ExternalIdentity id, @Nonnull List<SyncResult> results, @Nonnull List<String> list) {
    try {
        SyncResult r = context.sync(id);
        if (r.getIdentity() == null) {
            r = new DefaultSyncResultImpl(new DefaultSyncedIdentity(id.getId(), id.getExternalId(), false, -1), SyncResult.Status.NO_SUCH_IDENTITY);
            log.warn("sync failed. {}", r.getIdentity());
        } else {
            log.info("synced {}", r.getIdentity());
        }
        results.add(r);
    } catch (SyncException e) {
        log.error(ERROR_SYNC_USER, id, e);
        results.add(new ErrorSyncResult(id.getExternalId(), e));
    }
    return commit(list, results, batchSize);
}
Also used : DefaultSyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity) DefaultSyncResultImpl(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncResultImpl) SyncException(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncException) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) Nonnull(javax.annotation.Nonnull)

Example 2 with SyncResult

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

the class DefaultSyncContextTest method testSyncAutoMembershipListsNonExistingGroup.

@Test
public void testSyncAutoMembershipListsNonExistingGroup() throws Exception {
    syncConfig.user().setAutoMembership("nonExistingGroup");
    SyncResult result = syncCtx.sync(idp.listUsers().next());
    assertEquals(SyncResult.Status.ADD, result.getStatus());
}
Also used : SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 3 with SyncResult

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

the class DefaultSyncContextTest method testLostMembershipDifferentIDP.

@Test
public void testLostMembershipDifferentIDP() throws Exception {
    // create a group in the repository which is marked as being external
    // and associated with another IPD.
    Group gr = createTestGroup();
    setExternalID(gr, "differentIDP");
    // sync an external user from the IDP into the repo and make it member
    // of the test group
    SyncResult result = syncCtx.sync(idp.listUsers().next());
    User user = userManager.getAuthorizable(result.getIdentity().getId(), User.class);
    gr.addMember(user);
    root.commit();
    // enforce synchronization of the user and it's group membership
    syncCtx.setForceUserSync(true);
    syncConfig.user().setMembershipExpirationTime(-1);
    syncConfig.user().setMembershipNestingDepth(1);
    assertEquals(SyncResult.Status.UPDATE, syncCtx.sync(user.getID()).getStatus());
    // since the group is not associated with the test-IDP the group-membership
    // must NOT be modified during the sync.
    assertTrue(gr.isDeclaredMember(user));
}
Also used : 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) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 4 with SyncResult

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

the class DefaultSyncContextTest method testSyncExternalToExistingLocalUser.

@Test
public void testSyncExternalToExistingLocalUser() throws Exception {
    ExternalUser external = idp.listUsers().next();
    syncCtx.sync(external);
    User u = userManager.getAuthorizable(external.getId(), User.class);
    u.removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID);
    SyncResult result = syncCtx.sync(external);
    assertEquals(SyncResult.Status.FOREIGN, result.getStatus());
    SyncedIdentity si = result.getIdentity();
    assertNotNull(si);
    assertEquals(external.getExternalId(), si.getExternalIdRef());
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) SyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 5 with SyncResult

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

the class DefaultSyncContextTest method testSyncExternalUser.

@Test
public void testSyncExternalUser() throws Exception {
    ExternalUser user = idp.listUsers().next();
    assertNotNull(user);
    SyncResult result = syncCtx.sync(user);
    assertEquals(SyncResult.Status.ADD, result.getStatus());
    result = syncCtx.sync(user);
    assertEquals(SyncResult.Status.NOP, result.getStatus());
    syncCtx.setForceUserSync(true);
    result = syncCtx.sync(user);
    assertEquals(SyncResult.Status.UPDATE, result.getStatus());
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)46 Test (org.junit.Test)37 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)34 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)14 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)13 User (org.apache.jackrabbit.api.security.user.User)11 SyncedIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity)11 Group (org.apache.jackrabbit.api.security.user.Group)10 ExternalIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity)7 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)5 Nonnull (javax.annotation.Nonnull)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Tree (org.apache.jackrabbit.oak.api.Tree)4 SyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext)4 ArrayList (java.util.ArrayList)3 DefaultSyncContext (org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext)3 DefaultSyncedIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity)3 ExternalIdentityException (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException)2 SyncException (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncException)2