List of usage examples for javax.servlet FilterRegistration.Dynamic addMappingForUrlPatterns
public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns);
From source file:io.github.microcks.config.WebConfiguration.java
/** */ private void initStaticResourcesFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) { log.debug("Registering static resources production Filter"); FilterRegistration.Dynamic resFilter = servletContext.addFilter("staticResourcesFilter", new StaticResourcesFilter()); resFilter.addMappingForUrlPatterns(disps, true, "/"); resFilter.addMappingForUrlPatterns(disps, true, "/index.html"); resFilter.addMappingForUrlPatterns(disps, true, "/scripts/*"); resFilter.addMappingForUrlPatterns(disps, true, "/images/*"); resFilter.addMappingForUrlPatterns(disps, true, "/styles/*"); resFilter.addMappingForUrlPatterns(disps, true, "/views/*"); resFilter.addMappingForUrlPatterns(disps, true, "/bower_components/*"); resFilter.setAsyncSupported(true);/*from w w w. j a va 2 s .c o m*/ }
From source file:com.olegchir.wicket_spring_security_example.init.AppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { //Create webapp context AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); //part of spring-web root.register(SpringSecurityConfiguration.class); //register class by annotation. Here be all security rules. //Register DelegatingFilterProxy FilterRegistration.Dynamic springSecurityFilterChainReg = servletContext .addFilter("springSecurityFilterChain", DelegatingFilterProxy.class); springSecurityFilterChainReg .addMappingForUrlPatterns(EnumSet.of(DispatcherType.ERROR, DispatcherType.REQUEST), false, "/*"); servletContext.addListener(new ContextLoaderListener(root)); //Register WicketFilter WicketFilter wicketFilter = new WicketFilter(new WicketApplication()) { @Override//from www . j a v a 2 s . c o m public void init(boolean isServlet, FilterConfig filterConfig) throws ServletException { setFilterPath(""); //don't use web.xml. WicketApplication.init is a custom override for it. super.init(isServlet, filterConfig); } }; FilterRegistration.Dynamic wicketFilterReg = servletContext.addFilter("wicketFilter", wicketFilter); wicketFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "*"); }
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.local.ask.controller.WebAppInitializer.java
@Override public void onStartup(ServletContext container) { CharacterEncodingFilter encodingFilter = new org.springframework.web.filter.CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(false); FilterRegistration.Dynamic encodingFilterDinamic = container.addFilter("charEncodingFilter", encodingFilter);//from w w w .java2s . c o m encodingFilterDinamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebConfig.class); rootContext.register(SecurityConfig.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(HomeController.class); dispatcherContext.register(LoginController.class); dispatcherContext.register(PostController.class); dispatcherContext.register(SignUpController.class); dispatcherContext.register(ContactUsController.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); filterProxy.setTargetFilterLifecycle(true); container.addFilter("shiroFilter", filterProxy).addMappingForUrlPatterns(null, false, "/*"); // encoding filter }
From source file:io.gumga.security.WebConfigForTest.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); servletContext.setInitParameter("javax.servlet.jsp.jstl.fmt.localizationContext", "messages"); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);/* w ww . j a v a 2s. c o m*/ characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); rootContext.setServletContext(servletContext); rootContext.register(WebConfigForTest.class); rootContext.refresh(); }
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:org.davidmendoza.demo.config.StartUpConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(ComponentConfig.class, DataConfig.class, MailConfig.class, WebConfig.class); context.setDisplayName("DemoApp"); FilterRegistration.Dynamic sitemeshFilter = servletContext.addFilter("sitemeshFilter", new ConfigurableSiteMeshFilter()); sitemeshFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); servletContext.addListener(new ContextLoaderListener(context)); //servletContext.setInitParameter("defaultHtmlEscape", "false"); DispatcherServlet servlet = new DispatcherServlet(); // no explicit configuration reference here: everything is configured in the root container for simplicity servlet.setContextConfigLocation(""); ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", servlet); appServlet.setLoadOnStartup(1);// www . j av a 2s . c o m appServlet.setAsyncSupported(true); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14"); } }
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.indeed.imhotep.web.config.WebApp.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { if (WebApp.started) { return; // avoid double initialization when a subclass exists }// ww w. ja va 2 s. c o m WebApp.started = true; initWebapp(servletContext); initCharacterEncodingFilter(servletContext); super.onStartup(servletContext); FilterRegistration.Dynamic noCacheFilter = servletContext.addFilter("nocache", NoCacheFilter.class); noCacheFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); cleanupTempFiles(); }
From source file:net.orpiske.tcs.service.config.WebAppInitializer.java
private void configureSpringSecurity(ServletContext servletContext, WebApplicationContext rootContext) { FilterRegistration.Dynamic springSecurity = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain", rootContext)); springSecurity.addMappingForUrlPatterns(null, true, "/*"); }