Commit 17cdf36b authored by michael.simon's avatar michael.simon
Browse files

introduce audits which are always written, regardless of contents

parent 284ed530
......@@ -32,6 +32,8 @@ public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Aud
protected T audit;
protected Boolean writeAlways;
public AbstractAuditor(AuditEntryDao auditEntryDao, AuditDetailDao auditDetailDao, ApplicationConfig appConfig) {
this.auditDetailDao = auditDetailDao;
this.auditEntryDao = auditEntryDao;
......@@ -52,12 +54,22 @@ public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Aud
if (auditor != null)
getAudit().setParentEntry(auditor.getAudit());
}
@Override
public void startAuditTrail(String executor) {
startAuditTrail(executor, false);
}
@SuppressWarnings("unchecked")
@Override
public void startAuditTrail(String executor, Boolean writeAlways) {
getAudit().setStartTime(new Date());
getAudit().setAuditDetails(new HashSet<AuditDetailEntity>());
getAudit().setExecutor(executor);
this.writeAlways = writeAlways;
if (writeAlways) {
audit = (T) auditEntryDao.persist(getAudit());
}
}
@Override
......@@ -86,9 +98,11 @@ public abstract class AbstractAuditor<T extends AuditEntryEntity> implements Aud
@SuppressWarnings("unchecked")
@Override
public void finishAuditTrail() {
if (getAudit().getAuditDetails().size() > 0 ||
getAudit().setEndTime(new Date());
if ((! writeAlways) &&
getAudit().getAuditDetails().size() > 0 ||
getWriteEmptyAudits()) {
getAudit().setEndTime(new Date());
audit = (T) auditEntryDao.persist(getAudit());
}
}
......
......@@ -23,4 +23,6 @@ public interface Auditor extends Serializable {
public abstract String getActualExecutor();
void setParent(Auditor auditor);
void startAuditTrail(String executor, Boolean writeAlways);
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import edu.kit.scc.webreg.entity.audit.AuditStatus;
public class NullAuditor implements Auditor {
private static final long serialVersionUID = 1L;
private String executor;
@Override
......@@ -17,6 +18,11 @@ public class NullAuditor implements Auditor {
this.executor = executor;
}
@Override
public void startAuditTrail(String executor, Boolean writeAlways) {
this.executor = executor;
}
@Override
public void logAction(String subject, String action, String object,
String log, AuditStatus status) {
......
......@@ -103,7 +103,7 @@ public class ApprovalServiceImpl implements ApprovalService {
public void denyApproval(RegistryEntity registry, String executor, Auditor parentAuditor) throws RegisterException {
ApprovalAuditor auditor = new ApprovalAuditor(auditDao, auditDetailDao, appConfig);
auditor.startAuditTrail(executor);
auditor.startAuditTrail(executor, true);
auditor.setName(this.getClass().getName() + "-ApprovalDeny-Audit");
auditor.setDetail("Deny user " + registry.getUser().getEppn() + " for service " + registry.getService().getName());
auditor.setParent(parentAuditor);
......@@ -145,7 +145,7 @@ public class ApprovalServiceImpl implements ApprovalService {
UserEntity userEntity = userDao.findByIdWithAll(registry.getUser().getId());
ApprovalAuditor auditor = new ApprovalAuditor(auditDao, auditDetailDao, appConfig);
auditor.startAuditTrail(executor);
auditor.startAuditTrail(executor, true);
auditor.setName(workflow.getClass().getName() + "-ApprovalApprove-Audit");
auditor.setDetail("Approve user " + userEntity.getEppn() + " for service " + serviceEntity.getName());
auditor.setParent(parentAuditor);
......
......@@ -144,7 +144,7 @@ public class RegisterUserServiceImpl implements RegisterUserService {
service = serviceDao.findById(service.getId());
ServiceRegisterAuditor auditor = new ServiceRegisterAuditor(auditDao, auditDetailDao, appConfig);
auditor.startAuditTrail(executor);
auditor.startAuditTrail(executor, true);
auditor.setName(this.getClass().getName() + "-ServiceRegister-Audit");
auditor.setDetail("Register user " + user.getEppn() + " for service " + service.getName());
auditor.setParent(parentAuditor);
......
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