Search in sources :

Example 16 with SyncResult

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

the class DefaultSyncContextTest method testSyncRemovedGroupById.

@Test
public void testSyncRemovedGroupById() throws Exception {
    // mark a regular repo user as external user from the test IDP
    Group gr = createTestGroup();
    String groupId = gr.getID();
    setExternalID(gr, idp.getName());
    // test sync with 'keepmissing' = true
    syncCtx.setKeepMissing(true);
    SyncResult result = syncCtx.sync(groupId);
    assertEquals(SyncResult.Status.MISSING, result.getStatus());
    assertNotNull(userManager.getAuthorizable(groupId));
    // test sync with 'keepmissing' = false
    syncCtx.setKeepMissing(false);
    result = syncCtx.sync(groupId);
    assertEquals(SyncResult.Status.DELETE, result.getStatus());
    assertNull(userManager.getAuthorizable(groupId));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) 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)

Example 17 with SyncResult

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

the class DefaultSyncHandlerTest method sync.

private void sync(@Nonnull String id, boolean isGroup) throws Exception {
    SyncContext ctx = syncHandler.createContext(idp, userManager, getValueFactory());
    ExternalIdentity exIdentity = (isGroup) ? idp.getGroup(id) : idp.getUser(id);
    assertNotNull(exIdentity);
    SyncResult res = ctx.sync(exIdentity);
    assertSame(SyncResult.Status.ADD, res.getStatus());
    root.commit();
}
Also used : ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) SyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncContext) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) SyncResult(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)

Example 18 with SyncResult

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

the class DefaultSyncContextTest method testSyncAutoMembership.

@Test
public void testSyncAutoMembership() throws Exception {
    Group gr = createTestGroup();
    syncConfig.user().setAutoMembership(gr.getID());
    SyncResult result = syncCtx.sync(idp.listUsers().next());
    assertEquals(SyncResult.Status.ADD, result.getStatus());
    Authorizable a = userManager.getAuthorizable(result.getIdentity().getId());
    assertTrue(gr.isDeclaredMember(a));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) 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 19 with SyncResult

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

the class DefaultSyncContextTest method testSyncUserById.

@Test
public void testSyncUserById() throws Exception {
    ExternalIdentity externalId = idp.listUsers().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.setForceUserSync(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 20 with SyncResult

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

the class DefaultSyncContextTest method testSyncDoesNotEnableUsers.

@Test
public void testSyncDoesNotEnableUsers() throws Exception {
    // configure to remove missing users, check that sync does not mess with disabled status
    syncConfig.user().setDisableMissing(false);
    // test sync with 'keepmissing' = false
    syncCtx.setKeepMissing(false);
    ExternalUser user = idp.listUsers().next();
    assertNotNull(user);
    SyncResult result = syncCtx.sync(user);
    assertEquals(SyncResult.Status.ADD, result.getStatus());
    Authorizable authorizable = userManager.getAuthorizable(user.getId());
    assertTrue(authorizable instanceof User);
    User u = (User) authorizable;
    // disable user
    u.disable("disabled locally");
    root.commit();
    // sync
    syncCtx.setForceUserSync(true);
    result = syncCtx.sync(user.getId());
    assertEquals(SyncResult.Status.UPDATE, result.getStatus());
    authorizable = userManager.getAuthorizable(user.getId());
    assertNotNull(authorizable);
    assertTrue(authorizable instanceof User);
    assertTrue(((User) authorizable).isDisabled());
}
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) 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)

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