Search in sources :

Example 16 with UsersStateDifference

use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.

the class UserSyncServiceTest method testApplyStateDifferenceToIpa.

@Test
void testApplyStateDifferenceToIpa() throws FreeIpaClientException {
    FmsGroup groupToAdd1 = new FmsGroup().withName("groupToAdd1");
    FmsGroup groupToAdd2 = new FmsGroup().withName("groupToAdd2");
    FmsGroup groupToRemove1 = new FmsGroup().withName("groupToRemove1");
    FmsGroup groupToRemove2 = new FmsGroup().withName("groupToRemove2");
    FmsUser userToAdd1 = new FmsUser().withName("userToAdd1").withFirstName("clark").withLastName("kent");
    FmsUser userToAdd2 = new FmsUser().withName("userToAdd2").withFirstName("peter").withLastName("parker");
    String userToRemove1 = "userToRemove1";
    String userToRemove2 = "userToRemove2";
    String userToDisable1 = "userToDisable1";
    String userToDisable2 = "userToDisable2";
    String userToEnable1 = "userToEnable1";
    String userToEnable2 = "userToEnable2";
    Multimap<String, String> warnings = ArrayListMultimap.create();
    doNothing().when(freeIpaClient).callBatch(any(), any(), any(), any());
    UsersStateDifference usersStateDifference = new UsersStateDifference(ImmutableSet.of(groupToAdd1, groupToAdd2), ImmutableSet.of(groupToRemove1, groupToRemove2), ImmutableSet.of(userToAdd1, userToAdd2), ImmutableSet.of(), ImmutableSet.of(userToRemove1, userToRemove2), ImmutableMultimap.<String, String>builder().put(groupToAdd1.getName(), userToAdd1.getName()).put(groupToAdd2.getName(), userToAdd2.getName()).build(), ImmutableMultimap.<String, String>builder().put(groupToRemove1.getName(), userToRemove1).put(groupToRemove2.getName(), userToRemove2).build(), ImmutableSet.of(userToDisable1, userToDisable2), ImmutableSet.of(userToEnable1, userToEnable2));
    underTest.applyStateDifferenceToIpa(ENV_CRN, freeIpaClient, usersStateDifference, warnings::put, true);
    // 9 times instead of 8 because non-posix groups are added in a separate batch
    verify(freeIpaClient, times(9)).callBatch(any(), any(), any(), any());
    verifyNoMoreInteractions(freeIpaClient);
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

Example 17 with UsersStateDifference

use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.

the class UserSyncService method internalSynchronizeStackForDeleteUser.

private SyncStatusDetail internalSynchronizeStackForDeleteUser(Stack stack, String deletedWorkloadUser, boolean fmsToFreeipaBatchCallEnabled) {
    MDCBuilder.buildMdcContext(stack);
    String environmentCrn = stack.getEnvironmentCrn();
    Multimap<String, String> warnings = ArrayListMultimap.create();
    try {
        FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStack(stack);
        LOGGER.debug("Starting {} for environment {} and deleted user {} ...", LogEvent.USER_SYNC_DELETE, environmentCrn, deletedWorkloadUser);
        LOGGER.debug("Starting {} ...", LogEvent.RETRIEVE_PARTIAL_IPA_STATE);
        UsersState ipaUserState = getIpaStateForUser(freeIpaClient, deletedWorkloadUser);
        LOGGER.debug("Finished {}, found {} users and {} groups.", LogEvent.RETRIEVE_PARTIAL_IPA_STATE, ipaUserState.getUsers().size(), ipaUserState.getGroups().size());
        if (!ipaUserState.getUsers().isEmpty()) {
            ImmutableCollection<String> groupMembershipsToRemove = ipaUserState.getGroupMembership().get(deletedWorkloadUser);
            UsersStateDifference usersStateDifference = UsersStateDifference.forDeletedUser(deletedWorkloadUser, groupMembershipsToRemove);
            LOGGER.debug("Starting {} ...", LogEvent.APPLY_DIFFERENCE_TO_IPA);
            applyStateDifferenceToIpa(stack.getEnvironmentCrn(), freeIpaClient, usersStateDifference, warnings::put, fmsToFreeipaBatchCallEnabled);
            LOGGER.debug("Finished {}.", LogEvent.APPLY_DIFFERENCE_TO_IPA);
        }
        LOGGER.debug("Finished {} for environment {} and deleted user {} ...", LogEvent.USER_SYNC_DELETE, environmentCrn, deletedWorkloadUser);
        return toSyncStatusDetail(environmentCrn, warnings);
    } catch (Exception e) {
        LOGGER.warn("Failed to synchronize environment {}", environmentCrn, e);
        return SyncStatusDetail.fail(environmentCrn, e.getLocalizedMessage(), warnings);
    }
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with UsersStateDifference

use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.

the class UserSyncService method compareUmsAndFreeIpa.

private UsersStateDifference compareUmsAndFreeIpa(UmsUsersState umsUsersState, UserSyncOptions options, FreeIpaClient freeIpaClient) throws FreeIpaClientException {
    LogEvent logEvent = options.isFullSync() ? LogEvent.RETRIEVE_FULL_IPA_STATE : LogEvent.RETRIEVE_PARTIAL_IPA_STATE;
    LOGGER.debug("Starting {} ...", logEvent);
    UsersState ipaUsersState = getIpaUserState(freeIpaClient, umsUsersState, options.isFullSync());
    LOGGER.debug("Finished {}, found {} users and {} groups.", logEvent, ipaUsersState.getUsers().size(), ipaUsersState.getGroups().size());
    LOGGER.debug("Starting {} ...", LogEvent.CALCULATE_UMS_IPA_DIFFERENCE);
    UsersStateDifference usersStateDifference = UsersStateDifference.fromUmsAndIpaUsersStates(umsUsersState, ipaUsersState, options);
    LOGGER.debug("Finished {}.", LogEvent.CALCULATE_UMS_IPA_DIFFERENCE);
    return usersStateDifference;
}
Also used : UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)

Example 19 with UsersStateDifference

use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.

the class UserSyncService method internalSynchronizeStack.

private SyncStatusDetail internalSynchronizeStack(Stack stack, UmsUsersState umsUsersState, UserSyncOptions options) {
    MDCBuilder.buildMdcContext(stack);
    String environmentCrn = stack.getEnvironmentCrn();
    Multimap<String, String> warnings = ArrayListMultimap.create();
    try {
        FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStack(stack);
        UsersStateDifference usersStateDifferenceBeforeSync = compareUmsAndFreeIpa(umsUsersState, options, freeIpaClient);
        applyDifference(umsUsersState, environmentCrn, warnings, usersStateDifferenceBeforeSync, options, freeIpaClient);
        retrySyncIfBatchCallHasWarnings(stack, umsUsersState, warnings, options, freeIpaClient, usersStateDifferenceBeforeSync);
        // TODO For now we only sync cloud ids during full sync. We should eventually allow more granular syncs (actor level and group level sync).
        if (options.isFullSync() && entitlementService.cloudIdentityMappingEnabled(stack.getAccountId())) {
            LOGGER.debug("Starting {} ...", LogEvent.SYNC_CLOUD_IDENTITIES);
            cloudIdentitySyncService.syncCloudIdentities(stack, umsUsersState, warnings::put);
            LOGGER.debug("Finished {}.", LogEvent.SYNC_CLOUD_IDENTITIES);
        }
        return toSyncStatusDetail(environmentCrn, warnings);
    } catch (Exception e) {
        LOGGER.warn("Failed to synchronize environment {}", environmentCrn, e);
        return SyncStatusDetail.fail(environmentCrn, e.getLocalizedMessage(), warnings);
    }
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

UsersStateDifference (com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)19 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)12 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)11 Test (org.junit.jupiter.api.Test)10 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)7 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)6 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)6 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)5 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)4 TimeoutException (java.util.concurrent.TimeoutException)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 Config (com.sequenceiq.freeipa.client.model.Config)2 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)2 Collection (java.util.Collection)2 Set (java.util.Set)2 ExecutionException (java.util.concurrent.ExecutionException)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Multimap (com.google.common.collect.Multimap)1 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1