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