Commit a4374211 authored by michael.simon's avatar michael.simon
Browse files

Audit User update with registry changes

parent accafaed
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.entity.audit;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import edu.kit.scc.webreg.entity.RegistryEntity;
@Entity(name = "AuditRegistryEntity")
public class AuditRegistryEntity extends AuditEntryEntity {
private static final long serialVersionUID = 1L;
@ManyToOne(targetEntity = RegistryEntity.class)
private RegistryEntity registry;
public RegistryEntity getRegistry() {
return registry;
}
public void setRegistry(RegistryEntity registry) {
this.registry = registry;
}
}
package edu.kit.scc.webreg.entity.audit;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
import edu.kit.scc.webreg.entity.RegistryEntity;
@StaticMetamodel(AuditRegistryEntity.class)
public class AuditRegistryEntity_ extends AuditEntryEntity_ {
public static volatile SingularAttribute<AuditRegistryEntity, RegistryEntity> registry;
}
......@@ -36,7 +36,12 @@ public abstract class AbstractAuditor implements Auditor {
@Override
public abstract AuditEntryEntity getAudit();
@Override
public void setParent(Auditor auditor) {
getAudit().setParentEntry(auditor.getAudit().getParentEntry());
}
@Override
public void startAuditTrail(String executor) {
getAudit().setStartTime(new Date());
......
......@@ -19,4 +19,6 @@ public interface Auditor {
public abstract void setDetail(String detail);
public abstract String getActualExecutor();
void setParent(Auditor auditor);
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.audit;
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 {
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);
}
}
......@@ -25,6 +25,7 @@ import org.slf4j.Logger;
import edu.kit.scc.webreg.audit.Auditor;
import edu.kit.scc.webreg.audit.IdpCommunicationAuditor;
import edu.kit.scc.webreg.audit.RegistryAuditor;
import edu.kit.scc.webreg.audit.UserUpdateAuditor;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.dao.RegistryDao;
......@@ -162,17 +163,15 @@ public class UserUpdater implements Serializable {
user.getAttributeStore().clear();
if (UserStatus.ACTIVE.equals(user.getUserStatus())) {
user.setUserStatus(UserStatus.ON_HOLD);
user.setLastStatusChange(new Date());
changeUserStatus(user, UserStatus.ON_HOLD, auditor);
/*
* Also flag all registries for user ON_HOLD
*/
List<RegistryEntity> registryList = registryDao.findByUserAndStatus(user,
RegistryStatus.ACTIVE, RegistryStatus.LOST_ACCESS, RegistryStatus.INVALID);
for (RegistryEntity registry : registryList) {
registry.setRegistryStatus(RegistryStatus.ON_HOLD);
registry.setLastStatusChange(new Date());
changeRegistryStatus(registry, RegistryStatus.ON_HOLD, auditor);
}
}
}
......@@ -184,8 +183,7 @@ public class UserUpdater implements Serializable {
changed |= updateUserFromAttribute(user, attributeMap, auditor);
if (UserStatus.ON_HOLD.equals(user.getUserStatus())) {
user.setUserStatus(UserStatus.ACTIVE);
user.setLastStatusChange(new Date());
changeUserStatus(user, UserStatus.ACTIVE, auditor);
/*
* Also reenable all registries for user to LOST_ACCESS.
......@@ -194,8 +192,7 @@ public class UserUpdater implements Serializable {
List<RegistryEntity> registryList = registryDao.findByUserAndStatus(user,
RegistryStatus.ON_HOLD);
for (RegistryEntity registry : registryList) {
registry.setRegistryStatus(RegistryStatus.LOST_ACCESS);
registry.setLastStatusChange(new Date());
changeRegistryStatus(registry, RegistryStatus.LOST_ACCESS, auditor);
}
/*
......@@ -484,4 +481,29 @@ public class UserUpdater implements Serializable {
return true;
}
protected void changeUserStatus(UserEntity user, UserStatus toStatus, Auditor auditor) {
UserStatus fromStatus = user.getUserStatus();
user.setUserStatus(toStatus);
user.setLastStatusChange(new Date());
auditor.logAction(user.getEppn(), "CHANGE STATUS", fromStatus + " -> " + toStatus,
"Change status " + fromStatus + " -> " + toStatus, AuditStatus.SUCCESS);
}
protected void changeRegistryStatus(RegistryEntity registry, RegistryStatus toStatus, Auditor parentAuditor) {
RegistryStatus fromStatus = registry.getRegistryStatus();
registry.setRegistryStatus(toStatus);
registry.setLastStatusChange(new Date());
RegistryAuditor registryAuditor = new RegistryAuditor(auditDao, auditDetailDao, appConfig);
registryAuditor.setParent(parentAuditor);
registryAuditor.startAuditTrail(parentAuditor.getActualExecutor());
registryAuditor.setName(getClass().getName() + "-UserUpdate-Registry-Audit");
registryAuditor.setDetail("Update registry " + registry.getId() + " for user " + registry.getUser().getEppn());
registryAuditor.setRegistry(registry);
registryAuditor.logAction(registry.getUser().getEppn(), "CHANGE STATUS", "registry-" + registry.getId(),
"Change status " + fromStatus + " -> " + toStatus, AuditStatus.SUCCESS);
registryAuditor.finishAuditTrail();
}
}
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