Commit 14012f4d authored by michael.simon's avatar michael.simon
Browse files

OnHold Check Registries

parent dbd6d214
......@@ -15,6 +15,7 @@ import java.util.List;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
public interface UserDao extends BaseDao<UserEntity, Long> {
......@@ -29,4 +30,5 @@ public interface UserDao extends BaseDao<UserEntity, Long> {
List<UserEntity> findOrderByUpdatedWithLimit(Date date, Integer limit);
List<UserEntity> findGenericStoreKeyWithLimit(String key, Integer limit);
List<UserEntity> findOrderByFailedUpdateWithLimit(Date date, Integer limit);
List<UserEntity> findByStatus(UserStatus status);
}
......@@ -25,6 +25,7 @@ import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.UserDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
@Named
@ApplicationScoped
......@@ -114,6 +115,16 @@ public class JpaUserDao extends JpaBaseDao<UserEntity, Long> implements UserDao,
}
}
@Override
public List<UserEntity> findByStatus(UserStatus status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<UserEntity> criteria = builder.createQuery(UserEntity.class);
Root<UserEntity> user = criteria.from(UserEntity.class);
criteria.where(builder.equal(user.get("userStatus"), status));
criteria.select(user);
return em.createQuery(criteria).getResultList();
}
@Override
public UserEntity findByIdWithAll(Long id) {
CriteriaBuilder builder = em.getCriteriaBuilder();
......
/*******************************************************************************
* 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.job;
import java.util.List;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.service.UserService;
public class OnHoldUserRegistryCheck extends AbstractExecutableJob {
private static final long serialVersionUID = 1L;
@Override
public void execute() {
Logger logger = LoggerFactory.getLogger(OnHoldUserRegistryCheck.class);
logger.info("Starting Checking ON_HOLD user registries");
try {
InitialContext ic = new InitialContext();
UserService userService = (UserService) ic.lookup("global/bwreg/bwreg-service/UserServiceImpl!edu.kit.scc.webreg.service.UserService");
List<UserEntity> userList = userService.findByStatus(UserStatus.ON_HOLD);
for (UserEntity user : userList) {
logger.info("Checking user {}", user.getEppn());
userService.checkOnHoldRegistries(user);
}
} catch (NamingException e) {
logger.warn("Could not Deregister Invald Registries: {}", e);
}
}
}
......@@ -18,6 +18,7 @@ import edu.kit.scc.webreg.audit.Auditor;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.exc.UserUpdateException;
public interface UserService extends BaseService<UserEntity, Long> {
......@@ -56,4 +57,8 @@ public interface UserService extends BaseService<UserEntity, Long> {
UserEntity updateUserFromAttribute(UserEntity user,
Map<String, List<Object>> attributeMap, String executor)
throws UserUpdateException;
List<UserEntity> findByStatus(UserStatus status);
void checkOnHoldRegistries(UserEntity user);
}
......@@ -23,12 +23,16 @@ import org.slf4j.Logger;
import edu.kit.scc.webreg.audit.Auditor;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.RegistryDao;
import edu.kit.scc.webreg.dao.SamlIdpMetadataDao;
import edu.kit.scc.webreg.dao.UserDao;
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.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.service.UserService;
......@@ -49,6 +53,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement
@Inject
private UserUpdater userUpdater;
@Inject
private RegistryDao registryDao;
@Override
public List<UserEntity> findOrderByUpdatedWithLimit(Date date, Integer limit) {
return dao.findOrderByUpdatedWithLimit(date, limit);
......@@ -79,6 +86,11 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement
return dao.findByEppn(eppn);
}
@Override
public List<UserEntity> findByStatus(UserStatus status) {
return dao.findByStatus(status);
}
@Override
public UserEntity findByIdWithAll(Long id) {
return dao.findByIdWithAll(id);
......@@ -125,6 +137,19 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement
return dao;
}
@Override
public void checkOnHoldRegistries(UserEntity user) {
if (user.getUserStatus().equals(UserStatus.ON_HOLD)) {
List<RegistryEntity> registryList = registryDao.findByUserAndStatus(user,
RegistryStatus.ACTIVE, RegistryStatus.LOST_ACCESS, RegistryStatus.INVALID);
for (RegistryEntity registry : registryList) {
logger.debug("Setting registry {} (user {}) ON_HOLD", registry.getId(), user.getEppn());
registry.setRegistryStatus(RegistryStatus.ON_HOLD);
registry.setLastStatusChange(new Date());
}
}
}
@Override
public void convertLegacyUsers() {
List<UserEntity> userList = dao.findLegacyUsers();
......
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