Search in sources :

Example 6 with SetPasswordRequest

use of com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest in project cloudbreak by hortonworks.

the class SetPasswordHandlerTest method testWithPasswordHashSupportWithUmsPasswordWithoutUpdateOptimization.

@Test
void testWithPasswordHashSupportWithUmsPasswordWithoutUpdateOptimization() throws FreeIpaClientException, IOException {
    SetPasswordRequest request = new SetPasswordRequest(1L, "environment", USER, USER_CRN, "password", Optional.empty());
    FreeIpaClient mockFreeIpaClient = newfreeIpaClient(true);
    when(freeIpaClientFactory.getFreeIpaClientForStack(any())).thenReturn(mockFreeIpaClient);
    setupMocksForPasswordHashSupport(true, false);
    underTest.accept(new Event<>(request));
    verify(workloadCredentialService, times(1)).setWorkloadCredential(eq(false), any(), any());
    verify(mockFreeIpaClient, times(0)).userSetPasswordWithExpiration(any(), any(), any());
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) SetPasswordRequest(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest) Test(org.junit.jupiter.api.Test)

Example 7 with SetPasswordRequest

use of com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest in project cloudbreak by hortonworks.

the class SetPasswordHandlerTest method testWithoutPasswordHashSupport.

@Test
void testWithoutPasswordHashSupport() throws FreeIpaClientException {
    SetPasswordRequest request = new SetPasswordRequest(1L, "environment", USER, USER_CRN, "password", Optional.empty());
    FreeIpaClient mockFreeIpaClient = newfreeIpaClient(false);
    when(freeIpaClientFactory.getFreeIpaClientForStack(any())).thenReturn(mockFreeIpaClient);
    underTest.accept(new Event<>(request));
    verify(mockFreeIpaClient, times(1)).userSetPasswordWithExpiration(any(), any(), any());
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) SetPasswordRequest(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest) Test(org.junit.jupiter.api.Test)

Example 8 with SetPasswordRequest

use of com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest in project cloudbreak by hortonworks.

the class PasswordService method triggerSetPassword.

private SetPasswordRequest triggerSetPassword(Stack stack, String environment, String username, String userCrn, String password, Optional<Instant> expirationInstant) {
    SetPasswordRequest request = new SetPasswordRequest(stack.getId(), environment, username, userCrn, password, expirationInstant);
    freeIpaFlowManager.notifyNonFlowEvent(request);
    return request;
}
Also used : SetPasswordRequest(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)

Example 9 with SetPasswordRequest

use of com.sequenceiq.freeipa.flow.freeipa.user.event.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)

Aggregations

SetPasswordRequest (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)9 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)7 Test (org.junit.jupiter.api.Test)6 User (com.sequenceiq.freeipa.client.model.User)3 Stack (com.sequenceiq.freeipa.entity.Stack)2 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)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 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 SetPasswordResult (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordResult)1 WorkloadCredential (com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1