Search in sources :

Example 1 with ExternalUser

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

the class DefaultSyncContextTest method testSyncProperties.

@Test
public void testSyncProperties() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    Authorizable a = syncCtx.createUser(externalUser);
    // create exact mapping
    Map<String, String> mapping = new HashMap();
    Map<String, ?> extProps = externalUser.getProperties();
    for (String propName : extProps.keySet()) {
        mapping.put(propName, propName);
    }
    syncCtx.syncProperties(externalUser, a, mapping);
    for (String propName : extProps.keySet()) {
        assertTrue(a.hasProperty(propName));
        Object obj = extProps.get(propName);
        Value[] vs = a.getProperty(propName);
        if (vs.length == 1) {
            assertEquals(syncCtx.createValue(obj), a.getProperty(propName)[0]);
        } else {
            Value[] expected = (obj instanceof Collection) ? syncCtx.createValues((Collection) obj) : syncCtx.createValues(Arrays.asList((Object[]) obj));
            assertArrayEquals(expected, a.getProperty(propName));
        }
    }
}
Also used : HashMap(java.util.HashMap) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Collection(java.util.Collection) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 2 with ExternalUser

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

the class DefaultSyncContextTest method testSyncPropertiesMappingConstants.

@Test
public void testSyncPropertiesMappingConstants() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    sync(externalUser);
    Authorizable a = userManager.getAuthorizable(externalUser.getId());
    // create mapping that doesn't match to names in the external-properties
    // -> previously synced properties must be removed
    Map<String, String> mapping = new HashMap();
    Map<String, ?> extProps = externalUser.getProperties();
    for (String propName : extProps.keySet()) {
        mapping.put(propName, "\"any\"");
    }
    syncCtx.syncProperties(externalUser, a, mapping);
    Value anyValue = valueFactory.createValue("any");
    for (String propName : extProps.keySet()) {
        assertTrue(a.hasProperty(propName));
        assertEquals(anyValue, a.getProperty(propName)[0]);
    }
}
Also used : HashMap(java.util.HashMap) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Value(javax.jcr.Value) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 3 with ExternalUser

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser 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 4 with ExternalUser

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser 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 5 with ExternalUser

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

the class DynamicSyncContextTest method testSyncExternalUserExistingGroups.

@Test
public void testSyncExternalUserExistingGroups() throws Exception {
    syncConfig.user().setMembershipNestingDepth(1);
    ExternalUser externalUser = idp.getUser(USER_ID);
    DefaultSyncContext ctx = new DefaultSyncContext(syncConfig, idp, userManager, valueFactory);
    ctx.sync(externalUser);
    ctx.close();
    Authorizable a = userManager.getAuthorizable(USER_ID);
    assertSyncedMembership(userManager, a, externalUser);
    syncContext.setForceUserSync(true);
    syncConfig.user().setMembershipExpirationTime(-1);
    syncContext.sync(externalUser);
    Tree t = r.getTree(a.getPath());
    assertFalse(t.hasProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES));
    assertSyncedMembership(userManager, a, externalUser);
}
Also used : DefaultSyncContext(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncContext) 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)

Aggregations

ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)63 Test (org.junit.Test)56 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)28 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)23 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)19 User (org.apache.jackrabbit.api.security.user.User)12 SimpleCredentials (javax.jcr.SimpleCredentials)10 Group (org.apache.jackrabbit.api.security.user.Group)8 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)8 HashMap (java.util.HashMap)7 ExternalIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity)6 SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)6 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)6 Tree (org.apache.jackrabbit.oak.api.Tree)5 Principal (java.security.Principal)4 Nonnull (javax.annotation.Nonnull)4 Value (javax.jcr.Value)4 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 LdapIdentityProvider (org.apache.jackrabbit.oak.security.authentication.ldap.impl.LdapIdentityProvider)4 Collection (java.util.Collection)3