public void invalidateAll(String sessionId) { synchronized (sessionsIds) { sessionsIds.remove(sessionId); //tell all contexts that may have a session object with this id to //get rid of them Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof HazelcastSessionManager) { ((HazelcastSessionManager) manager).invalidateSession(sessionId); } } } } }
@Override public void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request) { //generate a new id String newClusterId = newSessionId(request.hashCode()); synchronized (sessionsIds) { //remove the old one from the list sessionsIds.remove(oldClusterId); //add in the new session id to the list sessionsIds.add(newClusterId); //tell all contexts to update the id Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof HazelcastSessionManager) { ((HazelcastSessionManager) manager). renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request)); } } } } }
@Override public void invalidateAll(String sessionId) { synchronized (sessionsIds) { sessionsIds.remove(sessionId); //tell all contexts that may have a session object with this id to //get rid of them Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof HazelcastSessionManager) { ((HazelcastSessionManager) manager).invalidateSession(sessionId); } } } } }
@Override public HttpServer listen(int port) throws Exception { SessionHandler sessionHandler = new SessionHandler(app.configuration(SessionManager.class)); sessionHandler.setHandler(new MiddlewareHandler(app)); ContextHandler context = new ContextHandler(); context.setContextPath("/"); context.setResourceBase("."); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.setHandler(sessionHandler); Server server = new Server(port); server.setSessionIdManager(new HashSessionIdManager()); server.setHandler(context); server.start(); server.join(); return this; }
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; }
private void configureSession(WebAppContext context) { SessionManager sessionManager = context.getSessionHandler().getSessionManager(); int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1); sessionManager.setMaxInactiveInterval(sessionTimeout); if (isPersistSession()) { Assert.isInstanceOf(HashSessionManager.class, sessionManager, "Unable to use persistent sessions"); configurePersistSession(sessionManager); } }
private void configurePersistSession(SessionManager sessionManager) { try { ((HashSessionManager) sessionManager) .setStoreDirectory(getValidSessionStoreDir()); } catch (IOException ex) { throw new IllegalStateException(ex); } }
public static void main(String[] args) throws Exception { new Thread(new Crawler()).start();// hourly JodelWebConfiguration conf; if (args.length != 1) { InputStream ins; File confFile = new File("conf/jodel.properties"); if (confFile.exists()) { ins = new FileInputStream(confFile); } else { ins = Launcher.class.getResourceAsStream("jodel.properties"); } conf = new JodelWebConfiguration(ins); } else { conf = new JodelWebConfiguration(new FileInputStream(new File( args[0]))); } DatabaseConnection.init(conf); Server s = new Server(new InetSocketAddress(conf.getHostName(), conf.getPort())); ((QueuedThreadPool) s.getThreadPool()).setMaxThreads(20); ServletContextHandler h = new ServletContextHandler( ServletContextHandler.SESSIONS); h.setInitParameter(SessionManager.__SessionCookieProperty, "Jodel-Session"); h.addServlet(JodelWeb.class, "/*"); HandlerList hl = new HandlerList(); hl.setHandlers(new Handler[] { generateStaticContext(), h }); s.setHandler(hl); s.start(); }
protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception { context.setContextPath("/"); SessionManager sm = new HashSessionManager(); SessionHandler sh = new SessionHandler(sm); context.setSessionHandler(sh); if (home != null) { String[] resources = home.split(":"); if (LOG.isDebugEnabled()) { LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]); } if (resources[0].equals("classpath")) { // Does not work when deployed as a bundle // context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1])); URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]); context.setBaseResource(Resource.newResource(url)); } else if (resources[0].equals("file")) { context.setBaseResource(Resource.newResource(resources[1])); } DefaultServlet defaultServlet = new DefaultServlet(); ServletHolder holder = new ServletHolder(defaultServlet); // avoid file locking on windows // http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages holder.setInitParameter("useFileMappedBuffer", "false"); context.addServlet(holder, "/"); } server.setHandler(context); return server; }
private void forEachSessionManager(final SessionManagerCallback callback) { Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { final SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { final SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof AbstractSessionManager) { callback.execute((AbstractSessionManager) manager); } } } }
/** * Set the secure cookies setting on the jetty session manager. */ protected void setSecureCookies() { SessionManager sessionManager = webapp.getSessionHandler().getSessionManager(); if (!(sessionManager instanceof AbstractSessionManager)) { throw new RuntimeException("Cannot set secure cookies on session manager."); } AbstractSessionManager abstractSessionManager = (AbstractSessionManager) sessionManager; abstractSessionManager.getSessionCookieConfig().setSecure(isSecureCookies()); abstractSessionManager.setHttpOnly(true); }
@Override public void configure(ConfigurableApp<Pipes> app) { app.configure(SessionManager.class, HashSessionManager::new, SessionManagerConfig::configure); app.configure(ObjectMapper.class, JacksonJsonConfig::configure); app.configure((LoggerContext) LoggerFactory.getILoggerFactory(), LogbackConfig::configure); app.configure(org.hibernate.cfg.Configuration.class, HibernateConfig::configure); }
@Override public void setSessionConfig() { SessionManager sessionManager = webAppContext.getSessionHandler().getSessionManager(); SessionCookieConfig sessionCookieConfig = sessionManager.getSessionCookieConfig(); sessionCookieConfig.setHttpOnly(true); sessionCookieConfig.setSecure(systemEnvironment.isSessionCookieSecure()); sessionCookieConfig.setMaxAge(systemEnvironment.sessionCookieMaxAgeInSeconds()); sessionManager.setMaxInactiveInterval(systemEnvironment.sessionTimeoutInSeconds()); }
public static void main(String[] args) throws Exception { LiteWaveWebConfigurator conf; if (args.length != 1) { InputStream ins; File confFile = new File("conf/litewave.properties"); ins = new FileInputStream(confFile); conf = new LiteWaveWebConfigurator(ins); } else { conf = new LiteWaveWebConfigurator(new FileInputStream(new File( args[0]))); } DatabaseConnection.init(conf); Server s = new Server(new InetSocketAddress(conf.getHostName(), conf.getPort())); System.out.println("start Server"); ((QueuedThreadPool) s.getThreadPool()).setMaxThreads(20); ServletContextHandler h = new ServletContextHandler( ServletContextHandler.SESSIONS); h.setInitParameter(SessionManager.__SessionCookieProperty, "DB-Session"); h.addServlet(LiteWaveMain.class, "/*"); HandlerList hl = new HandlerList(); hl.setHandlers(new Handler[] { generateStaticContext(), h }); s.setHandler(hl); s.start(); //For intel systems (OmniDriver Initialization /* ExecutorService executor = Executors.newSingleThreadExecutor(); try { executor.submit(new InitSpectrometer()).get(1800, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e1) { System.out.println("Timeout: USB driver not Initialized"); e1.printStackTrace(); } // Timeout of 10 minutes. executor.shutdown(); */ }
public AbstractApp() { configs.put(getKey(SessionManager.class, null), new HashSessionManager()); configs.put(getKey(ObjectMapper.class, null), configureObjectMapper(new ObjectMapper())); configs.put(getKey(ObjectMapper.class, XML_MAPPER_NAME), configureObjectMapper(new ObjectMapper())); }