use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class IdentityDeleteProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
// contracts
identityContractService.findAllByIdentity(identity.getId()).forEach(identityContract -> {
// when identity is deleted, then HR processes has to be shipped (prevent to update deleted identity, when contract is removed)
Map<String, Serializable> properties = new HashMap<>();
properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
identityContractService.publish(new CoreEvent<>(CoreEventType.DELETE, identityContract, properties));
});
// contract guaratee - set to null
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setGuaranteeId(identity.getId());
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// remove role guarantee
IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
roleGuaranteeFilter.setGuarantee(identity.getId());
roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
roleGuaranteeService.delete(roleGuarantee);
});
// remove password
passwordProcessor.deletePassword(identity);
// set to null all notification recipients - real recipient remains (email etc.)
notificationRecipientRepository.clearIdentity(identity.getId());
// remove authorities last changed relation
deleteAuthorityChange(identity);
// Delete all role requests where is this identity applicant
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(identity.getId());
roleRequestService.find(roleRequestFilter, null).forEach(request -> {
roleRequestService.delete(request);
});
// remove all IdentityRoleValidRequest for this identity
List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identity.getId());
identityRoleValidRequestService.deleteAll(validRequests);
// deletes identity
service.deleteInternal(identity);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class IdentityMonitoredFieldsProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
List<String> fields = getCommaSeparatedValues((String) this.getConfigurationMap().get(PROPERTY_MONITORED_FIELDS));
String recipientsRole = (String) this.getConfigurationMap().get(PROPERTY_RECIPIENTS_ROLE);
if (CollectionUtils.isEmpty(fields)) {
LOG.debug("None monitored fields found in configuration.");
return new DefaultEventResult<>(event, this);
}
List<IdmIdentityDto> recipients = service.findAllByRoleName(recipientsRole);
if (CollectionUtils.isEmpty(recipients)) {
LOG.debug("None recievers found in configuration.");
return new DefaultEventResult<>(event, this);
}
IdmIdentityDto newIdentity = event.getContent();
IdmIdentityDto identity = event.getOriginalSource();
List<ChangedField> changedFields = new ArrayList<>();
// Check monitored fields on some changes
fields.forEach(field -> {
try {
Object value = EntityUtils.getEntityValue(identity, field);
Object newValue = EntityUtils.getEntityValue(newIdentity, field);
if (value == null && newValue == null) {
return;
}
if (value != null && !value.equals(newValue)) {
changedFields.add(new ChangedField(field, value.toString(), newValue == null ? null : newValue.toString()));
return;
}
if (newValue != null && !newValue.equals(value)) {
changedFields.add(new ChangedField(field, value == null ? null : value.toString(), newValue.toString()));
return;
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | IntrospectionException e) {
throw new ResultCodeException(CoreResultCode.BAD_REQUEST, e);
}
});
if (!changedFields.isEmpty()) {
IdmMessageDto message = new IdmMessageDto.Builder(NotificationLevel.WARNING).addParameter("fullName", service.getNiceLabel(identity)).addParameter("identity", identity).addParameter("changedFields", changedFields).addParameter("url", configurationService.getFrontendUrl(String.format("identity/%s/profile", identity.getId()))).build();
notificationManager.send(String.format("core:%s", TOPIC), message, recipients);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class AuditableListener method onPreInsert.
@Override
public boolean onPreInsert(PreInsertEvent event) {
if (event.getEntity() instanceof Auditable) {
DateTime date = new DateTime();
Auditable entity = (Auditable) event.getEntity();
//
setValue(event.getState(), event, Auditable.PROPERTY_CREATED, date);
entity.setCreated(date);
//
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
if (entity.getCreator() == null) {
String creator = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
setValue(event.getState(), event, Auditable.PROPERTY_CREATOR, creator);
entity.setCreator(creator);
//
UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
setValue(event.getState(), event, Auditable.PROPERTY_CREATOR_ID, creatorId);
entity.setCreatorId(creatorId);
}
// could be filled in wf (applicant) ...
if (entity.getOriginalCreator() == null) {
String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR, originalCreator);
entity.setOriginalCreator(originalCreator);
//
UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
setValue(event.getState(), event, Auditable.PROPERTY_ORIGINAL_CREATOR_ID, originalCreatorId);
entity.setOriginalCreatorId(originalCreatorId);
}
}
return false;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class IdmAuditListener method changeRevisionDto.
private void changeRevisionDto(Class<AbstractEntity> entityClass, String entityName, UUID entityId, IdmAuditDto revisionEntity, RevisionType revisionType) {
// List<String> changedColumns;
// name of entity class - full name.
revisionEntity.setType(entityName);
// revision type - MOD, DEL, ADD
revisionEntity.setModification(revisionType.name());
// action executer identity
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentModifierIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalModifierIdentity = authentication == null ? null : authentication.getOriginalIdentity();
//
revisionEntity.setModifier(securityService.getUsername());
revisionEntity.setModifierId(currentModifierIdentity == null ? null : currentModifierIdentity.getId());
// original action executer identity (before switch)
revisionEntity.setOriginalModifier(securityService.getOriginalUsername());
revisionEntity.setOriginalModifierId(originalModifierIdentity == null ? null : originalModifierIdentity.getId());
// entity id
revisionEntity.setEntityId((UUID) entityId);
//
// get entity in new transaction if revision type is delete
AbstractEntity currentEntity = null;
if (revisionType == RevisionType.DEL) {
currentEntity = auditService.getActualRemovedEntity(entityClass, entityId);
} else {
currentEntity = (AbstractEntity) entityManger.find(entityClass, entityId);
}
//
if (currentEntity instanceof AuditSearchable) {
AuditSearchable searchableEntity = ((AuditSearchable) currentEntity);
revisionEntity.setOwnerCode(searchableEntity.getOwnerCode());
revisionEntity.setOwnerId(searchableEntity.getOwnerId());
revisionEntity.setOwnerType(searchableEntity.getOwnerType());
revisionEntity.setSubOwnerCode(searchableEntity.getSubOwnerCode());
revisionEntity.setSubOwnerId(searchableEntity.getSubOwnerId());
revisionEntity.setSubOwnerType(searchableEntity.getSubOwnerType());
} else if (currentEntity instanceof Codeable) {
revisionEntity.setOwnerCode(((Codeable) currentEntity).getCode());
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class PasswordExpiredTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmPasswordDto dto) {
IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, dto.getIdentity());
LOG.info("Publishing [{}] event to identity [{}], password expired in [{}]", IdentityEventType.PASSWORD_EXPIRED, identity.getUsername(), dto.getValidTill());
try {
entityEventManager.process(new IdentityEvent(IdentityEventType.PASSWORD_EXPIRED, identity));
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
LOG.error("Publishing [{}] event to identity [{}], password expired in [{}] failed", IdentityEventType.PASSWORD_EXPIRED, dto.getIdentity(), dto.getValidTill(), ex);
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build());
}
}
Aggregations