use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest in project cloudbreak by hortonworks.
the class UserV1ControllerTest method setPasswordRejected.
@Test
void setPasswordRejected() {
String password = "password";
SetPasswordRequest request = mock(SetPasswordRequest.class);
when(request.getPassword()).thenReturn(password);
Operation operation = mock(Operation.class);
when(passwordService.setPasswordWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, password, new HashSet<>(), AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)).thenReturn(operation);
SyncOperationStatus status = mock(SyncOperationStatus.class);
when(status.getStatus()).thenReturn(SynchronizationStatus.REJECTED);
when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
assertThrows(SyncOperationAlreadyRunningException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.setPassword(request)));
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest in project cloudbreak by hortonworks.
the class UserV1ControllerTest method setPassword.
@Test
void setPassword() {
String password = "password";
SetPasswordRequest request = mock(SetPasswordRequest.class);
when(request.getPassword()).thenReturn(password);
Operation operation = mock(Operation.class);
when(passwordService.setPasswordWithCustomPermissionCheck(any(), any(), any(), any(), any())).thenReturn(operation);
SyncOperationStatus status = mock(SyncOperationStatus.class);
when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.setPassword(request)));
verify(passwordService, times(1)).setPasswordWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, password, new HashSet<>(), AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest in project cloudbreak by hortonworks.
the class PasswordService method internalSetPasswords.
private void internalSetPasswords(String operationId, String accountId, String userCrn, String password, List<Stack> stacks) {
try {
String userId = getUserIdFromUserCrn(userCrn);
Optional<Instant> expirationInstant = calculateExpirationTime(userCrn, accountId);
List<SetPasswordRequest> requests = new ArrayList<>();
for (Stack stack : stacks) {
requests.add(triggerSetPassword(stack, stack.getEnvironmentCrn(), userId, userCrn, password, expirationInstant));
}
List<SuccessDetails> success = new ArrayList<>();
List<FailureDetails> failure = new ArrayList<>();
for (SetPasswordRequest request : requests) {
try {
waitSetPassword(request);
success.add(new SuccessDetails(request.getEnvironment()));
} catch (InterruptedException e) {
LOGGER.error("Interrupted while setting passwords for user {} in account {}", userCrn, accountId);
throw e;
} catch (Exception e) {
LOGGER.debug("Failed to set password for user {} in environment {}", userCrn, request.getEnvironment(), e);
failure.add(new FailureDetails(request.getEnvironment(), e.getLocalizedMessage()));
}
}
operationService.completeOperation(accountId, operationId, success, failure);
} catch (InterruptedException e) {
operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
Thread.currentThread().interrupt();
} catch (RuntimeException e) {
operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
throw e;
}
}
use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest in project cloudbreak by hortonworks.
the class FreeIpaSetPasswordAction method action.
public FreeIpaUserSyncTestDto action(TestContext testContext, FreeIpaUserSyncTestDto testDto, FreeIpaClient client) throws Exception {
SetPasswordRequest setPasswordRequest = testDto.setPassword(environmentCrns, newPassword);
Log.when(LOGGER, format(" List of environment Crns: [%s], freeIpa Crn: %s", environmentCrns, testDto.getRequest().getEnvironments()));
Log.whenJson(LOGGER, format(" FreeIPA set password request: %n"), setPasswordRequest);
SyncOperationStatus syncOperationStatus = client.getDefaultClient().getUserV1Endpoint().setPassword(setPasswordRequest);
testDto.setOperationId(syncOperationStatus.getOperationId());
LOGGER.info("Sync is in state: [{}], sync operation: [{}] with type: [{}]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType());
Log.when(LOGGER, format(" Sync is in state: [%s], sync operation: [%s] with type: [%s]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType()));
return testDto;
}
Aggregations