Search in sources :

Example 11 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorUnitTest method testLogItemProcessed.

@Test
public void testLogItemProcessed() {
    IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
    lrt.setId(UUID.randomUUID());
    when(itemService.saveInternal(any(IdmProcessedTaskItemDto.class))).then(AdditionalAnswers.returnsFirstArg());
    when(longRunningTaskService.get(any(UUID.class))).thenReturn(lrt);
    when(itemService.createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class))).thenCallRealMethod();
    // 
    IdmIdentityDto dto = getTestIdentityDto();
    OperationResult opResult = new OperationResult.Builder(OperationState.EXCEPTION).build();
    IdmProcessedTaskItemDto qItem = executor.logItemProcessed(dto, opResult);
    // 
    assertEquals(lrt.getId(), qItem.getLongRunningTask());
    assertEquals(opResult, qItem.getOperationResult());
    assertEquals(dto.getClass().getCanonicalName(), qItem.getReferencedDtoType());
    assertEquals(dto.getId(), qItem.getReferencedEntityId());
    assertNull(qItem.getScheduledTaskQueueOwner());
    // 
    verify(itemService, times(1)).saveInternal(any(IdmProcessedTaskItemDto.class));
    verify(executor, times(1)).logItemProcessed(any(IdmIdentityDto.class), any(OperationResult.class));
    verify(executor, times(1)).getLongRunningTaskId();
    verify(longRunningTaskService, times(1)).get(any(UUID.class));
    verify(itemService, times(1)).createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class));
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 12 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorUnitTest method testAddToProcessedQueue.

@Test
public void testAddToProcessedQueue() {
    IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
    scheduledTask.setId(UUID.randomUUID());
    when(scheduledTaskService.findByLongRunningTaskId(any(UUID.class))).thenReturn(scheduledTask);
    when(scheduledTaskService.get(any(UUID.class))).thenReturn(scheduledTask);
    when(itemService.saveInternal(any(IdmProcessedTaskItemDto.class))).then(AdditionalAnswers.returnsFirstArg());
    when(itemService.createQueueItem(any(AbstractDto.class), any(OperationResult.class), any(IdmScheduledTaskDto.class))).thenCallRealMethod();
    // 
    IdmIdentityDto dto = getTestIdentityDto();
    OperationResult opResult = new OperationResult.Builder(OperationState.EXCEPTION).build();
    IdmProcessedTaskItemDto qItem = executor.addToProcessedQueue(dto, opResult);
    // 
    assertEquals(scheduledTask.getId(), qItem.getScheduledTaskQueueOwner());
    assertEquals(opResult, qItem.getOperationResult());
    assertEquals(dto.getClass().getCanonicalName(), qItem.getReferencedDtoType());
    assertEquals(dto.getId(), qItem.getReferencedEntityId());
    assertNull(qItem.getLongRunningTask());
    // 
    verify(itemService, times(1)).saveInternal(any(IdmProcessedTaskItemDto.class));
    verify(executor, times(1)).addToProcessedQueue(any(IdmIdentityDto.class), any(OperationResult.class));
    verify(scheduledTaskService, times(1)).findByLongRunningTaskId(any(UUID.class));
    verify(scheduledTaskService, times(1)).get(any(UUID.class));
    verify(itemService, times(1)).createQueueItem(any(AbstractDto.class), any(OperationResult.class), any(IdmScheduledTaskDto.class));
}
Also used : IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Example 13 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class BasicIdmAuthenticationFilterTest method testEnableIdmPasswordChange.

@Test
public void testEnableIdmPasswordChange() {
    String testPassword = "testPassword";
    String newTestPassword = "newTestPassword";
    // 
    this.loginAsAdmin(TEST_ADMIN_USERNAME);
    configurationService.setBooleanValue(IdentityConfiguration.PROPERTY_PUBLIC_CHANGE_PASSWORD_FOR_IDM_ENABLED, true);
    // 
    // create identity
    IdmIdentityDto identity = testHelper.createIdentity();
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setNewPassword(new GuardedString(testPassword));
    passwordService.save(identity, passwordChangeDto);
    this.logout();
    // 
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(identity.getUsername());
    loginDto.setPassword(new GuardedString(testPassword));
    LoginDto login = loginService.login(loginDto);
    // 
    assertNotNull(login.getAuthentication());
    // 
    passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setNewPassword(new GuardedString(newTestPassword));
    passwordChangeDto.setOldPassword(new GuardedString(testPassword));
    passwordChangeDto.setAll(true);
    passwordChangeDto.setIdm(true);
    // 
    List<OperationResult> passwordChangeResults = identityService.passwordChange(identity, passwordChangeDto);
    // 
    assertEquals(1, passwordChangeResults.size());
    OperationResult operationResult = passwordChangeResults.get(0);
    assertEquals(OperationState.EXECUTED, operationResult.getState());
    assertEquals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name(), operationResult.getModel().getStatusEnum());
    assertEquals(HttpStatus.OK, operationResult.getModel().getStatus());
    // 
    loginDto.setUsername(identity.getUsername());
    loginDto.setPassword(new GuardedString(newTestPassword));
    login = loginService.login(loginDto);
    // 
    assertNotNull(login.getAuthentication());
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 14 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class BasicIdmAuthenticationFilterTest method testDisableIdmPasswordChangeViaRest.

@Test
public void testDisableIdmPasswordChangeViaRest() throws JsonProcessingException {
    String testPassword = "testPassword";
    String newTestPassword = "newTestPassword";
    // 
    this.loginAsAdmin(TEST_ADMIN_USERNAME);
    configurationService.setBooleanValue(IdentityConfiguration.PROPERTY_PUBLIC_CHANGE_PASSWORD_FOR_IDM_ENABLED, false);
    // 
    // create identity
    IdmIdentityDto identity = createIdentityInTransaction(testPassword);
    // allow password change
    IdmRoleDto roleWithPermission = testHelper.createRole();
    testHelper.createAuthorizationPolicy(roleWithPermission.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, SelfIdentityEvaluator.class, IdentityBasePermission.PASSWORDCHANGE);
    testHelper.assignRoles(testHelper.getPrimeContract(identity.getId()), roleWithPermission);
    this.logout();
    authorizationPolicyService.getDefaultAuthorities(identity.getId());
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setAll(true);
    passwordChangeDto.setIdm(true);
    passwordChangeDto.setNewPassword(new GuardedString(newTestPassword));
    passwordChangeDto.setOldPassword(new GuardedString(testPassword));
    List<OperationResult> passwordChangeResults = passwordChangeController.passwordChange(identity.getUsername(), passwordChangeDto);
    assertEquals(0, passwordChangeResults.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 15 with OperationResult

use of eu.bcvsolutions.idm.core.api.entity.OperationResult in project CzechIdMng by bcvsolutions.

the class DefaultProvisioningExecutor method execute.

@Override
public OperationResult execute(SysProvisioningBatchDto batch) {
    Assert.notNull(batch);
    batch = batchService.get(batch.getId());
    // 
    OperationResult result = null;
    for (SysProvisioningOperationDto provisioningOperation : provisioningOperationService.getByTimelineAndBatchId(batch.getId())) {
        // It not possible to get operation from embedded, because missing request
        // not run in transaction
        SysProvisioningOperationDto operation = executeInternal(provisioningOperation);
        result = operation.getResult();
        if (OperationState.EXECUTED != result.getState()) {
            // stop processing next requests
            return result;
        }
    }
    // last processed request state (previous requests will be OperationState.EXECUTED)
    return result;
}
Also used : OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Aggregations

OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)14 Test (org.junit.Test)10 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)7 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)5 UUID (java.util.UUID)5 ProvisioningContext (eu.bcvsolutions.idm.acc.domain.ProvisioningContext)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)4 IdmAccountDto (eu.bcvsolutions.idm.core.api.dto.IdmAccountDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 IdentityEvent (eu.bcvsolutions.idm.core.model.event.IdentityEvent)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)4 ArrayList (java.util.ArrayList)4 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)3 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)3 IdentityState (eu.bcvsolutions.idm.core.api.domain.IdentityState)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3