use of org.eclipse.jetty.server.session.SessionHandler in project structr by structr.
the class SessionHelper method invalidateSession.
public static synchronized void invalidateSession(final HttpSession session) {
if (session != null) {
final String sessionId = session.getId();
try {
final SessionCache sessionCache = Services.getInstance().getService(HttpService.class).getSessionCache();
synchronized (sessionCache) {
SessionHandler handler = sessionCache.getSessionHandler();
handler.clearEventListeners();
handler.removeSession(sessionId, true);
}
} catch (final Exception ex) {
logger.warn("Invalidating session failed: {}", sessionId);
}
}
}
use of org.eclipse.jetty.server.session.SessionHandler in project neo4j by neo4j.
the class Jetty9WebServer method loadJaxRsResource.
private void loadJaxRsResource(String mountPoint) {
log.debug("Mounting servlet at [%s]", mountPoint);
SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setServer(getJetty());
JaxRsServletHolderFactory jaxRsServletHolderFactory = jaxRsServletHolderFactories.get(mountPoint);
ServletContextHandler jerseyContext = new ServletContextHandler();
jerseyContext.setServer(getJetty());
jerseyContext.setErrorHandler(new NeoJettyErrorHandler());
jerseyContext.setContextPath(mountPoint);
jerseyContext.setSessionHandler(sessionHandler);
jerseyContext.addServlet(jaxRsServletHolderFactory.create(binder, wadlEnabled), "/*");
addFiltersTo(jerseyContext);
handlers.addHandler(jerseyContext);
}
use of org.eclipse.jetty.server.session.SessionHandler in project drill by apache.
the class WebServer method createSessionHandler.
/**
* Create a {@link SessionHandler}
*
* @param securityHandler Set of init parameters that are used by the Authentication
* @return session handler
*/
private SessionHandler createSessionHandler(final SecurityHandler securityHandler) {
SessionHandler sessionHandler = new SessionHandler();
// SessionManager sessionManager = new HashSessionManager();
sessionHandler.setMaxInactiveInterval(config.getInt(ExecConstants.HTTP_SESSION_MAX_IDLE_SECS));
// response cookie will be returned with HttpOnly flag
sessionHandler.getSessionCookieConfig().setHttpOnly(true);
sessionHandler.addEventListener(new HttpSessionListener() {
@Override
public void sessionCreated(HttpSessionEvent se) {
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
final HttpSession session = se.getSession();
if (session == null) {
return;
}
final Object authCreds = session.getAttribute(SessionAuthentication.__J_AUTHENTICATED);
if (authCreds != null) {
final SessionAuthentication sessionAuth = (SessionAuthentication) authCreds;
securityHandler.logout(sessionAuth);
session.removeAttribute(SessionAuthentication.__J_AUTHENTICATED);
}
// Clear all the resources allocated for this session
final WebSessionResources webSessionResources = (WebSessionResources) session.getAttribute(WebSessionResources.class.getSimpleName());
if (webSessionResources != null) {
webSessionResources.close();
session.removeAttribute(WebSessionResources.class.getSimpleName());
}
}
});
return sessionHandler;
}
use of org.eclipse.jetty.server.session.SessionHandler in project knox by apache.
the class HttpServer2 method initializeWebServer.
private void initializeWebServer(String name, String hostName, Configuration conf, String[] pathSpecs) throws IOException {
Preconditions.checkNotNull(webAppContext);
int maxThreads = conf.getInt(HTTP_MAX_THREADS_KEY, -1);
// If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the
// default value (currently 250).
QueuedThreadPool threadPool = (QueuedThreadPool) webServer.getThreadPool();
threadPool.setDaemon(true);
if (maxThreads != -1) {
// Minimum number of threads must be > 3.
// DatanodeHttpServer sets the HTTP_MAX_THREADS_KEY to 3
threadPool.setMaxThreads(Math.max(maxThreads, 4));
}
SessionHandler sessionHandler = webAppContext.getSessionHandler();
sessionHandler.setHttpOnly(true);
sessionHandler.getSessionCookieConfig().setSecure(true);
ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLog requestLog = HttpRequestLog.getRequestLog(name);
handlers.addHandler(contexts);
if (requestLog != null) {
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
handlers.addHandler(requestLogHandler);
}
handlers.addHandler(webAppContext);
final String appDir = getWebAppsPath(name);
addDefaultApps(contexts, appDir, conf);
webServer.setHandler(handlers);
Map<String, String> xFrameParams = setHeaders(conf);
addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams);
final FilterInitializer[] initializers = getFilterInitializers(conf);
if (initializers != null) {
conf = new Configuration(conf);
conf.set(BIND_ADDRESS, hostName);
for (FilterInitializer c : initializers) {
c.initFilter(this, conf);
}
}
addDefaultServlets();
if (pathSpecs != null) {
for (String path : pathSpecs) {
LOG.info("adding path spec: " + path);
addFilterPathMapping(path, webAppContext);
}
}
}
use of org.eclipse.jetty.server.session.SessionHandler in project knox by apache.
the class HttpServer2 method addDefaultApps.
/*
* Add default apps.
* @param appDir The application directory
*/
protected void addDefaultApps(ContextHandlerCollection parent, final String appDir, Configuration conf) {
// set up the context for "/logs/" if "hadoop.log.dir" property is defined
// and it's enabled.
String logDir = System.getProperty("hadoop.log.dir");
boolean logsEnabled = conf.getBoolean(CommonConfigurationKeys.HADOOP_HTTP_LOGS_ENABLED, CommonConfigurationKeys.HADOOP_HTTP_LOGS_ENABLED_DEFAULT);
if (logDir != null && logsEnabled) {
ServletContextHandler logContext = new ServletContextHandler(parent, "/logs");
logContext.setResourceBase(logDir);
logContext.addServlet(AdminAuthorizedServlet.class, "/*");
if (conf.getBoolean(CommonConfigurationKeys.HADOOP_JETTY_LOGS_SERVE_ALIASES, CommonConfigurationKeys.DEFAULT_HADOOP_JETTY_LOGS_SERVE_ALIASES)) {
@SuppressWarnings("unchecked") Map<String, String> params = logContext.getInitParams();
params.put("org.eclipse.jetty.servlet.Default.aliases", "true");
}
logContext.setDisplayName("logs");
SessionHandler handler = new SessionHandler();
handler.setHttpOnly(true);
handler.getSessionCookieConfig().setSecure(true);
logContext.setSessionHandler(handler);
setContextAttributes(logContext, conf);
addNoCacheFilter(logContext);
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
ServletContextHandler staticContext = new ServletContextHandler(parent, "/static");
staticContext.setResourceBase(appDir + "/static");
staticContext.addServlet(DefaultServlet.class, "/*");
staticContext.setDisplayName("static");
@SuppressWarnings("unchecked") Map<String, String> params = staticContext.getInitParams();
params.put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
params.put("org.eclipse.jetty.servlet.Default.gzip", "true");
SessionHandler handler = new SessionHandler();
handler.setHttpOnly(true);
handler.getSessionCookieConfig().setSecure(true);
staticContext.setSessionHandler(handler);
setContextAttributes(staticContext, conf);
defaultContexts.put(staticContext, true);
}
Aggregations