mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
support for Java9+ (#906)
* initial java9+ support * restore session management, updated for jetty 9.4 * Session actually implements EntityManager * reusable method for setting the timeout
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.commafeed.frontend.session;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
|
||||
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
||||
import org.eclipse.jetty.server.session.FileSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionCache;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import io.dropwizard.util.Duration;
|
||||
|
||||
public class SessionHandlerFactory {
|
||||
|
||||
private String path = "sessions";
|
||||
private Duration cookieRefreshAge = Duration.days(1);
|
||||
private Duration maxInactiveInterval = Duration.days(30);
|
||||
private Duration savePeriod = Duration.minutes(5);
|
||||
|
||||
public SessionHandler build() {
|
||||
SessionHandler sessionHandler = new SessionHandler();
|
||||
SessionCache sessionCache = new DefaultSessionCache(sessionHandler);
|
||||
sessionHandler.setSessionCache(sessionCache);
|
||||
FileSessionDataStore dataStore = new FileSessionDataStore();
|
||||
sessionCache.setSessionDataStore(dataStore);
|
||||
|
||||
sessionHandler.setHttpOnly(true);
|
||||
sessionHandler.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE));
|
||||
sessionHandler.setMaxInactiveInterval((int) maxInactiveInterval.toSeconds());
|
||||
sessionHandler.setRefreshCookieAge((int) cookieRefreshAge.toSeconds());
|
||||
|
||||
dataStore.setDeleteUnrestorableFiles(true);
|
||||
dataStore.setStoreDir(new File(path));
|
||||
dataStore.setSavePeriodSec((int) savePeriod.toSeconds());
|
||||
|
||||
return sessionHandler;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.commafeed.frontend.session;
|
||||
|
||||
import io.dropwizard.util.Duration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import org.eclipse.jetty.server.SessionManager;
|
||||
import org.eclipse.jetty.server.session.HashSessionManager;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@Getter
|
||||
public class SessionManagerFactory {
|
||||
|
||||
private String path = "sessions";
|
||||
private Duration cookieMaxAge = Duration.days(30);
|
||||
private Duration cookieRefreshAge = Duration.days(1);
|
||||
private Duration maxInactiveInterval = Duration.days(30);
|
||||
private Duration idleSavePeriod = Duration.hours(2);
|
||||
private Duration savePeriod = Duration.minutes(5);
|
||||
private Duration scavengePeriod = Duration.minutes(5);
|
||||
|
||||
public SessionManager build() throws IOException {
|
||||
HashSessionManager manager = new HashSessionManager();
|
||||
manager.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE));
|
||||
manager.setHttpOnly(true);
|
||||
manager.getSessionCookieConfig().setHttpOnly(true);
|
||||
manager.setDeleteUnrestorableSessions(true);
|
||||
|
||||
manager.setStoreDirectory(new File(getPath()));
|
||||
manager.getSessionCookieConfig().setMaxAge((int) cookieMaxAge.toSeconds());
|
||||
manager.setRefreshCookieAge((int) cookieRefreshAge.toSeconds());
|
||||
manager.setMaxInactiveInterval((int) maxInactiveInterval.toSeconds());
|
||||
manager.setIdleSavePeriod((int) idleSavePeriod.toSeconds());
|
||||
manager.setSavePeriod((int) savePeriod.toSeconds());
|
||||
manager.setScavengePeriod((int) scavengePeriod.toSeconds());
|
||||
return manager;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user