use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.
the class EntityEventProcessorUnitTest method testSupportRoleDeleteOnly.
@Test
public void testSupportRoleDeleteOnly() {
EntityEventProcessor<?> processor = new EventProcessorRole();
assertFalse(processor.supports(new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto())));
assertFalse(processor.supports(new IdentityEvent(IdentityEventType.DELETE, new IdmIdentityDto())));
assertTrue(processor.supports(new RoleEvent(RoleEventType.DELETE, new IdmRoleDto())));
assertFalse(processor.supports(new CoreEvent<IdmIdentityDto>(CustomType.SAVE, new IdmIdentityDto())));
assertFalse(processor.supports(new CoreEvent<>(CustomType.CUSTOM, new IdmIdentityDto())));
assertTrue(processor.supports(new CoreEvent<IdmRoleDto>(IdentityEventType.UPDATE, new IdmRoleDto())));
}
use of eu.bcvsolutions.idm.core.model.event.IdentityEvent in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testOriginalSource.
@Test
public void testOriginalSource() {
IdmIdentityDto createdIdentity = helper.createIdentity();
// process change
IdmIdentityDto updateIdentity = identityService.get(createdIdentity.getId());
updateIdentity.setFirstName("newFirst");
updateIdentity.setLastName("newLast");
EntityEvent<IdmIdentityDto> event = new IdentityEvent(IdentityEventType.UPDATE, updateIdentity);
EventContext<IdmIdentityDto> context = entityEventManager.process(event);
IdmIdentityDto originalIdentity = context.getLastResult().getEvent().getOriginalSource();
IdmIdentityDto savedIdentity = context.getLastResult().getEvent().getContent();
// check
assertEquals(createdIdentity.getUsername(), originalIdentity.getUsername());
assertEquals(createdIdentity.getFirstName(), originalIdentity.getFirstName());
assertEquals(createdIdentity.getLastName(), originalIdentity.getLastName());
assertEquals(updateIdentity.getUsername(), savedIdentity.getUsername());
assertEquals(updateIdentity.getFirstName(), savedIdentity.getFirstName());
assertEquals(updateIdentity.getLastName(), savedIdentity.getLastName());
}
use of eu.bcvsolutions.idm.core.model.event.IdentityEvent 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());
}
Aggregations