use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.
the class UserSyncService method getCredentialUpdate.
private WorkloadCredentialUpdate getCredentialUpdate(String username, UmsUsersState umsUsersState) {
UserMetadata userMetadata = requireNonNull(umsUsersState.getUsersState().getUserMetadataMap().get(username), "userMetadata must not be null");
WorkloadCredential workloadCredential = requireNonNull(umsUsersState.getUsersWorkloadCredentialMap().get(username), "workloadCredential must not be null");
return new WorkloadCredentialUpdate(username, userMetadata.getCrn(), workloadCredential);
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.
the class UserSyncStateApplierTest method testApplyDifferenceWithPasswordHashSupport.
@Test
public void testApplyDifferenceWithPasswordHashSupport() throws FreeIpaClientException, TimeoutException {
UsersState usersState = UsersState.newBuilder().addUserMetadata("userToUpdate1", new UserMetadata("userToUpdate1Crn", 1L)).addUserMetadata("userToUpdate2", new UserMetadata("userToUpdate2Crn", 2L)).build();
WorkloadCredential workloadCredential1 = mock(WorkloadCredential.class);
WorkloadCredential workloadCredential2 = mock(WorkloadCredential.class);
UmsUsersState umsUsersState = UmsUsersState.newBuilder().setUsersState(usersState).addWorkloadCredentials("userToUpdate1", workloadCredential1).addWorkloadCredentials("userToUpdate2", workloadCredential2).build();
UserSyncOptions userSyncOptions = mock(UserSyncOptions.class);
UsersStateDifference usersStateDifference = createStateDiff();
Multimap<String, String> warnings = ArrayListMultimap.create();
when(userSyncOptions.isFmsToFreeIpaBatchCallEnabled()).thenReturn(Boolean.TRUE);
Config config = new Config();
config.setIpauserobjectclasses(Set.of("cdpUserAttr"));
when(freeIpaClient.getConfig()).thenReturn(config);
underTest.applyDifference(umsUsersState, ENV_CRN, warnings, usersStateDifference, userSyncOptions, freeIpaClient);
ArgumentCaptor<Set<WorkloadCredentialUpdate>> credentialUpdateCaptor = ArgumentCaptor.forClass(Set.class);
verify(workloadCredentialService).setWorkloadCredentials(eq(userSyncOptions), eq(freeIpaClient), credentialUpdateCaptor.capture(), any());
Set<WorkloadCredentialUpdate> workloadCredentialUpdates = credentialUpdateCaptor.getValue();
assertThat(workloadCredentialUpdates, allOf(hasItem(allOf(hasProperty("username", is("userToUpdate1")), hasProperty("userCrn", is("userToUpdate1Crn")), hasProperty("workloadCredential", is(workloadCredential1)))), hasItem(allOf(hasProperty("username", is("userToUpdate2")), hasProperty("userCrn", is("userToUpdate2Crn")), hasProperty("workloadCredential", is(workloadCredential2))))));
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.
the class SetPasswordHandler method setPasswordHash.
private void setPasswordHash(Stack stack, SetPasswordRequest request, FreeIpaClient freeIpaClient, WorkloadCredential workloadCredential) throws IOException, FreeIpaClientException {
String accountId = Crn.fromString(stack.getEnvironmentCrn()).getAccountId();
boolean credentialsUpdateOptimizationEnabled = entitlementService.usersyncCredentialsUpdateOptimizationEnabled(accountId);
LOGGER.info("Credentials update optimization is{} enabled for account {}", credentialsUpdateOptimizationEnabled ? "" : " not", accountId);
if (credentialUpdateRequired(credentialsUpdateOptimizationEnabled, request.getUsername(), freeIpaClient, workloadCredential)) {
workloadCredentialService.setWorkloadCredential(credentialsUpdateOptimizationEnabled, freeIpaClient, new WorkloadCredentialUpdate(request.getUsername(), request.getUserCrn(), workloadCredential));
} else {
LOGGER.debug("Not setting workload credentials for user '{}' because credentials are already up to date", request.getUsername());
}
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.
the class WorkloadCredentialServiceTest method setWorkloadCredentials.
private void setWorkloadCredentials(boolean batchCallEnabled, boolean updateOptimizationEnabled, FreeIpaClient ipaClient, Map<String, WorkloadCredential> usersWorkloadCredentialMap, Set<String> usersWithCredentialsToUpdate, Map<String, String> userToCrnMap, BiConsumer<String, String> warnings) throws FreeIpaClientException, TimeoutException {
ImmutableSet<WorkloadCredentialUpdate> credentialUpdates = usersWithCredentialsToUpdate.stream().map(username -> new WorkloadCredentialUpdate(username, userToCrnMap.get(username), usersWorkloadCredentialMap.get(username))).collect(ImmutableSet.toImmutableSet());
WorkloadCredentialsUpdateType credentialsUpdateType = updateOptimizationEnabled ? WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED : WorkloadCredentialsUpdateType.FORCE_UPDATE;
underTest.setWorkloadCredentials(new UserSyncOptions(false, batchCallEnabled, credentialsUpdateType), ipaClient, credentialUpdates, warnings);
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.
the class WorkloadCredentialServiceTest method testSetWorkloadCredentialWithUpdateOptimization.
@Test
void testSetWorkloadCredentialWithUpdateOptimization() throws Exception {
doReturn("userMetadataJson").when(userMetadataConverter).toUserMetadataJson(USER_CRN, UMS_WORKLOAD_CREDENTIALS_VERSION);
when(freeIpaClient.invoke(any(), any(), any(), any())).thenReturn(getRpcResponse());
underTest.setWorkloadCredential(true, freeIpaClient, new WorkloadCredentialUpdate(USER, USER_CRN, createWorkloadCredential()));
verify(freeIpaClient).invoke(eq("user_mod"), eq(List.of(USER)), argThat(matchesTitleAttribute("userMetadataJson")), any());
verifyNoInteractions(interruptChecker);
}
Aggregations