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

Flag registries to "ON_HOLD" if a user status is changed to "ON_HOLD"

parent 61a6ad3e
......@@ -29,7 +29,7 @@ public interface RegistryDao extends BaseDao<RegistryEntity, Long> {
RegistryStatus status);
List<RegistryEntity> findByUserAndStatus(UserEntity user,
RegistryStatus status);
RegistryStatus... status);
List<RegistryEntity> findByServiceAndUser(ServiceEntity service, UserEntity user);
......
......@@ -237,13 +237,19 @@ public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements
}
@Override
public List<RegistryEntity> findByUserAndStatus(UserEntity user, RegistryStatus status) {
public List<RegistryEntity> findByUserAndStatus(UserEntity user, RegistryStatus... status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RegistryEntity> criteria = builder.createQuery(RegistryEntity.class);
Root<RegistryEntity> root = criteria.from(RegistryEntity.class);
List<Predicate> predList = new ArrayList<Predicate>();
for (RegistryStatus s : status)
predList.add(builder.equal(root.get("registryStatus"), s));
criteria.where(builder.and(
builder.equal(root.get("user"), user)),
builder.equal(root.get("registryStatus"), status));
builder.equal(root.get(RegistryEntity_.user), user),
builder.or(predList.toArray(new Predicate[]{}))));
criteria.select(root);
criteria.distinct(true);
criteria.orderBy(builder.asc(root.get("id")));
......
......@@ -30,7 +30,7 @@ public interface RegistryService extends BaseService<RegistryEntity, Long> {
RegistryStatus status);
List<RegistryEntity> findByUserAndStatus(UserEntity user,
RegistryStatus status);
RegistryStatus... status);
List<RegistryEntity> findByServiceAndUser(ServiceEntity service, UserEntity user);
......
......@@ -98,7 +98,7 @@ public class RegistryServiceImpl extends BaseServiceImpl<RegistryEntity, Long> i
}
@Override
public List<RegistryEntity> findByUserAndStatus(UserEntity user, RegistryStatus status) {
public List<RegistryEntity> findByUserAndStatus(UserEntity user, RegistryStatus... status) {
return dao.findByUserAndStatus(user, status);
}
......
......@@ -28,6 +28,7 @@ import edu.kit.scc.webreg.audit.UserUpdateAuditor;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.dao.AuditDetailDao;
import edu.kit.scc.webreg.dao.AuditEntryDao;
import edu.kit.scc.webreg.dao.RegistryDao;
import edu.kit.scc.webreg.dao.SamlIdpMetadataDao;
import edu.kit.scc.webreg.dao.SamlSpConfigurationDao;
import edu.kit.scc.webreg.dao.UserDao;
......@@ -35,6 +36,8 @@ import edu.kit.scc.webreg.dao.as.ASUserAttrDao;
import edu.kit.scc.webreg.entity.AuditStatus;
import edu.kit.scc.webreg.entity.EventType;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.RegistryStatus;
import edu.kit.scc.webreg.entity.SamlIdpMetadataEntity;
import edu.kit.scc.webreg.entity.SamlSpConfigurationEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
......@@ -83,6 +86,9 @@ public class UserUpdater implements Serializable {
@Inject
private ServiceService serviceService;
@Inject
private RegistryDao registryDao;
@Inject
private HomeOrgGroupUpdater homeOrgGroupUpdater;
......@@ -155,6 +161,16 @@ public class UserUpdater implements Serializable {
if (UserStatus.ACTIVE.equals(user.getUserStatus())) {
user.setUserStatus(UserStatus.ON_HOLD);
user.setLastStatusChange(new Date());
/*
* 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());
}
}
}
else {
......@@ -168,6 +184,17 @@ public class UserUpdater implements Serializable {
user.setUserStatus(UserStatus.ACTIVE);
user.setLastStatusChange(new Date());
/*
* Also reenable all registries for user to LOST_ACCESS.
* They are rechecked then
*/
List<RegistryEntity> registryList = registryDao.findByUserAndStatus(user,
RegistryStatus.ON_HOLD);
for (RegistryEntity registry : registryList) {
registry.setRegistryStatus(RegistryStatus.LOST_ACCESS);
registry.setLastStatusChange(new Date());
}
/*
* fire a user changed event to be sure, when the user is activated
*/
......
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