Search in sources :

Example 1 with SetPasswordRequest

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)));
}
Also used : SetPasswordRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 2 with SetPasswordRequest

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);
}
Also used : SetPasswordRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 3 with SetPasswordRequest

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;
    }
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Instant(java.time.Instant) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Stack(com.sequenceiq.freeipa.entity.Stack) SetPasswordRequest(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)

Example 4 with SetPasswordRequest

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;
}
Also used : SetPasswordRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)

Aggregations

SetPasswordRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest)3 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)3 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)2 Operation (com.sequenceiq.freeipa.entity.Operation)2 Test (org.junit.jupiter.api.Test)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)1 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 SetPasswordRequest (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1