use of org.eclipse.jetty.server.session.SessionHandler in project XRTB by benmfaul.
the class Handler method run.
/**
* Starts the JETTY server
*/
public void run() {
Server server = new Server(port);
Handler handler = new Handler();
try {
// org.eclipse.jetty.server.session.SessionHandler
SessionHandler sh = new SessionHandler();
sh.addEventListener(new CustomListener());
sh.setHandler(handler);
server.setHandler(sh);
server.start();
server.join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.eclipse.jetty.server.session.SessionHandler in project XRTB by benmfaul.
the class AddShutdownHook method startSeparateAdminServer.
/**
* Start a different handler for control and reporting functions
*
* @throws Exception
* if SSL is specified but is not configured
*/
void startSeparateAdminServer() throws Exception {
SSL ssl = Configuration.getInstance().ssl;
QueuedThreadPool threadPool = new QueuedThreadPool(threads, 50);
Server server = new Server(threadPool);
ServerConnector connector;
if (Configuration.getInstance().adminPort == 0)
return;
logger.info("Admin functions are available on port: {}", Configuration.getInstance().adminPort);
if (!Configuration.getInstance().adminSSL) {
// adminPort
connector = new ServerConnector(server);
connector.setPort(Configuration.getInstance().adminPort);
connector.setIdleTimeout(60000);
server.setConnectors(new Connector[] { connector });
} else {
if (config.getInstance().ssl == null) {
throw new Exception("Admin port set to SSL but no SSL credentials are configured.");
}
logger.info("Admin functions are available by SSL only");
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(ssl.setKeyStorePath);
sslContextFactory.setKeyStorePassword(ssl.setKeyStorePassword);
sslContextFactory.setKeyManagerPassword(ssl.setKeyManagerPassword);
ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https));
sslConnector.setPort(Configuration.getInstance().adminPort);
server.setConnectors(new Connector[] { sslConnector });
}
adminHandler = new AdminHandler();
// org.eclipse.jetty.server.session.SessionHandler
SessionHandler sh = new SessionHandler();
sh.setHandler(adminHandler);
// set session handle
server.setHandler(sh);
server.start();
server.join();
}
use of org.eclipse.jetty.server.session.SessionHandler in project jena by apache.
the class ExFusekiMain_2_AddShiro method addShiroFilter.
// From Barry Nouwt : https://lists.apache.org/thread.html/r1e3fa952ff9f4a9108e16f07f1edf78c67e08c9b081497c627e3b833%40%3Cusers.jena.apache.org%3E
public static void addShiroFilter(FusekiServer fusekiServer) {
Server jettyServer = fusekiServer.getJettyServer();
ServletContextHandler servletContextHandler = (ServletContextHandler) jettyServer.getHandler();
ServletHandler servletHandler = servletContextHandler.getServletHandler();
// for shiro
EnvironmentLoaderListener ell = new EnvironmentLoaderListener();
servletContextHandler.addEventListener(ell);
// Copies
List<FilterMapping> mappings = new ArrayList<FilterMapping>(Arrays.asList(servletHandler.getFilterMappings()));
List<FilterHolder> holders = new ArrayList<FilterHolder>(Arrays.asList(servletHandler.getFilters()));
{
// add Shiro Filter and mapping
FilterHolder holder1 = new FilterHolder();
holder1.setFilter(new ShiroFilter());
FilterMapping mapping1 = new FilterMapping();
mapping1.setFilterName(holder1.getName());
mapping1.setPathSpec("/*");
mapping1.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
mappings.add(0, mapping1);
holders.add(0, holder1);
}
FilterMapping[] mappings3 = new FilterMapping[mappings.size()];
mappings3 = mappings.toArray(mappings3);
FilterHolder[] holders3 = new FilterHolder[holders.size()];
holders3 = holders.toArray(holders3);
servletHandler.setFilters(holders3);
servletHandler.setFilterMappings(mappings3);
// Specify the Session ID Manager
SessionIdManager idmanager = new DefaultSessionIdManager(jettyServer);
jettyServer.setSessionIdManager(idmanager);
// Specify the session handler
SessionHandler sessionsHandler = new SessionHandler();
sessionsHandler.setUsingCookies(false);
servletHandler.setHandler(sessionsHandler);
}
use of org.eclipse.jetty.server.session.SessionHandler in project spring-boot by spring-projects.
the class JettyServletWebServerFactory method configureSession.
private void configureSession(WebAppContext context) {
SessionHandler handler = context.getSessionHandler();
SameSite sessionSameSite = getSession().getCookie().getSameSite();
if (sessionSameSite != null) {
handler.setSameSite(HttpCookie.SameSite.valueOf(sessionSameSite.name()));
}
Duration sessionTimeout = getSession().getTimeout();
handler.setMaxInactiveInterval(isNegative(sessionTimeout) ? -1 : (int) sessionTimeout.getSeconds());
if (getSession().isPersistent()) {
DefaultSessionCache cache = new DefaultSessionCache(handler);
FileSessionDataStore store = new FileSessionDataStore();
store.setStoreDir(getValidSessionStoreDir());
cache.setSessionDataStore(store);
handler.setSessionCache(cache);
}
}
use of org.eclipse.jetty.server.session.SessionHandler 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