Search in sources :

Example 21 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method synchronizeAllUsersRejected.

@Test
void synchronizeAllUsersRejected() {
    Set<String> environments = Set.of(ENV_CRN);
    Set<String> users = Set.of(USER_CRN);
    SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
    request.setEnvironments(environments);
    request.setUsers(users);
    Operation operation = mock(Operation.class);
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(users, Set.of(), Optional.empty());
    when(userSyncService.synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, environments, userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, 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.synchronizeAllUsers(request)));
}
Also used : UserSyncRequestFilter(com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) Test(org.junit.jupiter.api.Test)

Example 22 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus 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 23 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method synchronizeUser.

@Test
void synchronizeUser() {
    Operation operation = mock(Operation.class);
    when(userSyncService.synchronizeUsersWithCustomPermissionCheck(any(), any(), any(), any(), any(), any())).thenReturn(operation);
    SyncOperationStatus status = mock(SyncOperationStatus.class);
    when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
    SynchronizeUserRequest request = mock(SynchronizeUserRequest.class);
    assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeUser(request)));
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(USER_CRN), Set.of(), Optional.empty());
    verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, Set.of(), userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Also used : UserSyncRequestFilter(com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) SynchronizeUserRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeUserRequest) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 24 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus 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)

Example 25 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class FreeIpaSynchronizeAllUsersAction method action.

public FreeIpaUserSyncTestDto action(TestContext testContext, FreeIpaUserSyncTestDto testDto, FreeIpaClient client) throws Exception {
    Log.when(LOGGER, format(" Environment Crn: [%s], freeIpa Crn: %s", testDto.getEnvironmentCrn(), testDto.getRequest().getEnvironments()));
    Log.whenJson(LOGGER, format(" FreeIPA sync request: %n"), testDto.getRequest());
    // checking if there is ongoing usersync
    EnvironmentUserSyncState environmentUserSyncState = client.getDefaultClient().getUserV1Endpoint().getUserSyncState(testDto.getEnvironmentCrn());
    if (UserSyncState.SYNC_IN_PROGRESS.equals(environmentUserSyncState.getState())) {
        // sync already in progress, no need to execute another one
        testDto.setOperationId(environmentUserSyncState.getLastUserSyncOperationId());
        LOGGER.info("Sync is in state: [{}], sync operation: [{}]", environmentUserSyncState.getState(), environmentUserSyncState.getLastUserSyncOperationId());
        Log.when(LOGGER, format(" Sync is in state: [%s], sync operation: [%s]", environmentUserSyncState.getState(), environmentUserSyncState.getLastUserSyncOperationId()));
    } else {
        try {
            // need to sync
            SyncOperationStatus syncOperationStatus = client.getDefaultClient().getUserV1Endpoint().synchronizeAllUsers(testDto.getRequest());
            testDto.setOperationId(syncOperationStatus.getOperationId());
            LOGGER.info("Sync is in state: [{}], sync operation id: [{}] with type: [{}]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType());
            Log.when(LOGGER, format(" Sync is in state: [%s], sync operation id: [%s] with type: [%s]", syncOperationStatus.getStatus(), syncOperationStatus.getOperationId(), syncOperationStatus.getSyncOperationType()));
        } catch (ClientErrorException e) {
            // still can happen that a concurrent user sync got initiated
            if (e.getResponse() != null && HttpStatus.CONFLICT.value() == e.getResponse().getStatus()) {
                LOGGER.info("Sync were already initiated for environment {}", testDto.getEnvironmentCrn());
            } else {
                throw e;
            }
        }
    }
    return testDto;
}
Also used : SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) ClientErrorException(javax.ws.rs.ClientErrorException) EnvironmentUserSyncState(com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)

Aggregations

SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)26 Test (org.junit.jupiter.api.Test)18 Operation (com.sequenceiq.freeipa.entity.Operation)15 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)12 SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)8 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)3 SetPasswordRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest)3 SynchronizationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus)3 SynchronizeUserRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeUserRequest)3 OperationState (com.sequenceiq.freeipa.api.v1.operation.model.OperationState)3 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 ResourceCrn (com.sequenceiq.authorization.annotation.ResourceCrn)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 UserV1Endpoint (com.sequenceiq.freeipa.api.v1.freeipa.user.UserV1Endpoint)1 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)1 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1