use of org.eclipse.jetty.servlet.FilterHolder in project incubator-pulsar by apache.
the class Filters method addFilterClass.
/**
* Adds a filter to the servlet context handler which gets instantiated and configured when the server starts.
*
* @param context servlet context handler instance
* @param filter filter class
* @param initParams initialization parameters used for configuring the filter instance
*/
public static void addFilterClass(ServletContextHandler context, Class<? extends Filter> filter, Map<String, String> initParams) {
FilterHolder holder = new FilterHolder(filter);
holder.setInitParameters(initParams);
addFilterHolder(context, holder);
}
use of org.eclipse.jetty.servlet.FilterHolder in project activemq-artemis by apache.
the class WebServerComponent method createWebAppContext.
protected WebAppContext createWebAppContext(String url, String warFile, Path warDirectory, String virtualHost) {
WebAppContext webapp = new WebAppContext();
if (url.startsWith("/")) {
webapp.setContextPath(url);
} else {
webapp.setContextPath("/" + url);
}
// add the filters needed for audit logging
webapp.addFilter(new FilterHolder(JolokiaFilter.class), "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
webapp.addFilter(new FilterHolder(AuthenticationFilter.class), "/auth/login/*", EnumSet.of(DispatcherType.REQUEST));
webapp.setWar(warDirectory.resolve(warFile).toString());
webapp.setAttribute("org.eclipse.jetty.webapp.basetempdir", temporaryWarDir.toFile().getAbsolutePath());
// Set the default authenticator factory to avoid NPE due to the following commit:
// https://github.com/eclipse/jetty.project/commit/7e91d34177a880ecbe70009e8f200d02e3a0c5dd
webapp.getSecurityHandler().setAuthenticatorFactory(new DefaultAuthenticatorFactory());
webapp.setVirtualHosts(new String[] { virtualHost });
return webapp;
}
use of org.eclipse.jetty.servlet.FilterHolder in project knox by apache.
the class ServiceRegistryFunctionsTest method testSetup.
private void testSetup(String username, Map<String, String> initParams) throws Exception {
ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-nn-scheme://test-nn-host:411").anyTimes();
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "JOBTRACKER")).andReturn("test-jt-scheme://test-jt-host:511").anyTimes();
GatewayServices mockGatewayServices = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(mockGatewayServices.getService(ServiceType.SERVICE_REGISTRY_SERVICE)).andReturn(mockServiceRegistry).anyTimes();
EasyMock.replay(mockServiceRegistry, mockGatewayServices);
String descriptorUrl = getTestResource("rewrite.xml").toExternalForm();
Log.setLog(new NoOpLogger());
server = new ServletTester();
server.setContextPath("/");
server.getContext().addEventListener(new UrlRewriteServletContextListener());
server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);
server.getContext().setAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster");
server.getContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices);
FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
setupFilter.setFilter(new SetupFilter(username));
FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
if (initParams != null) {
for (Map.Entry<String, String> entry : initParams.entrySet()) {
rewriteFilter.setInitParameter(entry.getKey(), entry.getValue());
}
}
rewriteFilter.setFilter(new UrlRewriteServletFilter());
interactions = new ArrayDeque<>();
ServletHolder servlet = server.addServlet(MockServlet.class, "/");
servlet.setServlet(new MockServlet("mock-servlet", interactions));
server.start();
interaction = new MockInteraction();
request = HttpTester.newRequest();
response = null;
}
use of org.eclipse.jetty.servlet.FilterHolder in project knox by apache.
the class HttpServer2 method addGlobalFilter.
@Override
public void addGlobalFilter(String name, String classname, Map<String, String> parameters) {
final String[] ALL_URLS = { "/*" };
FilterHolder filterHolder = getFilterHolder(name, classname, parameters);
FilterMapping fmap = getFilterMapping(name, ALL_URLS);
defineFilter(webAppContext, filterHolder, fmap);
for (ServletContextHandler ctx : defaultContexts.keySet()) {
defineFilter(ctx, filterHolder, fmap);
}
LOG.info("Added global filter '" + name + "' (class=" + classname + ")");
}
use of org.eclipse.jetty.servlet.FilterHolder in project knox by apache.
the class FrontendFunctionProcessorTest method testSetup.
private void testSetup(String username, Map<String, String> initParams, Attributes attributes) throws Exception {
ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-nn-scheme://test-nn-host:411").anyTimes();
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "JOBTRACKER")).andReturn("test-jt-scheme://test-jt-host:511").anyTimes();
GatewayServices mockGatewayServices = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(mockGatewayServices.getService(ServiceType.SERVICE_REGISTRY_SERVICE)).andReturn(mockServiceRegistry).anyTimes();
EasyMock.replay(mockServiceRegistry, mockGatewayServices);
String descriptorUrl = TestUtils.getResourceUrl(FrontendFunctionProcessorTest.class, "rewrite.xml").toExternalForm();
Log.setLog(new NoOpLogger());
server = new ServletTester();
server.setContextPath("/");
server.getContext().addEventListener(new UrlRewriteServletContextListener());
server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);
if (attributes != null) {
server.getContext().setAttributes(attributes);
}
server.getContext().setAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster");
server.getContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices);
FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
setupFilter.setFilter(new SetupFilter(username));
FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
if (initParams != null) {
for (Map.Entry<String, String> entry : initParams.entrySet()) {
rewriteFilter.setInitParameter(entry.getKey(), entry.getValue());
}
}
rewriteFilter.setFilter(new UrlRewriteServletFilter());
interactions = new ArrayDeque<>();
ServletHolder servlet = server.addServlet(MockServlet.class, "/");
servlet.setServlet(new MockServlet("mock-servlet", interactions));
server.start();
interaction = new MockInteraction();
request = HttpTester.newRequest();
response = null;
}
Aggregations