use of eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication in project CzechIdMng by bcvsolutions.
the class AuditableEntityListener method touchForCreate.
/**
* Sets creation date and creator on the target object in case it implements {@link Auditable} on
* persist events.
*
* @param target
*/
@PrePersist
public void touchForCreate(Object target) {
if (!(target instanceof Auditable)) {
return;
}
//
AutowireHelper.autowire(this, this.securityService);
//
ZonedDateTime date = ZonedDateTime.now();
Auditable entity = (Auditable) target;
// set created date - can be preset (e.g. preserve created date of original operation moved some where info archive)
if (entity.getCreated() == null) {
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();
entity.setCreator(creator);
//
UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
entity.setCreatorId(creatorId);
}
// could be filled in wf (applicant) ...
if (entity.getOriginalCreator() == null) {
String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
entity.setOriginalCreator(originalCreator);
//
UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
entity.setOriginalCreatorId(originalCreatorId);
}
// set transaction id from context holder
entity.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
}
use of eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication in project CzechIdMng by bcvsolutions.
the class IdmAuditListener method changeRevisionEntity.
private void changeRevisionEntity(Class<AbstractEntity> entityClass, String entityName, UUID entityId, IdmAudit revisionEntity, RevisionType revisionType) {
// 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 currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
//
revisionEntity.setModifier(securityService.getUsername());
revisionEntity.setModifierId(currentIdentity == null ? null : currentIdentity.getId());
// original action executer identity (before switch)
revisionEntity.setOriginalModifier(securityService.getOriginalUsername());
revisionEntity.setOriginalModifierId(originalIdentity == null ? null : originalIdentity.getId());
// entity id
revisionEntity.setEntityId((UUID) entityId);
//
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());
}
// transaction id
revisionEntity.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
}
Aggregations