use of org.eclipse.jetty.server.session.JDBCSessionDataStoreFactory in project traccar by tananaev.
the class WebServer method initSessionConfig.
private void initSessionConfig(Config config, ServletContextHandler servletHandler) {
if (config.getBoolean(Keys.WEB_PERSIST_SESSION)) {
DatabaseAdaptor databaseAdaptor = new DatabaseAdaptor();
databaseAdaptor.setDatasource(Context.getDataManager().getDataSource());
JDBCSessionDataStoreFactory jdbcSessionDataStoreFactory = new JDBCSessionDataStoreFactory();
jdbcSessionDataStoreFactory.setDatabaseAdaptor(databaseAdaptor);
SessionHandler sessionHandler = servletHandler.getSessionHandler();
SessionCache sessionCache = new DefaultSessionCache(sessionHandler);
sessionCache.setSessionDataStore(jdbcSessionDataStoreFactory.getSessionDataStore(sessionHandler));
sessionHandler.setSessionCache(sessionCache);
}
int sessionTimeout = config.getInteger(Keys.WEB_SESSION_TIMEOUT);
if (sessionTimeout > 0) {
servletHandler.getSessionHandler().setMaxInactiveInterval(sessionTimeout);
}
String sameSiteCookie = config.getString(Keys.WEB_SAME_SITE_COOKIE);
if (sameSiteCookie != null) {
SessionCookieConfig sessionCookieConfig = servletHandler.getServletContext().getSessionCookieConfig();
switch(sameSiteCookie.toLowerCase()) {
case "lax":
sessionCookieConfig.setComment(HttpCookie.SAME_SITE_LAX_COMMENT);
break;
case "strict":
sessionCookieConfig.setComment(HttpCookie.SAME_SITE_STRICT_COMMENT);
break;
case "none":
sessionCookieConfig.setSecure(true);
sessionCookieConfig.setComment(HttpCookie.SAME_SITE_NONE_COMMENT);
break;
default:
break;
}
}
}
Aggregations