diff --git a/ccm-bundle-devel-wildfly-web/src/main/resources/log4j2.xml b/ccm-bundle-devel-wildfly-web/src/main/resources/log4j2.xml
index c58bb8918..340d8d223 100644
--- a/ccm-bundle-devel-wildfly-web/src/main/resources/log4j2.xml
+++ b/ccm-bundle-devel-wildfly-web/src/main/resources/log4j2.xml
@@ -29,14 +29,15 @@
-
+
+
-
\ No newline at end of file
diff --git a/ccm-core/src/main/java/org/libreccm/security/OneTimeAuthTokenCleaner.java b/ccm-core/src/main/java/org/libreccm/security/OneTimeAuthTokenCleaner.java
index 87012a0d8..87bf24fec 100644
--- a/ccm-core/src/main/java/org/libreccm/security/OneTimeAuthTokenCleaner.java
+++ b/ccm-core/src/main/java/org/libreccm/security/OneTimeAuthTokenCleaner.java
@@ -18,33 +18,40 @@
*/
package org.libreccm.security;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.libreccm.configuration.ConfigurationManager;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
+import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
import javax.inject.Inject;
-import javax.inject.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
/**
- * This EJB uses the {@link TimerService} to run a cleanup task periodically to
- * remove all expired {@link OneTimeAuthToken}s. The task period is the same
- * as the time a {@link OneTimeAuthToken} is valid.
- *
+ * This EJB uses the {@link TimerService} to run a cleanup task periodically to
+ * remove all expired {@link OneTimeAuthToken}s. The task period is the same as
+ * the time a {@link OneTimeAuthToken} is valid.
+ *
* @author Jens Pelzetter
*/
-@Singleton
@Startup
+@Singleton
public class OneTimeAuthTokenCleaner {
+ private static final Logger LOGGER = LogManager.getLogger(
+ OneTimeAuthTokenCleaner.class);
+
@Resource
private TimerService timerService;
@@ -59,24 +66,50 @@ public class OneTimeAuthTokenCleaner {
@PostConstruct
public void init() {
+ LOGGER.debug("Initialising OneTimeAuthTokenCleaner...");
final OneTimeAuthConfig config = configurationManager.findConfiguration(
OneTimeAuthConfig.class);
final long interval = config.getTokenValid() * 1000;
+// final long interval = 60 * 60 * 1000;
+ LOGGER.debug("Creating interval for {} s.", interval / 1000);
timerService.createIntervalTimer(interval, interval, new TimerConfig());
}
@Timeout
@Transactional(Transactional.TxType.REQUIRED)
public void cleanupTokens() {
+ LOGGER.debug("Cleaning up one time auth tokens...");
final TypedQuery query = entityManager.createQuery(
"SELECT t FROM OneTimeAuthToken t", OneTimeAuthToken.class);
final List tokens = query.getResultList();
+ LOGGER.debug("Found {} one time auth tokens.", tokens.size());
+ if (LOGGER.isDebugEnabled()) {
+ final LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC);
+ LOGGER.debug("Current time is: {}", now);
+ tokens.forEach(t -> {
+ if (oneTimeAuthManager.isValid(t)) {
+ LOGGER.debug("OneTimeAuthToken with id {} is still valid. "
+ + "Expires at {}.",
+ t.getTokenId(),
+ t.getValidUntil());
+ } else {
+ LOGGER.debug("OneTimeAuthToken with id {} is invalid. "
+ + "Expires at {}.",
+ t.getTokenId(),
+ t.getValidUntil());
+ }
+ });
+ }
+
tokens.stream()
.filter((token) -> (!oneTimeAuthManager.isValid(token)))
.forEach((token) -> {
+ LOGGER.debug("Token with id {} expired at {}. "
+ + "Invalidating token.",
+ token.getTokenId(), token.getValidUntil());
oneTimeAuthManager.invalidate(token);
});
}