Search in sources :

Example 1 with ExternalIdentityRef

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

the class DefaultSyncContextTest method testSyncForeignExternalUser.

@Test
public void testSyncForeignExternalUser() throws Exception {
    ExternalIdentity foreign = new TestIdentityProvider.ForeignExternalUser();
    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);
    assertFalse(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 2 with ExternalIdentityRef

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

the class DynamicSyncContextTest method testSyncUserIdExistingGroups.

@Test
public void testSyncUserIdExistingGroups() throws Exception {
    ExternalUser externalUser = idp.getUser(USER_ID);
    DefaultSyncContext ctx = new DefaultSyncContext(syncConfig, idp, userManager, valueFactory);
    ctx.sync(externalUser);
    ctx.close();
    Authorizable user = userManager.getAuthorizable(externalUser.getId());
    for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) {
        Group gr = userManager.getAuthorizable(ref.getId(), Group.class);
        assertTrue(gr.isMember(user));
    }
    syncContext.setForceUserSync(true);
    syncContext.sync(externalUser.getId());
    Authorizable a = userManager.getAuthorizable(USER_ID);
    Tree t = r.getTree(a.getPath());
    assertFalse(t.hasProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES));
    assertSyncedMembership(userManager, a, externalUser);
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 3 with ExternalIdentityRef

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

the class DynamicSyncContextTest method testSyncExternalUserDepth1.

@Test
public void testSyncExternalUserDepth1() throws Exception {
    syncConfig.user().setMembershipNestingDepth(1);
    ExternalUser externalUser = idp.getUser(USER_ID);
    sync(externalUser, SyncResult.Status.ADD);
    Tree tree = r.getTree(userManager.getAuthorizable(USER_ID).getPath());
    PropertyState extPrincipalNames = tree.getProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES);
    assertNotNull(extPrincipalNames);
    Set<String> pNames = Sets.newHashSet(extPrincipalNames.getValue(Type.STRINGS));
    for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) {
        assertTrue(pNames.remove(idp.getIdentity(ref).getPrincipalName()));
    }
    assertTrue(pNames.isEmpty());
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 4 with ExternalIdentityRef

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

the class DefaultSyncHandlerTest method testListIdentitiesAfterSync.

@Test
public void testListIdentitiesAfterSync() throws Exception {
    sync(USER_ID, false);
    // membership-nesting is 1 => expect only 'USER_ID' plus the declared group-membership
    Set<String> expected = Sets.newHashSet(USER_ID);
    for (ExternalIdentityRef extRef : idp.getUser(USER_ID).getDeclaredGroups()) {
        expected.add(extRef.getId());
    }
    Iterator<SyncedIdentity> identities = syncHandler.listIdentities(userManager);
    while (identities.hasNext()) {
        SyncedIdentity si = identities.next();
        if (expected.contains(si.getId())) {
            expected.remove(si.getId());
            assertNotNull(si.getExternalIdRef());
        } else {
            fail("Sync handler returned unexpected identity: " + si);
        }
    }
    assertTrue(expected.isEmpty());
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) DefaultSyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity) SyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity) Test(org.junit.Test)

Example 5 with ExternalIdentityRef

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

the class DelegateeTest method testSyncForeignExternalUserSaveError.

@Test
public void testSyncForeignExternalUserSaveError() throws Exception {
    Root r = preventRootCommit(delegatee);
    ;
    String[] result = delegatee.syncExternalUsers(new String[] { new ExternalIdentityRef(TestIdentityProvider.ID_TEST_USER, foreignIDP.getName()).getString() });
    assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "for");
    assertFalse(r.hasPendingChanges());
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) Test(org.junit.Test)

Aggregations

ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)64 Test (org.junit.Test)47 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)23 ExternalIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity)18 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)15 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)14 Group (org.apache.jackrabbit.api.security.user.Group)11 User (org.apache.jackrabbit.api.security.user.User)10 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)7 SyncedIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity)6 Nonnull (javax.annotation.Nonnull)5 DebugTimer (org.apache.jackrabbit.oak.commons.DebugTimer)5 ExternalIdentityException (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException)5 SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)5 Principal (java.security.Principal)4 HashMap (java.util.HashMap)4 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)4 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 Root (org.apache.jackrabbit.oak.api.Root)4 DefaultSyncedIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity)4