Search in sources :

Example 31 with SyncResult

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

the class DefaultSyncContextTest method testSyncByForeignUserId.

@Test
public void testSyncByForeignUserId() throws Exception {
    SyncResult result = syncCtx.sync(getTestUser().getID());
    assertEquals(SyncResult.Status.FOREIGN, result.getStatus());
    SyncedIdentity si = result.getIdentity();
    assertNotNull(si);
    assertNull(si.getExternalIdRef());
    assertFalse(si.isGroup());
}
Also used : 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 32 with SyncResult

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

the class DefaultSyncContextTest method testSyncDisabledUserById.

@Test
public void testSyncDisabledUserById() throws Exception {
    // configure to disable missing users
    syncConfig.user().setDisableMissing(true);
    // mark a regular repo user as external user from the test IDP
    User u = userManager.createUser("test" + UUID.randomUUID(), null);
    String userId = u.getID();
    setExternalID(u, idp.getName());
    // test sync with 'keepmissing' = true
    syncCtx.setKeepMissing(true);
    SyncResult result = syncCtx.sync(userId);
    assertEquals(SyncResult.Status.MISSING, result.getStatus());
    assertNotNull(userManager.getAuthorizable(userId));
    // test sync with 'keepmissing' = false
    syncCtx.setKeepMissing(false);
    result = syncCtx.sync(userId);
    assertEquals(SyncResult.Status.DISABLE, result.getStatus());
    Authorizable authorizable = userManager.getAuthorizable(userId);
    assertNotNull(authorizable);
    assertTrue(((User) authorizable).isDisabled());
    // add external user back
    addIDPUser(userId);
    result = syncCtx.sync(userId);
    assertEquals(SyncResult.Status.ENABLE, result.getStatus());
    assertNotNull(userManager.getAuthorizable(userId));
    assertFalse(((User) authorizable).isDisabled());
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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 33 with SyncResult

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

the class DefaultSyncContextTest method testSyncForeignExternalGroup.

@Test
public void testSyncForeignExternalGroup() throws Exception {
    ExternalIdentity foreign = new TestIdentityProvider.ForeignExternalGroup();
    SyncResult res = syncCtx.sync(foreign);
    assertNotNull(res);
    assertSame(SyncResult.Status.FOREIGN, res.getStatus());
    // expect {@code SyncedIdentity} in accordance with {@code sync(String userId)},
    // where the authorizable is found to be linked to a different IDP.
    SyncedIdentity si = res.getIdentity();
    assertNotNull(si);
    assertEquals(foreign.getId(), si.getId());
    ExternalIdentityRef ref = si.getExternalIdRef();
    assertNotNull(ref);
    assertEquals(foreign.getExternalId(), ref);
    assertTrue(si.isGroup());
    assertEquals(-1, si.lastSynced());
    assertFalse(root.hasPendingChanges());
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) 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 34 with SyncResult

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

the class DefaultSyncContextTest method testSyncGroupById.

@Test
public void testSyncGroupById() throws Exception {
    ExternalIdentity externalId = idp.listGroups().next();
    // no initial sync -> sync-by-id doesn't succeed
    SyncResult result = syncCtx.sync(externalId.getId());
    assertEquals(SyncResult.Status.NO_SUCH_AUTHORIZABLE, result.getStatus());
    // force sync
    syncCtx.sync(externalId);
    // try again
    syncCtx.setForceGroupSync(true);
    result = syncCtx.sync(externalId.getId());
    assertEquals(SyncResult.Status.UPDATE, result.getStatus());
}
Also used : ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) 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 35 with SyncResult

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

the class DefaultSyncContextTest method testSyncExternalGroup.

@Test
public void testSyncExternalGroup() throws Exception {
    ExternalGroup gr = idp.listGroups().next();
    assertNotNull(gr);
    SyncResult result = syncCtx.sync(gr);
    assertEquals(SyncResult.Status.ADD, result.getStatus());
    result = syncCtx.sync(gr);
    assertEquals(SyncResult.Status.NOP, result.getStatus());
    syncCtx.setForceGroupSync(true);
    result = syncCtx.sync(gr);
    assertEquals(SyncResult.Status.UPDATE, result.getStatus());
}
Also used : ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) 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