Search in sources :

Example 6 with UsersStateDifference

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

the class UserSyncForStackServiceTest method testSynchronizeStackSuccessFullWithRetry.

@Test
public void testSynchronizeStackSuccessFullWithRetry() throws Exception {
    UmsUsersState umsUsersState = mock(UmsUsersState.class);
    UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.FORCE_UPDATE);
    UsersState usersState = mock(UsersState.class);
    when(usersState.getUsers()).thenReturn(ImmutableSet.of());
    when(usersState.getGroups()).thenReturn(ImmutableSet.of());
    when(freeIpaUsersStateProvider.getUsersState(FREE_IPA_CLIENT)).thenReturn(usersState);
    UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
    when(userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, usersState, options)).thenReturn(usersStateDifference);
    when(userStateDifferenceCalculator.usersStateDifferenceChanged(any(), any())).thenReturn(TRUE);
    when(entitlementService.cloudIdentityMappingEnabled(ACCOUNT)).thenReturn(TRUE);
    when(entitlementService.isEnvironmentPrivilegedUserEnabled(ACCOUNT)).thenReturn(TRUE);
    doAnswer(invocation -> {
        Multimap<String, String> warnings = invocation.getArgument(2, Multimap.class);
        warnings.put(ENV_CRN, "failed");
        return null;
    }).doNothing().when(stateApplier).applyDifference(eq(umsUsersState), eq(ENV_CRN), any(), eq(usersStateDifference), eq(options), eq(FREE_IPA_CLIENT));
    SyncStatusDetail result = underTest.synchronizeStack(STACK, umsUsersState, options);
    verify(freeIpaUsersStateProvider, never()).getFilteredFreeIpaState(any(), any());
    verify(cloudIdentitySyncService).syncCloudIdentities(eq(STACK), eq(umsUsersState), any());
    verify(sudoRuleService).setupSudoRule(STACK, FREE_IPA_CLIENT);
    assertEquals(ENV_CRN, result.getEnvironmentCrn());
    assertEquals(COMPLETED, result.getStatus());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) TimeoutException(java.util.concurrent.TimeoutException) Multimap(com.google.common.collect.Multimap) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Mockito.doAnswer(org.mockito.Mockito.doAnswer) WorkloadCredentialsUpdateType(com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Stack(com.sequenceiq.freeipa.entity.Stack) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableSet(com.google.common.collect.ImmutableSet) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) COMPLETED(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.COMPLETED) Collection(java.util.Collection) Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) FAILED(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) TRUE(java.lang.Boolean.TRUE) Mockito.mock(org.mockito.Mockito.mock) Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) 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) Test(org.junit.jupiter.api.Test)

Example 7 with UsersStateDifference

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

the class UserSyncForStackService method retrySyncIfBatchCallHasWarnings.

private void retrySyncIfBatchCallHasWarnings(Stack stack, UmsUsersState umsUsersState, Multimap<String, String> warnings, UserSyncOptions options, FreeIpaClient freeIpaClient, UsersStateDifference usersStateDifferenceBeforeSync) throws FreeIpaClientException, TimeoutException {
    if (options.isFullSync() && !warnings.isEmpty() && options.isFmsToFreeIpaBatchCallEnabled()) {
        UsersStateDifference usersStateDifferenceAfterSync = compareUmsAndFreeIpa(umsUsersState, options, freeIpaClient);
        if (userStateDifferenceCalculator.usersStateDifferenceChanged(usersStateDifferenceBeforeSync, usersStateDifferenceAfterSync)) {
            Multimap<String, String> retryWarnings = ArrayListMultimap.create();
            try {
                LOGGER.info(String.format("Sync was partially successful for %s, thus we are trying it once again", stack.getResourceCrn()));
                stateApplier.applyDifference(umsUsersState, stack.getEnvironmentCrn(), retryWarnings, usersStateDifferenceAfterSync, options, freeIpaClient);
                warnings.clear();
            } finally {
                warnings.putAll(retryWarnings);
            }
        }
    }
}
Also used : UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)

Example 8 with UsersStateDifference

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

the class UserSyncForStackService method compareUmsAndFreeIpa.

private UsersStateDifference compareUmsAndFreeIpa(UmsUsersState umsUsersState, UserSyncOptions options, FreeIpaClient freeIpaClient) throws FreeIpaClientException {
    UserSyncLogEvent logEvent = options.isFullSync() ? RETRIEVE_FULL_IPA_STATE : 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 {} ...", CALCULATE_UMS_IPA_DIFFERENCE);
    UsersStateDifference usersStateDifference = userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, ipaUsersState, options);
    LOGGER.debug("Finished {}.", 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 9 with UsersStateDifference

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

the class UserSyncStateApplierTest method testApplyStateDifferenceToIpa.

@Test
void testApplyStateDifferenceToIpa() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    UsersStateDifference usersStateDifference = createStateDiff();
    underTest.applyStateDifferenceToIpa(ENV_CRN, freeIpaClient, usersStateDifference, warnings::put, true);
    verifyOperationsCalled(usersStateDifference);
}
Also used : UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

Example 10 with UsersStateDifference

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

the class UserSyncStateApplierTest method testApplyDifferenceNoPasswordHashSupport.

@Test
public void testApplyDifferenceNoPasswordHashSupport() throws FreeIpaClientException, TimeoutException {
    UmsUsersState umsUsersState = mock(UmsUsersState.class);
    UserSyncOptions userSyncOptions = mock(UserSyncOptions.class);
    UsersStateDifference usersStateDifference = createStateDiff();
    Multimap<String, String> warnings = ArrayListMultimap.create();
    when(userSyncOptions.isFmsToFreeIpaBatchCallEnabled()).thenReturn(Boolean.TRUE);
    when(freeIpaClient.getConfig()).thenReturn(new Config());
    underTest.applyDifference(umsUsersState, ENV_CRN, warnings, usersStateDifference, userSyncOptions, freeIpaClient);
    verifyNoInteractions(workloadCredentialService);
}
Also used : Config(com.sequenceiq.freeipa.client.model.Config) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

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