Search in sources :

Example 11 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState 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 12 with UmsUsersState

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

the class BaseUmsUsersStateProviderTest method verifyUmsUsersStateBuilderMap.

protected void verifyUmsUsersStateBuilderMap(Map<String, UmsUsersState> umsUsersStateMap) {
    assertEquals(1, umsUsersStateMap.size());
    UmsUsersState state = umsUsersStateMap.get(ENVIRONMENT_CRN);
    assertNotNull(state);
    // Add the internal group to the expected groups and wags
    assertEquals(testData.groups.size() + testData.wagsForThisEnvironment.size() + 1, state.getUsersState().getGroups().size());
    List<String> groupNames = state.getUsersState().getGroups().stream().map(FmsGroup::getName).collect(Collectors.toList());
    assertTrue(groupNames.containsAll(testData.groups.stream().map(UserManagementProto.Group::getGroupName).collect(Collectors.toList())));
    assertTrue(groupNames.containsAll(testData.wagsForThisEnvironment.stream().map(UserManagementProto.WorkloadAdministrationGroup::getWorkloadAdministrationGroupName).collect(Collectors.toList())));
    assertEquals(testData.allWags.stream().map(UserManagementProto.WorkloadAdministrationGroup::getWorkloadAdministrationGroupName).collect(Collectors.toSet()), state.getWorkloadAdministrationGroups().stream().map(FmsGroup::getName).collect(Collectors.toSet()));
    assertEquals(Stream.concat(testData.users.stream().map(UserManagementProto.User::getWorkloadUsername), testData.machineUsers.stream().map(UserManagementProto.MachineUser::getWorkloadUsername)).collect(Collectors.toSet()), state.getRequestedWorkloadUsernames());
    // users including rights, group membership, wags
    // machine users including rights, group membership, wags
    UsersState usersState = state.getUsersState();
    Set<String> workloadUsersWithAccess = usersState.getUsers().stream().map(FmsUser::getName).collect(Collectors.toSet());
    Multimap<String, String> groupsPerMember = Multimaps.invertFrom(usersState.getGroupMembership(), ArrayListMultimap.<String, String>create());
    testData.users.forEach(u -> verifyActor(u.getCrn(), u.getWorkloadUsername(), workloadUsersWithAccess, groupsPerMember.get(u.getWorkloadUsername()), state.getUsersWorkloadCredentialMap().get(u.getWorkloadUsername()), usersState.getUserMetadataMap().get(u.getWorkloadUsername())));
    testData.machineUsers.forEach(mu -> verifyActor(mu.getCrn(), mu.getWorkloadUsername(), workloadUsersWithAccess, groupsPerMember.get(mu.getWorkloadUsername()), state.getUsersWorkloadCredentialMap().get(mu.getWorkloadUsername()), usersState.getUserMetadataMap().get(mu.getWorkloadUsername())));
    assertEquals(testData.servicePrincipalCloudIdentities, state.getServicePrincipalCloudIdentities());
}
Also used : UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)

Example 13 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState 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 14 with UmsUsersState

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState 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)

Example 15 with UmsUsersState

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

the class UsersStateDifferenceCalculatorTest method testCalculateGroupMembershipsToRemove.

@Test
void testCalculateGroupMembershipsToRemove() {
    String group = "group";
    String unmanagedGroup = FreeIpaChecks.IPA_UNMANAGED_GROUPS.get(0);
    String userUms = "userUms";
    String userBoth = "userBoth";
    String userIPA = "userIPA";
    UmsUsersState umsUsersState = new UmsUsersState.Builder().setUsersState(new UsersState.Builder().addMemberToGroup(group, userUms).addMemberToGroup(group, userBoth).build()).build();
    UsersState ipaUsersState = new UsersState.Builder().addMemberToGroup(group, userBoth).addMemberToGroup(group, userIPA).addMemberToGroup(unmanagedGroup, userUms).build();
    ImmutableMultimap<String, String> groupMembershipsToRemove = new UserStateDifferenceCalculator().calculateGroupMembershipToRemove(umsUsersState, ipaUsersState);
    // group that exists only in IPA will be removed
    assertTrue(groupMembershipsToRemove.get(group).contains(userIPA));
    // unmanaged groups will be ignored
    assertFalse(groupMembershipsToRemove.get(unmanagedGroup).contains(userUms));
    // groups that exist in both or only ums will not be added
    assertFalse(groupMembershipsToRemove.get(group).contains(userBoth));
    assertFalse(groupMembershipsToRemove.get(group).contains(userUms));
}
Also used : UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Test(org.junit.jupiter.api.Test)

Aggregations

UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)30 Test (org.junit.jupiter.api.Test)23 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)19 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)14 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)11 UsersStateDifference (com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)9 Stack (com.sequenceiq.freeipa.entity.Stack)8 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)7 Collection (java.util.Collection)7 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)5 List (java.util.List)5 Optional (java.util.Optional)5 Callable (java.util.concurrent.Callable)5 Future (java.util.concurrent.Future)5 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)4 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)4 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)4 Set (java.util.Set)4 TimeoutException (java.util.concurrent.TimeoutException)4 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3