Commit 20d3e7c1 authored by michael.simon's avatar michael.simon
Browse files

Update user and check rules, if last user update is older than 14 days

parent 1163ed10
......@@ -10,6 +10,7 @@
******************************************************************************/
package edu.kit.scc.webreg.job;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -19,10 +20,14 @@ import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.kit.scc.webreg.drools.KnowledgeSessionService;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.RegistryStatus;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.service.RegistryService;
import edu.kit.scc.webreg.service.UserService;
import edu.kit.scc.webreg.service.reg.RegisterUserService;
......@@ -44,21 +49,15 @@ public class DeregisterLostAccessRegistries extends AbstractExecutableJob {
}
Long lastUpdate = Long.parseLong(getJobStore().get("lost_access_since_millis"));
String ssn = getJobStore().get("service_short_name");
Integer limit;
Long lastUserUpdate = 14 * 24 * 60 * 60 * 1000L; // 14 days standard value
if (getJobStore().containsKey("last_user_update_millis"))
lastUserUpdate = Long.parseLong(getJobStore().get("last_user_update_millis"));
if (getJobStore().containsKey("registries_per_exec")) {
Integer limit = 1;
if (getJobStore().containsKey("registries_per_exec"))
limit = Integer.parseInt(getJobStore().get("registries_per_exec"));
}
else {
limit = 1;
}
String ssn = null;
if (getJobStore().containsKey("service_short_name")) {
ssn = getJobStore().get("service_short_name");
}
logger.info("Starting Deregister LostAccess Registries for {}", ssn);
......@@ -67,6 +66,9 @@ public class DeregisterLostAccessRegistries extends AbstractExecutableJob {
RegistryService registryService = (RegistryService) ic.lookup("global/bwreg/bwreg-service/RegistryServiceImpl!edu.kit.scc.webreg.service.RegistryService");
RegisterUserService registerUserService = (RegisterUserService) ic.lookup("global/bwreg/bwreg-service/RegisterUserServiceImpl!edu.kit.scc.webreg.service.reg.RegisterUserService");
UserService userService = (UserService) ic.lookup("global/bwreg/bwreg-service/UserServiceImpl!edu.kit.scc.webreg.service.UserService");
KnowledgeSessionService knowledgeSessionService = (KnowledgeSessionService) ic.lookup("global/bwreg/bwreg-service/KnowledgeSessionServiceImpl!edu.kit.scc.webreg.drools.KnowledgeSessionService");
List<RegistryEntity> registryList = registryService.findByServiceAndStatus(ssn, RegistryStatus.LOST_ACCESS,
new Date(System.currentTimeMillis() - lastUpdate), limit);
......@@ -77,7 +79,29 @@ public class DeregisterLostAccessRegistries extends AbstractExecutableJob {
for (RegistryEntity registry : registryList) {
try {
logger.info("Deregister Registry {}", registry.getId());
registerUserService.deregisterUser(registry, "lost-access-reg-job");
UserEntity user = registry.getUser();
if ((System.currentTimeMillis() - user.getLastUpdate().getTime()) > lastUserUpdate) {
// user is too old, try update first
logger.info("User {} lastUpdate is older than {}ms. Trying update", user.getEppn(), lastUserUpdate);
try {
userService.updateUserFromIdp(user);
} catch (UserUpdateException e) {
logger.info("Exception while Querying IDP: {}", e.getMessage());
if (e.getCause() != null) {
logger.info("Cause is: {}", e.getCause().getMessage());
if (e.getCause().getCause() != null) {
logger.info("Inner Cause is: {}", e.getCause().getCause().getMessage());
}
}
}
List<RegistryEntity> tempRegistryList = new ArrayList<RegistryEntity>();
tempRegistryList.add(registry);
knowledgeSessionService.checkRules(tempRegistryList, user, "lost-access-reg-job", false);
}
if (RegistryStatus.LOST_ACCESS.equals(registry.getRegistryStatus())) {
registerUserService.deregisterUser(registry, "lost-access-reg-job");
}
} catch (RegisterException e) {
logger.info("Could not deregister", e);
}
......
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