Commit 284ed530 authored by michael.simon's avatar michael.simon
Browse files

Change Auditors to reuse Audit objects after persist

parent 47b49c80
......@@ -29,7 +29,7 @@ public class JpaAuditEntryDao extends JpaBaseDao<AuditEntryEntity, Long> impleme
@Override
@SuppressWarnings({"unchecked"})
public List<AuditEntryEntity> findAllOlderThan(Date date, int limit) {
return em.createQuery("select e from AuditEntryEntity e where endTime < :date order by endTime asc")
return em.createQuery("select e from AuditEntryEntity e where parentEntry is not null and endTime < :date order by endTime asc")
.setParameter("date", date).setMaxResults(limit).getResultList();
}
......
......@@ -51,9 +51,13 @@ public class AuditEntryEntity extends AbstractBaseEntity {
@Column(name = "audit_executor", length=64)
private String executor;
@ManyToOne(targetEntity = AuditEntryEntity.class)
@ManyToOne(targetEntity = AuditEntryEntity.class, cascade = { CascadeType.MERGE })
private AuditEntryEntity parentEntry;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE },
targetEntity = AuditEntryEntity.class, mappedBy = "parentEntry")
private Set<AuditEntryEntity> childEntries;
public Date getStartTime() {
return startTime;
}
......
......@@ -20,22 +20,32 @@ import edu.kit.scc.webreg.entity.audit.AuditDetailEntity;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
import edu.kit.scc.webreg.entity.audit.AuditStatus;
public abstract class AbstractAuditor implements Auditor {
public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Auditor {
private static final long serialVersionUID = 1L;
protected static final String WRITE_EMPTY_AUDITS = "AbstractAuditor.writeEmptyAudits";
protected AuditEntryDao auditEntryDao;
protected AuditDetailDao auditDetailDao;
protected ApplicationConfig appConfig;
protected T audit;
public AbstractAuditor(AuditEntryDao auditEntryDao, AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
this.auditDetailDao = auditDetailDao;
this.auditEntryDao = auditEntryDao;
this.appConfig = appConfig;
audit = newInstance();
}
protected abstract T newInstance();
@Override
public abstract AuditEntryEntity getAudit();
public T getAudit() {
return audit;
}
@Override
public void setParent(Auditor auditor) {
......@@ -73,12 +83,13 @@ public abstract class AbstractAuditor implements Auditor {
getAudit().getAuditDetails().add(detail);
}
@SuppressWarnings("unchecked")
@Override
public void finishAuditTrail() {
if (getAudit().getAuditDetails().size() > 0 ||
getWriteEmptyAudits()) {
getAudit().setEndTime(new Date());
auditEntryDao.persist(getAudit());
audit = (T) auditEntryDao.persist(getAudit());
}
}
......
......@@ -15,27 +15,24 @@ import edu.kit.scc.webreg.dao.audit.AuditDetailDao;
import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.audit.AuditApprovalEntity;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
public class ApprovalAuditor extends AbstractAuditor {
public class ApprovalAuditor extends AbstractAuditor<AuditApprovalEntity> {
private static final long serialVersionUID = 1L;
private AuditApprovalEntity audit;
public ApprovalAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditEntryEntity getAudit() {
if (audit == null)
audit = new AuditApprovalEntity();
return audit;
}
public void setRegistry(RegistryEntity entity) {
audit.setRegistry(entity);
}
@Override
protected AuditApprovalEntity newInstance() {
return new AuditApprovalEntity();
}
}
......@@ -15,27 +15,23 @@ import edu.kit.scc.webreg.dao.audit.AuditDetailDao;
import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.entity.audit.AuditAttributeSourceEntity;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
public class AttributeSourceAuditor extends AbstractAuditor {
public class AttributeSourceAuditor extends AbstractAuditor<AuditAttributeSourceEntity> {
private static final long serialVersionUID = 1L;
private AuditAttributeSourceEntity audit;
public AttributeSourceAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditEntryEntity getAudit() {
if (audit == null)
audit = new AuditAttributeSourceEntity();
return audit;
}
public void setAsUserAttr(ASUserAttrEntity entity) {
audit.setAsUserAttr(entity);
}
@Override
protected AuditAttributeSourceEntity newInstance() {
return new AuditAttributeSourceEntity();
}
}
package edu.kit.scc.webreg.audit;
import java.io.Serializable;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
import edu.kit.scc.webreg.entity.audit.AuditStatus;
public interface Auditor {
public interface Auditor extends Serializable {
public abstract AuditEntryEntity getAudit();
......
......@@ -16,25 +16,22 @@ import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.audit.AuditGroupEntity;
public class GroupAuditor extends AbstractAuditor {
public class GroupAuditor extends AbstractAuditor<AuditGroupEntity> {
private static final long serialVersionUID = 1L;
private AuditGroupEntity audit;
public GroupAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditGroupEntity getAudit() {
if (audit == null)
audit = new AuditGroupEntity();
return audit;
}
public void setGroup(GroupEntity entity) {
audit.setGroup(entity);
}
@Override
protected AuditGroupEntity newInstance() {
return new AuditGroupEntity();
}
}
......@@ -17,24 +17,16 @@ import edu.kit.scc.webreg.entity.SamlIdpMetadataEntity;
import edu.kit.scc.webreg.entity.SamlSpConfigurationEntity;
import edu.kit.scc.webreg.entity.audit.AuditIdpCommunicationEntity;
public class IdpCommunicationAuditor extends AbstractAuditor {
public class IdpCommunicationAuditor extends AbstractAuditor<AuditIdpCommunicationEntity> {
private static final long serialVersionUID = 1L;
private AuditIdpCommunicationEntity audit;
public IdpCommunicationAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditIdpCommunicationEntity getAudit() {
if (audit == null)
audit = new AuditIdpCommunicationEntity();
return audit;
}
public void setIdp(SamlIdpMetadataEntity idp) {
audit.setIdp(idp);
}
......@@ -42,4 +34,9 @@ public class IdpCommunicationAuditor extends AbstractAuditor {
public void setSpConfig(SamlSpConfigurationEntity spConfig) {
audit.setSpConfig(spConfig);
}
@Override
protected AuditIdpCommunicationEntity newInstance() {
return new AuditIdpCommunicationEntity();
}
}
......@@ -14,28 +14,24 @@ import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.dao.audit.AuditDetailDao;
import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
import edu.kit.scc.webreg.entity.audit.AuditRegistryEntity;
public class RegistryAuditor extends AbstractAuditor {
public class RegistryAuditor extends AbstractAuditor<AuditRegistryEntity> {
private static final long serialVersionUID = 1L;
private AuditRegistryEntity audit;
public RegistryAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditEntryEntity getAudit() {
if (audit == null)
audit = new AuditRegistryEntity();
return audit;
}
public void setRegistry(RegistryEntity entity) {
audit.setRegistry(entity);
}
@Override
protected AuditRegistryEntity newInstance() {
return new AuditRegistryEntity();
}
}
......@@ -14,28 +14,24 @@ import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.dao.audit.AuditDetailDao;
import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
import edu.kit.scc.webreg.entity.audit.AuditServiceEntity;
public class ServiceAuditor extends AbstractAuditor {
public class ServiceAuditor extends AbstractAuditor<AuditServiceEntity> {
private static final long serialVersionUID = 1L;
private AuditServiceEntity audit;
public ServiceAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditEntryEntity getAudit() {
if (audit == null)
audit = new AuditServiceEntity();
return audit;
}
public void setService(ServiceEntity entity) {
audit.setService(entity);
}
@Override
protected AuditServiceEntity newInstance() {
return new AuditServiceEntity();
}
}
......@@ -14,28 +14,24 @@ import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.dao.audit.AuditDetailDao;
import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
import edu.kit.scc.webreg.entity.audit.AuditServiceRegisterEntity;
public class ServiceRegisterAuditor extends AbstractAuditor {
public class ServiceRegisterAuditor extends AbstractAuditor<AuditServiceRegisterEntity> {
private static final long serialVersionUID = 1L;
private AuditServiceRegisterEntity audit;
public ServiceRegisterAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditEntryEntity getAudit() {
if (audit == null)
audit = new AuditServiceRegisterEntity();
return audit;
}
public void setRegistry(RegistryEntity entity) {
audit.setRegistry(entity);
}
@Override
protected AuditServiceRegisterEntity newInstance() {
return new AuditServiceRegisterEntity();
}
}
......@@ -16,28 +16,19 @@ import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.dao.audit.AuditDetailDao;
import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.audit.AuditEntryEntity;
import edu.kit.scc.webreg.entity.audit.AuditStatus;
import edu.kit.scc.webreg.entity.audit.AuditUserCreateEntity;
public class UserCreateAuditor extends AbstractAuditor {
public class UserCreateAuditor extends AbstractAuditor<AuditUserCreateEntity> {
private static final long serialVersionUID = 1L;
private AuditUserCreateEntity audit;
public UserCreateAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditEntryEntity getAudit() {
if (audit == null)
audit = new AuditUserCreateEntity();
return audit;
}
public void setUser(UserEntity entity) {
audit.setUser(entity);
}
......@@ -52,4 +43,9 @@ public class UserCreateAuditor extends AbstractAuditor {
entry.getValue(), AuditStatus.SUCCESS);
}
}
@Override
protected AuditUserCreateEntity newInstance() {
return new AuditUserCreateEntity();
}
}
......@@ -16,25 +16,22 @@ import edu.kit.scc.webreg.dao.audit.AuditEntryDao;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.audit.AuditUserUpdateEntity;
public class UserUpdateAuditor extends AbstractAuditor {
public class UserUpdateAuditor extends AbstractAuditor<AuditUserUpdateEntity> {
private static final long serialVersionUID = 1L;
private AuditUserUpdateEntity audit;
public UserUpdateAuditor(AuditEntryDao auditEntryDao,
AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
super(auditEntryDao, auditDetailDao, appConfig);
}
@Override
public AuditUserUpdateEntity getAudit() {
if (audit == null)
audit = new AuditUserUpdateEntity();
return audit;
}
public void setUser(UserEntity entity) {
audit.setUser(entity);
}
@Override
protected AuditUserUpdateEntity newInstance() {
return new AuditUserUpdateEntity();
}
}
......@@ -192,11 +192,13 @@ public class RegisterUserServiceImpl implements RegisterUserService {
if (registry.getApprovalBean() != null) {
logger.debug("Registering {} for approval {}", user.getEppn(), registry.getApprovalBean());
auditor.logAction(user.getEppn(), "STARTING APPROVAL", "registry-" + registry.getId(), "Approval is started: " + registry.getApprovalBean(), AuditStatus.SUCCESS);
auditor.finishAuditTrail();
approvalService.registerApproval(registry, auditor);
}
else {
logger.debug("No approval role for service {}. AutoApproving {}", service.getName(), user.getEppn());
auditor.logAction(user.getEppn(), "STARTING AUTO APPROVE", "registry-" + registry.getId(), "Autoapproving registry", AuditStatus.SUCCESS);
auditor.finishAuditTrail();
approvalService.approve(registry, executor, auditor);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment