use of org.eclipse.jetty.server.session.AbstractSessionManager in project hadoop 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) {
threadPool.setMaxThreads(maxThreads);
}
SessionManager sm = webAppContext.getSessionHandler().getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.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 = new HashMap<>();
xFrameParams.put(X_FRAME_ENABLED, String.valueOf(this.xFrameOptionIsEnabled));
xFrameParams.put(X_FRAME_VALUE, this.xFrameOption.toString());
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.AbstractSessionManager in project hadoop by apache.
the class HttpServer2 method addDefaultApps.
/**
* Add default apps.
* @param appDir The application directory
* @throws IOException
*/
protected void addDefaultApps(ContextHandlerCollection parent, final String appDir, Configuration conf) throws IOException {
// 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();
SessionManager sm = handler.getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.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();
SessionManager sm = handler.getSessionManager();
if (sm instanceof AbstractSessionManager) {
AbstractSessionManager asm = (AbstractSessionManager) sm;
asm.setHttpOnly(true);
asm.getSessionCookieConfig().setSecure(true);
}
staticContext.setSessionHandler(handler);
setContextAttributes(staticContext, conf);
defaultContexts.put(staticContext, true);
}
use of org.eclipse.jetty.server.session.AbstractSessionManager in project coprhd-controller by CoprHD.
the class AuthenticationServerImpl method initServer.
@Override
protected void initServer() throws Exception {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
String authDocumentRoot = loader.getResource(AUTH_DOCUMENT_ROOT).toString();
_server = new Server();
initConnectors();
// Static Pages
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setWelcomeFiles(new String[] { "*" });
resourceHandler.setResourceBase(authDocumentRoot);
// AuthN servlet filters
ServletContextHandler rootHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
rootHandler.setContextPath("/");
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { resourceHandler, rootHandler });
_server.setHandler(handlerCollection);
((AbstractSessionManager) rootHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_secFilters));
rootHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
// Add the REST resources
if (_app != null) {
ResourceConfig config = new DefaultResourceConfig();
config.add(_app);
Map<String, MediaType> type = config.getMediaTypeMappings();
type.put("json", MediaType.APPLICATION_JSON_TYPE);
type.put("xml", MediaType.APPLICATION_XML_TYPE);
rootHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
}
// load trust store from file to zk. must do it before authmgr started, who holds the connection with ad.
loadTrustStoreFromLocalFiles();
_dbClient.start();
_tokenManager.init();
_authManager.init();
}
use of org.eclipse.jetty.server.session.AbstractSessionManager in project coprhd-controller by CoprHD.
the class TestWebServer method initServer.
/**
* Initialize server handlers, rest resources.
*
* @throws Exception
*/
private void initServer() throws Exception {
_server = new Server();
initConnectors();
// AuthN servlet filters
ServletContextHandler rootHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
rootHandler.setContextPath("/");
_server.setHandler(rootHandler);
((AbstractSessionManager) rootHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
// Add the REST resources
if (_app != null) {
ResourceConfig config = new DefaultResourceConfig();
config.add(_app);
Map<String, MediaType> type = config.getMediaTypeMappings();
type.put(MediaType.TEXT_PLAIN, MediaType.TEXT_PLAIN_TYPE);
rootHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
}
}
use of org.eclipse.jetty.server.session.AbstractSessionManager in project coprhd-controller by CoprHD.
the class AbstractSecuredWebServer method initServer.
/**
* Initialize server handlers, rest resources.
*
* @throws Exception
*/
protected void initServer() throws Exception {
_server = new Server();
initThreadPool();
initConnectors();
// AuthN servlet filters
servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setContextPath("/");
_server.setHandler(servletHandler);
((AbstractSessionManager) servletHandler.getSessionHandler().getSessionManager()).setUsingCookies(false);
if (_disabler != null) {
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_disablingFilter));
servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
_log.warn("security checks are disabled... skipped adding security filters");
} else {
final FilterHolder securityFilterHolder = new FilterHolder(new DelegatingFilterProxy(_secFilters));
servletHandler.addFilter(securityFilterHolder, "/*", FilterMapping.REQUEST);
}
// Add the REST resources
if (_app != null) {
ResourceConfig config = new DefaultResourceConfig();
config.add(_app);
Map<String, MediaType> type = config.getMediaTypeMappings();
type.put("json", MediaType.APPLICATION_JSON_TYPE);
type.put("xml", MediaType.APPLICATION_XML_TYPE);
type.put("octet-stream", MediaType.APPLICATION_OCTET_STREAM_TYPE);
type.put("form-data", MediaType.MULTIPART_FORM_DATA_TYPE);
servletHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
// AuthZ resource filters
Map<String, Object> props = new HashMap<String, Object>();
props.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, _resourceFilterFactory);
// Adding the ContainerResponseFilter
props.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, _responseFilter);
config.setPropertiesAndFeatures(props);
}
if (_dbClient != null) {
// Otherwise there could be a dependency loop between services.
if (startDbClientInBackground) {
_log.info("starting dbclient in background");
new Thread() {
public void run() {
_dbClient.start();
}
}.start();
} else {
_log.info("starting dbclient");
_dbClient.start();
}
}
}
Aggregations