use of org.eclipse.jetty.servlet.FilterHolder in project gravitee-management-rest-api by gravitee-io.
the class JettyEmbeddedContainer method doStart.
@Override
protected void doStart() throws Exception {
AbstractHandler noContentHandler = new NoContentOutputErrorHandler();
// This part is needed to avoid WARN while starting container.
noContentHandler.setServer(server);
server.addBean(noContentHandler);
// Create the servlet context
final ServletContextHandler context = new ServletContextHandler(server, "/management/*", ServletContextHandler.SESSIONS);
// REST configuration
final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
servletHolder.setInitParameter("javax.ws.rs.Application", GraviteeApplication.class.getName());
servletHolder.setInitOrder(0);
context.addServlet(servletHolder, "/*");
// Spring configuration
System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "basic");
AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
webApplicationContext.register(SecurityConfiguration.class);
webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
webApplicationContext.setParent(applicationContext);
context.addEventListener(new ContextLoaderListener(webApplicationContext));
// Spring Security filter
context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", EnumSet.allOf(DispatcherType.class));
// start the server
server.start();
}
use of org.eclipse.jetty.servlet.FilterHolder in project steve by RWTH-i5-IDSG.
the class SteveAppContext method addSecurityFilter.
private void addSecurityFilter(WebAppContext ctx) {
// The bean name is not arbitrary, but is as expected by Spring
Filter f = new DelegatingFilterProxy(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);
ctx.addFilter(new FilterHolder(f), CONFIG.getSpringManagerMapping(), EnumSet.allOf(DispatcherType.class));
}
use of org.eclipse.jetty.servlet.FilterHolder in project drill by axbaretto.
the class WebServer method createServletContextHandler.
private ServletContextHandler createServletContextHandler(final boolean authEnabled) throws DrillbitStartupException {
// Add resources
final ErrorHandler errorHandler = new DrillErrorHandler();
errorHandler.setShowStacks(true);
errorHandler.setShowMessageInTitle(true);
final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setErrorHandler(errorHandler);
servletContextHandler.setContextPath("/");
final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new DrillRestServer(workManager, servletContextHandler.getServletContext(), drillbit)));
servletHolder.setInitOrder(1);
servletContextHandler.addServlet(servletHolder, "/*");
servletContextHandler.addServlet(new ServletHolder(new MetricsServlet(metrics)), "/status/metrics");
servletContextHandler.addServlet(new ServletHolder(new ThreadDumpServlet()), "/status/threads");
final ServletHolder staticHolder = new ServletHolder("static", DefaultServlet.class);
// Get resource URL for Drill static assets, based on where Drill icon is located
String drillIconResourcePath = Resource.newClassPathResource(BASE_STATIC_PATH + DRILL_ICON_RESOURCE_RELATIVE_PATH).getURL().toString();
staticHolder.setInitParameter("resourceBase", drillIconResourcePath.substring(0, drillIconResourcePath.length() - DRILL_ICON_RESOURCE_RELATIVE_PATH.length()));
staticHolder.setInitParameter("dirAllowed", "false");
staticHolder.setInitParameter("pathInfoOnly", "true");
servletContextHandler.addServlet(staticHolder, "/static/*");
if (authEnabled) {
// DrillSecurityHandler is used to support SPNEGO and FORM authentication together
servletContextHandler.setSecurityHandler(new DrillHttpSecurityHandlerProvider(config, workManager.getContext()));
servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
}
if (isImpersonationOnlyEnabled(workManager.getContext().getConfig())) {
for (String path : new String[] { "/query", "/query.json" }) {
servletContextHandler.addFilter(UserNameFilter.class, path, EnumSet.of(DispatcherType.REQUEST));
}
}
if (config.getBoolean(ExecConstants.HTTP_CORS_ENABLED)) {
FilterHolder holder = new FilterHolder(CrossOriginFilter.class);
holder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_ORIGINS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_METHODS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_HEADERS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(config.getBoolean(ExecConstants.HTTP_CORS_CREDENTIALS)));
for (String path : new String[] { "*.json", "/storage/*/enable/*", "/status*" }) {
servletContextHandler.addFilter(holder, path, EnumSet.of(DispatcherType.REQUEST));
}
}
return servletContextHandler;
}
use of org.eclipse.jetty.servlet.FilterHolder in project dropwizard-guicey by xvik.
the class WebMappingsRenderer method renderContextFilters.
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private Multimap<String, FilterReference> renderContextFilters(final MappingsConfig config, final MutableServletContextHandler handler, final TreeNode root) throws Exception {
final Multimap<String, FilterReference> servletFilters = LinkedHashMultimap.create();
for (FilterMapping mapping : handler.getServletHandler().getFilterMappings()) {
final FilterHolder holder = handler.getServletHandler().getFilter(mapping.getFilterName());
// single filter instance used for both contexts and so the name is also the same
final boolean isGuiceFilter = mapping.getFilterName().equals(GuiceWebModule.GUICE_FILTER);
if ((isGuiceFilter && !config.isGuiceMappings()) || !isAllowed(holder.getClassName(), config)) {
continue;
}
if (mapping.getServletNames() != null && mapping.getServletNames().length > 0) {
// filters targeting exact servlet are only remembered to be shown below target servlet
for (String servlet : mapping.getServletNames()) {
servletFilters.put(servlet, new FilterReference(mapping, holder));
}
} else {
final TreeNode filter = renderFilter(mapping, holder, root);
if (isGuiceFilter) {
renderGuiceWeb(filter);
}
}
}
return servletFilters;
}
use of org.eclipse.jetty.servlet.FilterHolder in project validator by validator.
the class Main method main.
public static void main(String[] args) throws Exception {
System.setProperties(new ThreadLocalProperties(System.getProperties()));
if (!"1".equals(System.getProperty("nu.validator.servlet.read-local-log4j-properties"))) {
PropertyConfigurator.configure(Main.class.getClassLoader().getResource("nu/validator/localentities/files/log4j.properties"));
} else {
PropertyConfigurator.configure(System.getProperty("nu.validator.servlet.log4j-properties", "log4j.properties"));
}
Logger log4j = Logger.getLogger(Main.class);
ConsoleAppender console = new ConsoleAppender();
console.setLayout(new PatternLayout("%m%n"));
console.activateOptions();
log4j.setAdditivity(false);
log4j.addAppender(console);
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/");
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setIncludedMethods("POST", "GET");
gzipHandler.setInflateBufferSize(2048);
gzipHandler.setHandler(contextHandler);
contextHandler.addFilter(new FilterHolder(new InboundSizeLimitFilter(SIZE_LIMIT)), "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addFilter(new FilterHolder(new InboundGzipFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addFilter(new FilterHolder(new MultipartFormDataFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
contextHandler.addServlet(new ServletHolder(new VerifierServlet()), "/*");
Server server = new Server(new QueuedThreadPool(100));
server.setHandler(contextHandler);
server.setHandler(gzipHandler);
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(new HttpConfiguration()));
int port = args.length > 0 ? Integer.parseInt(args[0]) : 8888;
serverConnector.setPort(port);
serverConnector.setHost(BIND_ADDRESS);
server.setConnectors(new Connector[] { serverConnector });
int stopPort = -1;
if (args.length > 1) {
stopPort = Integer.parseInt(args[1]);
}
if (stopPort != -1) {
try (Socket clientSocket = new Socket(InetAddress.getByName("127.0.0.1"), stopPort);
InputStream in = clientSocket.getInputStream()) {
in.read();
} catch (ConnectException e) {
}
server.start();
emitStartupMessage(log4j, serverConnector.getHost(), port);
try (ServerSocket serverSocket = new ServerSocket(stopPort, 0, InetAddress.getByName("127.0.0.1"));
Socket s = serverSocket.accept()) {
server.stop();
s.getOutputStream().close();
}
} else {
server.start();
emitStartupMessage(log4j, serverConnector.getHost(), port);
}
}
Aggregations