Search in sources :

Example 26 with OperationResult

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

the class IdentityContractEndProcessor method process.

/**
 * Check identity state after contract ended
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    // update identity state
    IdmIdentityDto identity = identityService.get(contract.getIdentity());
    IdentityState newState = identityService.evaluateState(identity.getId());
    if (identity.getState() != newState) {
        LOG.info("Change identity [{}] state [{}]", identity.getUsername(), newState);
        // 
        identity.setState(newState);
        // is neccessary publish new event with skip recalculation automatic roles
        IdentityEvent identityEvent = new IdentityEvent(IdentityEventType.UPDATE, identity);
        identityEvent.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, skipRecalculation);
        identityService.publish(identityEvent);
    }
    // TODO: remove? It's solved by different process
    if (!contract.isValidNowOrInFuture()) {
        identityRoleService.findAllByContract(contract.getId()).forEach(role -> {
            identityRoleService.delete(role);
        });
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 27 with OperationResult

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

the class IdentityContractEndProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    if (!StringUtils.isEmpty(getWorkflowDefinitionKey())) {
        // wf is configured - execute wf instance
        return super.process(event);
    }
    // 
    IdmIdentityContractDto contract = event.getContent();
    OperationResult result = process(contract, (Boolean) event.getProperties().get(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION));
    return new DefaultEventResult.Builder<>(event, this).setResult(result).build();
}
Also used : OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 28 with OperationResult

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

the class IdentityPasswordChangeNotificationProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    List<EventResult<IdmIdentityDto>> results = event.getContext().getResults();
    // 
    List<IdmAccountDto> successAccounts = new ArrayList<>();
    List<OperationResult> failureResults = new ArrayList<>();
    List<String> systemNames = new ArrayList<>();
    for (EventResult<IdmIdentityDto> eventResult : results) {
        eventResult.getResults().forEach(result -> {
            if (result.getModel() != null) {
                boolean success = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
                if (success) {
                    IdmAccountDto account = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
                    systemNames.add(account.getSystemName());
                    successAccounts.add(account);
                } else {
                    // exception is logged before
                    failureResults.add(result);
                }
            }
        });
    }
    // send notification if at least one system success
    if (!successAccounts.isEmpty()) {
        notificationManager.send(CoreModuleDescriptor.TOPIC_PASSWORD_CHANGED, new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).addParameter("successSystemNames", StringUtils.join(systemNames, ", ")).addParameter("successAccounts", successAccounts).addParameter("failureResults", failureResults).addParameter("name", identityService.getNiceLabel(identity)).addParameter("username", identity.getUsername()).build(), identity);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : ArrayList(java.util.ArrayList) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 29 with OperationResult

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

the class DefaultIdmIdentityService method passwordChange.

/**
 * Changes given identity's password
 *
 * @param identity
 * @param passwordChangeDto
 */
@Override
@Transactional
public List<OperationResult> passwordChange(IdmIdentityDto identity, PasswordChangeDto passwordChangeDto) {
    Assert.notNull(identity);
    // 
    LOG.debug("Changing password for identity [{}]", identity.getUsername());
    EventContext<IdmIdentityDto> context = entityEventManager.process(new IdentityEvent(IdentityEventType.PASSWORD, identity, ImmutableMap.of(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO, passwordChangeDto)));
    // get all password change results
    // more provisioning operation can be executed for one password change - we need to distinct them by account id
    // accountId / result
    Map<UUID, OperationResult> passwordChangeResults = new HashMap<>();
    context.getResults().forEach(eventResult -> {
        eventResult.getResults().forEach(result -> {
            if (result.getModel() != null) {
                boolean success = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
                boolean failure = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_FAILED.name());
                if (success || failure) {
                    IdmAccountDto resultAccount = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
                    if (!passwordChangeResults.containsKey(resultAccount.getId())) {
                        passwordChangeResults.put(resultAccount.getId(), result);
                    } else if (failure) {
                        // failure has higher priority
                        passwordChangeResults.put(resultAccount.getId(), result);
                    }
                }
            }
        });
    });
    return new ArrayList<>(passwordChangeResults.values());
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) HashMap(java.util.HashMap) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) ArrayList(java.util.ArrayList) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with OperationResult

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

the class DefaultSchedulerManagerIntegrationTest method testDependentTaskNoExecutionAfterInitiatorFails.

@Test
public void testDependentTaskNoExecutionAfterInitiatorFails() throws Exception {
    helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
    try {
        LongRunningTaskExecuteDependentProcessor processor = context.getBean(LongRunningTaskExecuteDependentProcessor.class);
        // 
        IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
        filter.setOperationState(OperationState.CREATED);
        filter.setTaskType(TestSchedulableTask.class.getCanonicalName());
        filter.setFrom(new DateTime());
        List<IdmLongRunningTaskDto> createdLrts = longRunningTaskService.find(filter, null).getContent();
        Assert.assertEquals(0L, createdLrts.size());
        // 
        Task task = createTask("dependent-task-initiator");
        DependentTaskTrigger trigger = new DependentTaskTrigger();
        trigger.setInitiatorTaskId(task.getId());
        // 
        // initiator = dependent task => circular execution
        manager.createTrigger(task.getId(), trigger);
        manager.runTask(task.getId());
        helper.waitForResult(getContinueFunction());
        createdLrts = longRunningTaskService.find(filter, null).getContent();
        Assert.assertEquals(1L, createdLrts.size());
        IdmLongRunningTaskDto lrt = createdLrts.get(0);
        lrt.setResult(new OperationResult(OperationState.EXCEPTION));
        // not executed
        EventResult<IdmLongRunningTaskDto> result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.BLOCKED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.NOT_EXECUTED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.CANCELED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.CREATED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.RUNNING));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        // 
        longRunningTaskManager.cancel(lrt.getId());
        // 
        longRunningTaskService.find(filter, null).getContent();
        // cancel - clean up
        Assert.assertEquals(0L, longRunningTaskService.find(filter, null).getTotalElements());
    } finally {
        helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) FutureTask(java.util.concurrent.FutureTask) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) LongRunningTaskExecuteDependentProcessor(eu.bcvsolutions.idm.core.scheduler.event.processor.LongRunningTaskExecuteDependentProcessor) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) LongRunningTaskEvent(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent) DateTime(org.joda.time.DateTime) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

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