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();
}
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();
}
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);
}
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());
}
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);
}
}
Aggregations