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());
}
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());
}
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;
}
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);
}
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));
}
Aggregations