use of javax.servlet.FilterConfig in project spring-framework by spring-projects.
the class ConditionalDelegatingFilterProxyTests method init.
@Test
public void init() throws Exception {
FilterConfig config = new MockFilterConfig();
filter = new PatternMappingFilterProxy(delegate, "/");
filter.init(config);
assertThat(delegate.filterConfig, is(config));
}
use of javax.servlet.FilterConfig in project hadoop by apache.
the class TestAuthFilter method testGetCustomAuthConfiguration.
@Test
public void testGetCustomAuthConfiguration() throws ServletException {
AuthFilter filter = new AuthFilter();
Map<String, String> m = new HashMap<String, String>();
m.put(AuthFilter.CONF_PREFIX + AuthFilter.AUTH_TYPE, "com.yourclass");
m.put(AuthFilter.CONF_PREFIX + "alt-kerberos.param", "value");
FilterConfig config = new DummyFilterConfig(m);
Properties p = filter.getConfiguration(AuthFilter.CONF_PREFIX, config);
Assert.assertEquals("com.yourclass", p.getProperty(AuthFilter.AUTH_TYPE));
Assert.assertEquals("value", p.getProperty("alt-kerberos.param"));
}
use of javax.servlet.FilterConfig in project hadoop by apache.
the class TestAuthFilter method testGetConfiguration.
@Test
public void testGetConfiguration() throws ServletException {
AuthFilter filter = new AuthFilter();
Map<String, String> m = new HashMap<String, String>();
m.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY, "xyz/thehost@REALM");
m.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY, "thekeytab");
FilterConfig config = new DummyFilterConfig(m);
Properties p = filter.getConfiguration("random", config);
Assert.assertEquals("xyz/thehost@REALM", p.getProperty("kerberos.principal"));
Assert.assertEquals("thekeytab", p.getProperty("kerberos.keytab"));
Assert.assertEquals("true", p.getProperty(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED));
}
use of javax.servlet.FilterConfig in project newts by OpenNMS.
the class NewtsService method configureUIRedirect.
private void configureUIRedirect(Environment environment) {
environment.servlets().addFilter("TrailingSlashRedirect", new Filter() {
@Override
public void init(FilterConfig cfg) throws ServletException {
LOG.info("Initializing redirect filter");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
StringBuffer url = ((HttpServletRequest) request).getRequestURL();
String path = new URL(url.toString()).getPath();
if (path.endsWith(UI_URL_PATH)) {
LOG.debug("Caught request to malformed URL {}, redirecting...", UI_URL_PATH);
((HttpServletResponse) response).sendRedirect(String.format("%s/", url.toString()));
} else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
}
}).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}
use of javax.servlet.FilterConfig in project hadoop by apache.
the class TestCrossOriginFilter method testPatternMatchingOrigins.
@Test
public void testPatternMatchingOrigins() throws ServletException, IOException {
// Setup the configuration settings of the server
Map<String, String> conf = new HashMap<String, String>();
conf.put(CrossOriginFilter.ALLOWED_ORIGINS, "*.example.com");
FilterConfig filterConfig = new FilterConfigTest(conf);
// Object under test
CrossOriginFilter filter = new CrossOriginFilter();
filter.init(filterConfig);
// match multiple sub-domains
Assert.assertFalse(filter.areOriginsAllowed("example.com"));
Assert.assertFalse(filter.areOriginsAllowed("foo:example.com"));
Assert.assertTrue(filter.areOriginsAllowed("foo.example.com"));
Assert.assertTrue(filter.areOriginsAllowed("foo.bar.example.com"));
// First origin is allowed
Assert.assertTrue(filter.areOriginsAllowed("foo.example.com foo.nomatch.com"));
// Second origin is allowed
Assert.assertTrue(filter.areOriginsAllowed("foo.nomatch.com foo.example.com"));
// No origin in list is allowed
Assert.assertFalse(filter.areOriginsAllowed("foo.nomatch1.com foo.nomatch2.com"));
}
Aggregations