Example usage for javax.servlet ServletContext addFilter

List of usage examples for javax.servlet ServletContext addFilter

Introduction

In this page you can find the example usage for javax.servlet ServletContext addFilter.

Prototype

public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass);

Source Link

Document

Adds the filter with the given name and class type to this servlet context.

Usage

From source file:com.gosmarter.it.eis.config.ExcelERPWebApplicationInitializer.java

private void registerSpringSecurityFilterChain(ServletContext servletContext) {
    DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy("springSecurityFilterChain");
    FilterRegistration fr = servletContext.addFilter("securityFilter", delegatingFilterProxy);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");
}

From source file:br.eti.danielcamargo.backend.common.config.WebAppInitializer.java

private void configureSpringSecurity(ServletContext servletContext, WebApplicationContext rootContext) {
    EnumSet<DispatcherType> dispacherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
    FilterRegistration.Dynamic springSecurity = servletContext.addFilter("springSecurityFilterChain",
            new DelegatingFilterProxy("springSecurityFilterChain", rootContext));
    springSecurity.addMappingForUrlPatterns(dispacherTypes, true, "/*");
}

From source file:com.shrisha.autoclient.config.ServletInitializer.java

private void registerProxyFilter(ServletContext servletContext, String name) {
    DelegatingFilterProxy filter = new DelegatingFilterProxy(name);
    filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher");
    servletContext.addFilter(name, filter).addMappingForUrlPatterns(null, false, "/*");
}

From source file:com.dm.platform.listener.PlatformServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    System.out.println("contextInitialized");

    ServletContext sc = sce.getServletContext();
    sc.setInitParameter("contextConfigLocation", "/WEB-INF/applicationContext.xml");
    //    sc.addListener(ContextLoaderListener.class);
    FilterRegistration fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(),
            DelegatingFilterProxy.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/spring/*");

    ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class);
    sr.setInitParameter("contextConfigLocation",
            "/WEB-INF/dispatcher-servlet.xml /WEB-INF/platform-security.xml");
    sr.addMapping("/spring/*");

    fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*");

}

From source file:io.springagora.store.AppInitializer.java

private void initializeOpenEMInViewFilter(ServletContext container) {
    OpenEntityManagerInViewFilter sessionFilter = new OpenEntityManagerInViewFilter();
    FilterRegistration.Dynamic filterReg = container.addFilter("Open EM In View Filter", sessionFilter);
    filterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, URL_PATTERN_WEB);
    filterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, URL_PATTERN_REST);
}

From source file:com.jiwhiz.web.config.WebConfigurer.java

/**
 * Initializes the cachig HTTP Headers Filter.
 *///from   w w  w.  j  a  va2s.  c o  m
private void initCachingHttpHeadersFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Registering Caching HTTP Headers Filter");
    FilterRegistration.Dynamic cachingHttpHeadersFilter = servletContext.addFilter("cachingHttpHeadersFilter",
            new CachingHttpHeadersFilter());

    cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/images/*");
    cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/fonts/*");
    cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/scripts/*");
    cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/styles/*");
    cachingHttpHeadersFilter.setAsyncSupported(true);
}

From source file:org.lightadmin.logging.configurer.LightConfigurerWebApplicationInitializer.java

private void registerCharsetFilter(ServletContext servletContext, LoggingConfigurerSettings configuration) {
    final String urlMapping = urlMapping(configuration.getApplicationBaseUrl());

    servletContext.addFilter("LightConfigurerCharsetFilter", characterEncodingFilter())
            .addMappingForServletNames(null, false, urlMapping);
}

From source file:ca.unx.template.config.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    /* Let super do its thing... */
    super.onStartup(servletContext);

    /* Add the Spring Security filter. */
    servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy())
            .addMappingForUrlPatterns(null, false, "/*");

    // Add metrics servlet.
    ServletRegistration.Dynamic metricsServlet = servletContext.addServlet("metrics", AdminServlet.class);
    metricsServlet.addMapping("/metrics/*");
}

From source file:org.smigo.config.WebAppInitializer.java

@Override
protected void afterSpringSecurityFilterChain(ServletContext servletContext) {
    //Adding filter here so we can use request.getUserPrincipal()
    super.afterSpringSecurityFilterChain(servletContext);
    FilterRegistration.Dynamic logStatusCode = servletContext.addFilter("RequestLogFilter",
            new RequestLogFilter());
    logStatusCode.addMappingForUrlPatterns(null, false, "/*");
}

From source file:com.jiwhiz.web.config.WebConfigurer.java

/**
 * Initializes the static resources production Filter.
 *///www . ja v a  2 s.c o m
private void initStaticResourcesProductionFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {

    log.debug("Registering static resources production Filter");
    FilterRegistration.Dynamic staticResourcesProductionFilter = servletContext
            .addFilter("staticResourcesProductionFilter", new StaticResourcesProductionFilter());

    staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/");
    staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/index.html");
    staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/images/*");
    staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/fonts/*");
    staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/scripts/*");
    staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/styles/*");
    staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/views/*");
    staticResourcesProductionFilter.setAsyncSupported(true);
}