Search in sources :

Example 16 with ExternalIdentityRef

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

the class SyncMBeanImplTest method testSyncExternalUserThrowingHandler.

@Test
public void testSyncExternalUserThrowingHandler() throws Exception {
    ExternalIdentityRef ref = new ExternalIdentityRef(TestIdentityProvider.ID_TEST_USER, idp.getName());
    String[] result = createThrowingSyncMBean(false).syncExternalUsers(new String[] { ref.getString() });
    assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "ERR");
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) Test(org.junit.Test)

Example 17 with ExternalIdentityRef

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

the class SyncMBeanImplTest method testSyncExternalUsersLastSyncedProperty.

@Test
public void testSyncExternalUsersLastSyncedProperty() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER);
    String[] externalId = new String[] { externalUser.getExternalId().getString() };
    syncMBean.syncExternalUsers(externalId);
    UserManager userManager = getUserManager();
    User testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    long lastSynced = testUser.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        Group gr = userManager.getAuthorizable(groupRef.getId(), Group.class);
        long groupLastSynced = gr.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
        assertTrue(lastSynced == groupLastSynced);
    }
    while (System.currentTimeMillis() <= lastSynced) {
    // wait for system time to move
    }
    // default value for forceGroup sync is defined to be 'true' => verify result
    syncMBean.syncExternalUsers(externalId);
    userManager = getUserManager();
    testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    long lastSynced2 = testUser.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
    assertTrue("lastSynced: " + lastSynced + ", lastSynced2: " + lastSynced2, lastSynced < lastSynced2);
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        Group gr = userManager.getAuthorizable(groupRef.getId(), Group.class);
        long groupLastSynced = gr.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
        assertTrue(lastSynced2 == groupLastSynced);
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 18 with ExternalIdentityRef

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

the class SyncMBeanImplTest method testInitialSyncExternalUsersNoNesting.

@Test
public void testInitialSyncExternalUsersNoNesting() throws Exception {
    syncConfig.user().setMembershipNestingDepth(-1);
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER);
    String[] externalId = new String[] { externalUser.getExternalId().getString() };
    String[] result = syncMBean.syncExternalUsers(externalId);
    assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "add");
    UserManager userManager = getUserManager();
    User testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    assertNotNull(testUser);
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        assertNull(userManager.getAuthorizable(groupRef.getId()));
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 19 with ExternalIdentityRef

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

the class SyncMBeanImplTest method testInitialSyncExternalUsers.

@Test
public void testInitialSyncExternalUsers() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER);
    String[] externalId = new String[] { externalUser.getExternalId().getString() };
    String[] result = syncMBean.syncExternalUsers(externalId);
    assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "add");
    UserManager userManager = getUserManager();
    User testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    assertNotNull(testUser);
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        assertNotNull(userManager.getAuthorizable(groupRef.getId()));
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 20 with ExternalIdentityRef

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

the class LdapIdentityProvider method createUser.

@Nonnull
private ExternalUser createUser(@Nonnull Entry entry, @CheckForNull String id) throws LdapInvalidAttributeValueException {
    ExternalIdentityRef ref = new ExternalIdentityRef(entry.getDn().getName(), this.getName());
    if (id == null) {
        String idAttribute = config.getUserConfig().getIdAttribute();
        Attribute attr = entry.get(idAttribute);
        if (attr == null) {
            throw new LdapInvalidAttributeValueException(ResultCodeEnum.CONSTRAINT_VIOLATION, "no value found for attribute '" + idAttribute + "' for entry " + entry);
        }
        id = attr.getString();
    }
    String path = config.getUserConfig().makeDnPath() ? createDNPath(entry.getDn()) : null;
    LdapUser user = new LdapUser(this, ref, id, path);
    Map<String, Object> props = user.getProperties();
    applyAttributes(props, entry);
    return user;
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) Nonnull(javax.annotation.Nonnull)

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