Search in sources :

Example 56 with SessionHandler

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();
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Server(org.eclipse.jetty.server.Server) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) CustomListener(com.xrtb.bidder.CustomListener) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 57 with SessionHandler

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();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) SSL(com.xrtb.common.SSL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 58 with SessionHandler

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);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) EnvironmentLoaderListener(org.apache.shiro.web.env.EnvironmentLoaderListener) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) Server(org.eclipse.jetty.server.Server) ArrayList(java.util.ArrayList) FilterMapping(org.eclipse.jetty.servlet.FilterMapping) SessionIdManager(org.eclipse.jetty.server.SessionIdManager) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ShiroFilter(org.apache.shiro.web.servlet.ShiroFilter)

Example 59 with SessionHandler

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);
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) DefaultSessionCache(org.eclipse.jetty.server.session.DefaultSessionCache) SameSite(org.springframework.boot.web.server.Cookie.SameSite) Duration(java.time.Duration) FileSessionDataStore(org.eclipse.jetty.server.session.FileSessionDataStore)

Example 60 with SessionHandler

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;
        }
    }
}
Also used : DatabaseAdaptor(org.eclipse.jetty.server.session.DatabaseAdaptor) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) DefaultSessionCache(org.eclipse.jetty.server.session.DefaultSessionCache) SessionCookieConfig(javax.servlet.SessionCookieConfig) DefaultSessionCache(org.eclipse.jetty.server.session.DefaultSessionCache) SessionCache(org.eclipse.jetty.server.session.SessionCache) JDBCSessionDataStoreFactory(org.eclipse.jetty.server.session.JDBCSessionDataStoreFactory)

Aggregations

SessionHandler (org.eclipse.jetty.server.session.SessionHandler)70 Server (org.eclipse.jetty.server.Server)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)17 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)13 IOException (java.io.IOException)10 Test (org.junit.Test)9 ServletException (javax.servlet.ServletException)8 HttpSession (javax.servlet.http.HttpSession)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 HashSessionManager (org.eclipse.jetty.server.session.HashSessionManager)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Handler (org.eclipse.jetty.server.Handler)5 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 ArrayList (java.util.ArrayList)4 SessionCookieConfig (javax.servlet.SessionCookieConfig)4 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)4 HttpSessionListener (javax.servlet.http.HttpSessionListener)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4