Search in sources :

Example 46 with ExternalUser

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

the class LdapProviderTest method testGetUserProperties.

@Test
public void testGetUserProperties() throws Exception {
    ExternalUser user = idp.getUser(TEST_USER1_UID);
    assertNotNull("User 1 must exist", user);
    Map<String, ?> properties = user.getProperties();
    assertThat((Map<String, Collection<String>>) properties, Matchers.<String, Collection<String>>hasEntry(Matchers.equalTo("objectclass"), Matchers.containsInAnyOrder("inetOrgPerson", "top", "person", "organizationalPerson")));
    assertThat(properties, Matchers.<String, Object>hasEntry("uid", "hhornblo"));
    assertThat(properties, Matchers.<String, Object>hasEntry("givenname", "Horatio"));
    assertThat(properties, Matchers.<String, Object>hasEntry("description", "Capt. Horatio Hornblower, R.N"));
    assertThat(properties, Matchers.<String, Object>hasEntry("sn", "Hornblower"));
    assertThat(properties, Matchers.not(Matchers.<String, Object>hasEntry("mail", "hhornblo@royalnavy.mod.uk")));
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Collection(java.util.Collection) Test(org.junit.Test)

Example 47 with ExternalUser

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

the class LdapProviderTest method testSplitDNIntermediatePath.

@Test
public void testSplitDNIntermediatePath() throws Exception {
    providerConfig.getUserConfig().setMakeDnPath(true);
    ExternalUser user = idp.getUser(TEST_USER1_UID);
    assertNotNull("User 1 must exist", user);
    assertEquals("Intermediate path must be the split dn", TEST_USER1_PATH, user.getIntermediatePath());
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Test(org.junit.Test)

Example 48 with ExternalUser

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

the class DefaultSyncContextTest method testSyncPropertiesRemapped.

@Test
public void testSyncPropertiesRemapped() 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("a/" + propName, propName);
    }
    syncCtx.syncProperties(externalUser, a, mapping);
    for (String propName : extProps.keySet()) {
        String relPath = "a/" + propName;
        assertTrue(a.hasProperty(relPath));
        Object obj = extProps.get(propName);
        Value[] vs = a.getProperty(relPath);
        if (vs.length == 1) {
            assertEquals(syncCtx.createValue(obj), a.getProperty(relPath)[0]);
        } else {
            Value[] expected = (obj instanceof Collection) ? syncCtx.createValues((Collection) obj) : syncCtx.createValues(Arrays.asList((Object[]) obj));
            assertArrayEquals(expected, a.getProperty(relPath));
        }
    }
}
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 49 with ExternalUser

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

the class DefaultSyncContextTest method testSyncPropertiesEmptyMap.

@Test
public void testSyncPropertiesEmptyMap() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER);
    Authorizable a = syncCtx.createUser(externalUser);
    syncCtx.syncProperties(externalUser, a, ImmutableMap.<String, String>of());
    for (String propName : externalUser.getProperties().keySet()) {
        assertFalse(a.hasProperty(propName));
    }
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 50 with ExternalUser

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

the class DynamicSyncContextTest method testSyncMembershipWithNesting.

@Test
public void testSyncMembershipWithNesting() throws Exception {
    long nesting = 1;
    syncConfig.user().setMembershipNestingDepth(nesting);
    ExternalUser externalUser = idp.getUser(USER_ID);
    sync(externalUser, SyncResult.Status.ADD);
    Authorizable a = userManager.getAuthorizable(externalUser.getId());
    assertDynamicMembership(a, externalUser, nesting);
    // verify that the membership is always reflected in the rep:externalPrincipalNames property
    // 1. membership nesting  = -1
    nesting = -1;
    syncContext.syncMembership(externalUser, a, nesting);
    assertDynamicMembership(a, externalUser, nesting);
    // 2. membership nesting is > 0
    nesting = Long.MAX_VALUE;
    syncContext.syncMembership(externalUser, a, nesting);
    assertDynamicMembership(a, externalUser, nesting);
}
Also used : ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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