Search in sources :

Example 46 with Filter

use of javax.servlet.Filter in project ddf by codice.

the class ProxyFilterChainTest method testAddFiltersAfterDo.

/**
     * Tests that an exception is thrown if more filters are attempted to be
     * added after the filter has been run.
     *
     * @throws IOException
     * @throws ServletException
     */
@Test(expected = IllegalStateException.class)
public void testAddFiltersAfterDo() throws IOException, ServletException {
    FilterChain initialChain = mock(FilterChain.class);
    ProxyFilterChain proxyChain = new ProxyFilterChain(initialChain);
    Filter filter2 = mock(Filter.class);
    Filter filter3 = mock(Filter.class);
    proxyChain.doFilter(mock(ServletRequest.class), mock(ServletResponse.class));
    proxyChain.addFilters(Arrays.asList(filter2, filter3));
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) Filter(javax.servlet.Filter) FilterChain(javax.servlet.FilterChain) Test(org.junit.Test)

Example 47 with Filter

use of javax.servlet.Filter in project spring-security-oauth by spring-projects.

the class AuthorizationServerSecurityConfigurer method configure.

@Override
public void configure(HttpSecurity http) throws Exception {
    // ensure this is initialized
    frameworkEndpointHandlerMapping();
    if (allowFormAuthenticationForClients) {
        clientCredentialsTokenEndpointFilter(http);
    }
    for (Filter filter : tokenEndpointAuthenticationFilters) {
        http.addFilterBefore(filter, BasicAuthenticationFilter.class);
    }
    http.exceptionHandling().accessDeniedHandler(accessDeniedHandler);
}
Also used : Filter(javax.servlet.Filter) BasicAuthenticationFilter(org.springframework.security.web.authentication.www.BasicAuthenticationFilter) ClientCredentialsTokenEndpointFilter(org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter)

Example 48 with Filter

use of javax.servlet.Filter in project nutzboot by nutzam.

the class UndertowStarter method addFilter.

public void addFilter(WebFilterFace webFilter) {
    if (webFilter == null || webFilter.getFilter() == null) {
        return;
    }
    log.debugf("add filter name=%s pathSpec=%s", webFilter.getName(), webFilter.getPathSpec());
    ImmediateInstanceFactory<Filter> factory = new ImmediateInstanceFactory<Filter>(webFilter.getFilter());
    FilterInfo filter = new FilterInfo(webFilter.getName(), webFilter.getFilter().getClass(), factory);
    Iterator<Map.Entry<String, String>> entries = webFilter.getInitParameters().entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry<String, String> entry = entries.next();
        filter.addInitParam(entry.getKey(), entry.getValue());
    }
    deployment.addFilter(filter).addFilterUrlMapping(webFilter.getName(), webFilter.getPathSpec(), DispatcherType.REQUEST).addFilterUrlMapping(webFilter.getName(), webFilter.getPathSpec(), DispatcherType.FORWARD);
}
Also used : Filter(javax.servlet.Filter) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory) FilterInfo(io.undertow.servlet.api.FilterInfo) Map(java.util.Map)

Example 49 with Filter

use of javax.servlet.Filter in project nutzboot by nutzam.

the class NbResourceBasedWebEnvironment method configure.

protected void configure() {
    this.objects.clear();
    WebSecurityManager securityManager = createWebSecurityManager();
    setWebSecurityManager(securityManager);
    String loginUrl = conf.get(ShiroEnvStarter.PROP_URL_LOGIN, "/user/login");
    String unauthorizedUrl = conf.get(ShiroEnvStarter.PROP_URL_UNAUTH, "/user/login");
    String logoutUrl = conf.get(ShiroEnvStarter.PROP_URL_LOGOUT_REDIRECT, "/");
    for (Map.Entry<String, Filter> en : DefaultFilter.createInstanceMap(null).entrySet()) {
        Filter filter = en.getValue();
        if (filter instanceof LogoutFilter) {
            ((LogoutFilter) filter).setRedirectUrl(logoutUrl);
        } else if (filter instanceof AuthenticatingFilter) {
            ((AuthenticatingFilter) filter).setLoginUrl(loginUrl);
        } else if (filter instanceof AccessControlFilter) {
            ((AccessControlFilter) filter).setLoginUrl(unauthorizedUrl);
        }
        objects.put(en.getKey(), en.getValue());
    }
    for (String objectName : Strings.splitIgnoreBlank(conf.get("shiro.objects", ""))) {
        objects.put(objectName, ioc.get(null, objectName));
    }
    FilterChainResolver resolver = createFilterChainResolver();
    if (resolver != null) {
        setFilterChainResolver(resolver);
    }
    NutShiro.DefaultLoginURL = loginUrl;
    NutShiro.DefaultNoAuthURL = unauthorizedUrl;
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) AuthenticatingFilter(org.apache.shiro.web.filter.authc.AuthenticatingFilter) AccessControlFilter(org.apache.shiro.web.filter.AccessControlFilter) AccessControlFilter(org.apache.shiro.web.filter.AccessControlFilter) DefaultFilter(org.apache.shiro.web.filter.mgt.DefaultFilter) Filter(javax.servlet.Filter) LogoutFilter(org.apache.shiro.web.filter.authc.LogoutFilter) AuthenticatingFilter(org.apache.shiro.web.filter.authc.AuthenticatingFilter) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) LogoutFilter(org.apache.shiro.web.filter.authc.LogoutFilter) Map(java.util.Map)

Example 50 with Filter

use of javax.servlet.Filter in project gitiles by GerritCodeReview.

the class GitilesFilter method init.

@Override
public synchronized void init(FilterConfig config) throws ServletException {
    super.init(config);
    setDefaultFields(config);
    for (GitilesView.Type type : GitilesView.Type.values()) {
        if (!servlets.containsKey(type)) {
            servlets.put(type, getDefaultHandler(type));
        }
    }
    Filter repositoryFilter = new RepositoryFilter(resolver);
    Filter viewFilter = new ViewFilter(accessFactory, urls, visibilityCache);
    Filter dispatchFilter = new DispatchFilter(filters, servlets);
    ServletBinder root = serveRegex(ROOT_REGEX).through(viewFilter);
    if (gitwebRedirect != null) {
        root.through(gitwebRedirect);
    }
    root.through(dispatchFilter);
    serveRegex(REPO_REGEX).through(repositoryFilter).through(viewFilter).through(dispatchFilter);
    serveRegex(REPO_PATH_REGEX).through(repositoryFilter).through(viewFilter).through(dispatchFilter);
    initialized = true;
}
Also used : MetaFilter(org.eclipse.jgit.http.server.glue.MetaFilter) Filter(javax.servlet.Filter) ServletBinder(org.eclipse.jgit.http.server.glue.ServletBinder)

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