Search in sources :

Example 76 with Filter

use of javax.servlet.Filter in project dropwizard-shiro by silb.

the class ShiroBundle method run.

@Override
public void run(T configuration, Environment environment) {
    ShiroConfiguration shiroConfig = narrow(configuration);
    ResourceConfig resourceConfig = environment.jersey().getResourceConfig();
    resourceConfig.register(new AuthorizationFilterFeature());
    resourceConfig.register(new SubjectFactory());
    resourceConfig.register(new AuthInjectionBinder());
    Filter shiroFilter = createFilter(configuration);
    environment.servlets().addFilter("ShiroFilter", shiroFilter).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, shiroConfig.filterUrlPattern());
}
Also used : SubjectFactory(org.secnod.shiro.jersey.SubjectFactory) AuthorizationFilterFeature(org.secnod.shiro.jersey.AuthorizationFilterFeature) AbstractShiroFilter(org.apache.shiro.web.servlet.AbstractShiroFilter) Filter(javax.servlet.Filter) AuthInjectionBinder(org.secnod.shiro.jersey.AuthInjectionBinder) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) DispatcherType(javax.servlet.DispatcherType)

Example 77 with Filter

use of javax.servlet.Filter in project neo4j by neo4j.

the class AuthorizationModule method start.

@Override
public void start() {
    final Filter authorizationFilter;
    if (config.get(GraphDatabaseSettings.auth_enabled)) {
        authorizationFilter = new AuthorizationEnabledFilter(authManagerSupplier, logProvider, uriWhitelist);
    } else {
        authorizationFilter = createAuthorizationDisabledFilter();
    }
    webServer.addFilter(authorizationFilter, "/*");
}
Also used : AuthorizationDisabledFilter(org.neo4j.server.rest.dbms.AuthorizationDisabledFilter) AuthorizationEnabledFilter(org.neo4j.server.rest.dbms.AuthorizationEnabledFilter) Filter(javax.servlet.Filter) AuthorizationEnabledFilter(org.neo4j.server.rest.dbms.AuthorizationEnabledFilter)

Example 78 with Filter

use of javax.servlet.Filter in project pinpoint by naver.

the class WebServerConfig method etagFilterBean.

@Bean
public FilterRegistrationBean etagFilterBean() {
    FilterRegistrationBean filterBean = new FilterRegistrationBean();
    Filter filter = new ShallowEtagHeaderFilter();
    filterBean.setFilter(filter);
    filterBean.setUrlPatterns(Collections.singletonList("*"));
    return filterBean;
}
Also used : ErrorPageFilter(org.springframework.boot.web.servlet.support.ErrorPageFilter) Filter(javax.servlet.Filter) ShallowEtagHeaderFilter(org.springframework.web.filter.ShallowEtagHeaderFilter) ShallowEtagHeaderFilter(org.springframework.web.filter.ShallowEtagHeaderFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 79 with Filter

use of javax.servlet.Filter in project druid by druid-io.

the class TrustedDomainAuthenticatorTest method testTrustedHost.

@Test
public void testTrustedHost() throws IOException, ServletException {
    Authenticator authenticator = new TrustedDomainAuthenticator("test-authenticator", "test.com", false, "my-auth", "myUser");
    HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
    EasyMock.expect(req.getRemoteAddr()).andReturn("serverA.test.com");
    req.setAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT, new AuthenticationResult("myUser", "my-auth", "test-authenticator", null));
    EasyMock.expectLastCall().times(1);
    EasyMock.replay(req);
    HttpServletResponse resp = EasyMock.createMock(HttpServletResponse.class);
    EasyMock.replay(resp);
    FilterChain filterChain = EasyMock.createMock(FilterChain.class);
    filterChain.doFilter(req, resp);
    EasyMock.expectLastCall().times(1);
    EasyMock.replay(filterChain);
    Filter authenticatorFilter = authenticator.getFilter();
    authenticatorFilter.doFilter(req, resp, filterChain);
    EasyMock.verify(req, resp, filterChain);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Filter(javax.servlet.Filter) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 80 with Filter

use of javax.servlet.Filter in project druid by druid-io.

the class TrustedDomainAuthenticatorTest method testNonTrustedHost.

@Test
public void testNonTrustedHost() throws IOException, ServletException {
    Authenticator authenticator = new TrustedDomainAuthenticator("test-authenticator", "test.com", false, "my-auth", "myUser");
    HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
    EasyMock.expect(req.getRemoteAddr()).andReturn("serverA.test2.com");
    EasyMock.replay(req);
    HttpServletResponse resp = EasyMock.createMock(HttpServletResponse.class);
    EasyMock.replay(resp);
    FilterChain filterChain = EasyMock.createMock(FilterChain.class);
    filterChain.doFilter(req, resp);
    EasyMock.expectLastCall().times(1);
    EasyMock.replay(filterChain);
    Filter authenticatorFilter = authenticator.getFilter();
    authenticatorFilter.doFilter(req, resp, filterChain);
    EasyMock.verify(req, resp, filterChain);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Filter(javax.servlet.Filter) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Aggregations

Filter (javax.servlet.Filter)185 FilterChain (javax.servlet.FilterChain)67 Test (org.junit.Test)57 HttpServletRequest (javax.servlet.http.HttpServletRequest)53 HttpServletResponse (javax.servlet.http.HttpServletResponse)44 ServletRequest (javax.servlet.ServletRequest)43 ServletResponse (javax.servlet.ServletResponse)43 ServletException (javax.servlet.ServletException)28 FilterConfig (javax.servlet.FilterConfig)25 IOException (java.io.IOException)23 ServletContext (javax.servlet.ServletContext)20 Injector (com.google.inject.Injector)17 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)16 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 Map (java.util.Map)9 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)9 ArrayList (java.util.ArrayList)8 Hashtable (java.util.Hashtable)8 DispatcherType (javax.servlet.DispatcherType)8