org.springframework.web.filter.DelegatingFilterProxy Java Examples

The following examples show how to use org.springframework.web.filter.DelegatingFilterProxy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CentralizeInitializer.java    From java-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	Map<String, String> filterChainDefinitionMap = Application.getSecurityFilterChainDefinitionMap();
	filterChainDefinitionMap.put("/admin", DefaultFilter.authc.name());
	filterChainDefinitionMap.put("/admin/logout", DefaultFilter.logout.name());
	filterChainDefinitionMap.put("/admin/**", DefaultFilter.authc.name());

	List<Filter> filters = Application.getFilters();

	DelegatingFilterProxy shiroFilter = new DelegatingFilterProxy("shiroFilter");
	shiroFilter.setTargetFilterLifecycle(true);
	filters.add(shiroFilter);

	filters.add(new RequestContextFilter());
	filters.add(new CharacterEncodingFilter("UTF-8", true));
}
 
Example #2
Source File: ShiroConfig.java    From erp-framework with MIT License 6 votes vote down vote up
/**
     * 自动创建代理
     * @return
     */
//    @Bean
//    @DependsOn({"lifecycleBeanPostProcessor"})
//    public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator(){
//        DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
//        advisorAutoProxyCreator.setProxyTargetClass(true);
//        return advisorAutoProxyCreator;
//    }

    @Bean
    public FilterRegistrationBean delegatingFilterProxy(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        DelegatingFilterProxy proxy = new DelegatingFilterProxy();
        proxy.setTargetFilterLifecycle(true);
        proxy.setTargetBeanName("shiroFilter");
        filterRegistrationBean.setFilter(proxy);
        filterRegistrationBean.setDispatcherTypes(DispatcherType.ERROR,DispatcherType.REQUEST,DispatcherType.FORWARD,DispatcherType.INCLUDE);
        return filterRegistrationBean;
    }
 
Example #3
Source File: ApplicationConfig.java    From docker-kubernetes-by-example-java with Apache License 2.0 5 votes vote down vote up
@Bean
@Order(value = 0)
FilterRegistrationBean sessionRepositoryFilterRegistration(
    SessionRepositoryFilter filter) {
  FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(
      new DelegatingFilterProxy(filter));
  filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));

  return filterRegistrationBean;
}
 
Example #4
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #5
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #6
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #7
Source File: JPAWebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #8
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #9
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #10
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #11
Source File: WarInitializer.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the delegating filter proxy which is used for Spring Security.
 *
 * @param servletContext the servlet context.
 */
protected void initDelegatingFilterProxy(ServletContext servletContext)
{
    // Initialize and add the Spring security's delegating filter proxy to the servlet context.
    DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy();
    FilterRegistration.Dynamic filterChainProxyFilterRegistration = servletContext.addFilter("filterChainProxy", delegatingFilterProxy);
    filterChainProxyFilterRegistration.addMappingForUrlPatterns(null, true, "/*");
}
 
Example #12
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    LOGGER.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #13
Source File: WebInitializer.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
public void onStartup(ServletContext servletContext) {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.setConfigLocation("org.audt4j.demo.hibernate.config");
	servletContext.addListener(new ContextLoaderListener(ctx));
	ctx.setServletContext(servletContext);
	Dynamic servlet = servletContext.addServlet("dispatcher",
			new DispatcherServlet(ctx));
	servlet.addMapping("/*");
	servlet.setLoadOnStartup(1);
	FilterRegistration.Dynamic springSecurityFilterChain = servletContext
			.addFilter("springSecurityFilterChain",
					new DelegatingFilterProxy());
	springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");
	springSecurityFilterChain.setAsyncSupported(true);
}
 
Example #14
Source File: ShiroConfiguration.java    From EasyEE with MIT License 5 votes vote down vote up
/**
 * Shiro Core FilterRegistrationBean: Shiro DelegatingFilterProxy
 * 
 * @return
 */
@Bean 
public FilterRegistrationBean shiroFilterRegistrationBean() {
	FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
	DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy("shiroFilter");
	delegatingFilterProxy.setTargetFilterLifecycle(true);
	filterRegistration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE,
			DispatcherType.ERROR);
	filterRegistration.setFilter(delegatingFilterProxy);
	List<String> urlPatterns = new ArrayList<String>();
	urlPatterns.add("/*");
	filterRegistration.setUrlPatterns(urlPatterns);
	return filterRegistration;
}
 
Example #15
Source File: ShiroConfiguration.java    From EasyEE with MIT License 5 votes vote down vote up
/**
 * Shiro Core FilterRegistrationBean: Shiro DelegatingFilterProxy
 * 
 * @return
 */
@Bean 
public FilterRegistrationBean shiroFilterRegistrationBean() {
	FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
	DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy("shiroFilter");
	delegatingFilterProxy.setTargetFilterLifecycle(true);
	filterRegistration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE,
			DispatcherType.ERROR);
	filterRegistration.setFilter(delegatingFilterProxy);
	List<String> urlPatterns = new ArrayList<String>();
	urlPatterns.add("/*");
	filterRegistration.setUrlPatterns(urlPatterns);
	return filterRegistration;
}
 
Example #16
Source File: AbstractHttpSessionApplicationInitializer.java    From spring-session with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the springSessionRepositoryFilter.
 * @param servletContext the {@link ServletContext}
 */
private void insertSessionRepositoryFilter(ServletContext servletContext) {
	String filterName = DEFAULT_FILTER_NAME;
	DelegatingFilterProxy springSessionRepositoryFilter = new DelegatingFilterProxy(filterName);
	String contextAttribute = getWebApplicationContextAttribute();
	if (contextAttribute != null) {
		springSessionRepositoryFilter.setContextAttribute(contextAttribute);
	}
	registerFilter(servletContext, true, filterName, springSessionRepositoryFilter);
}
 
Example #17
Source File: WallRideServletConfiguration.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean urlRewriteFilterRegistration() {
	DelegatingFilterProxy proxy = new DelegatingFilterProxy("urlRewriteFilter");
	proxy.setTargetFilterLifecycle(true);

	FilterRegistrationBean registration = new FilterRegistrationBean();
	registration.setName("urlRewriteFilter");
	registration.setFilter(proxy);
	registration.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST));
	registration.addUrlPatterns("/*");
	registration.setOrder(0);
	return registration;
}
 
Example #18
Source File: ServletConfig.java    From EasyReport with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean filterRegistrationBean() {
    final FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
    filterRegistration.setFilter(new DelegatingFilterProxy("shiroFilter"));
    filterRegistration.addInitParameter("targetFilterLifecycle", "true");
    filterRegistration.setEnabled(true);
    filterRegistration.addUrlPatterns("/*");
    return filterRegistration;
}
 
Example #19
Source File: AbstractWebApplicationInitializer.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
protected void createFilters(ServletContext ctx) {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");

        SimpleCORSFilter corsFilter = new SimpleCORSFilter();
        corsFilter.setCorsAllowCredentials("true");
        corsFilter.setCorsAllowMethods("GET, POST, PUT, PATCH, DELETE, OPTIONS");
        corsFilter.setCorsAllowHeaders("content-type, x-requested-with, origin, accept, authorization, username, password, x-app-type, x-app-version, x-auth-token, soapaction");
        corsFilter.setCorsExposeHeaders("content-type, cookie, x-requested-with, origin, accept, username, password, x-app-type, x-app-version, x-auth-token, soapaction");
        corsFilter.setCorsMaxAge("3600");

        ctx.addFilter("springSessionRepositoryFilter", DelegatingFilterProxy.class).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);
        ctx.addFilter("simpleCORSFilter", DelegatingFilterProxy.class).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);
//        ctx.addFilter("SimpleCorsFilter", corsFilter).addMappingForUrlPatterns(
//                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);
        ctx.addFilter("JsonHttpRequestFilter", new JsonHttpRequestFilter()).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/api/authenticate");
        ctx.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);
        ctx.addFilter("CharacterEncodingFilter", characterEncodingFilter).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);
        ctx.addFilter("HiddenHttpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);
        ctx.addFilter("HttpPutFormContentFilter", new HttpPutFormContentFilter()).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);
        ctx.addFilter("ShallowEtagHeaderFilter", new ShallowEtagHeaderFilter()).addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING);

    }
 
Example #20
Source File: MainWebAppInitializer.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Register and configure all Servlet container components necessary to power the web application.
 */
@Override
public void onStartup(final ServletContext sc) throws ServletException {
    System.out.println("MyWebAppInitializer.onStartup()");

    // Create the 'root' Spring application context
    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.scan("com.baeldung.config.parent");
    // root.getEnvironment().setDefaultProfiles("embedded");

    // Manages the lifecycle of the root application context
    sc.addListener(new ContextLoaderListener(root));

    // Handles requests into the application
    final AnnotationConfigWebApplicationContext childWebApplicationContext = new AnnotationConfigWebApplicationContext();
    childWebApplicationContext.scan("com.baeldung.config.child");
    final ServletRegistration.Dynamic appServlet = sc.addServlet("api", new DispatcherServlet(childWebApplicationContext));
    appServlet.setLoadOnStartup(1);
    final Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
        throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
    }

    // spring security filter
    final DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain");
    final Dynamic addedFilter = sc.addFilter("springSecurityFilterChain", springSecurityFilterChain);
    addedFilter.addMappingForUrlPatterns(null, false, "/*");
}
 
Example #21
Source File: WebAppInitializer.java    From thymeleafexamples-layouts with Apache License 2.0 5 votes vote down vote up
@Override
protected Filter[] getServletFilters() {
    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    DelegatingFilterProxy securityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain");

    return new Filter[] {characterEncodingFilter, securityFilterChain};
}
 
Example #22
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
  log.debug("Registering Spring Security Filter");
  FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

  springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
  springSecurityFilter.setAsyncSupported(true);
}
 
Example #23
Source File: AnnotationConfigDispatcherServletInitializerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected Filter[] getServletFilters() {
	return new Filter[] {
			new HiddenHttpMethodFilter(),
			new DelegatingFilterProxy("a"),
			new DelegatingFilterProxy("b"),
			new DelegatingFilterProxy("c")
	};
}
 
Example #24
Source File: ShiroConfig.java    From spring-boot-plus with Apache License 2.0 5 votes vote down vote up
/**
 * ShiroFilter配置
 *
 * @return
 */
@Bean
public FilterRegistrationBean delegatingFilterProxy() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    DelegatingFilterProxy proxy = new DelegatingFilterProxy();
    proxy.setTargetFilterLifecycle(true);
    proxy.setTargetBeanName(SHIRO_FILTER_NAME);
    filterRegistrationBean.setFilter(proxy);
    filterRegistrationBean.setAsyncSupported(true);
    filterRegistrationBean.setEnabled(true);
    filterRegistrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
    return filterRegistrationBean;
}
 
Example #25
Source File: AnnotationConfigDispatcherServletInitializerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected Filter[] getServletFilters() {
	return new Filter[] {
			new HiddenHttpMethodFilter(),
			new DelegatingFilterProxy("a"),
			new DelegatingFilterProxy("b"),
			new DelegatingFilterProxy("c")
	};
}
 
Example #26
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
    springSecurityFilter.setAsyncSupported(true);
}
 
Example #27
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
  log.debug("Registering Spring Security Filter");
  FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

  springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #28
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

    springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
    springSecurityFilter.setAsyncSupported(true);
}
 
Example #29
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
  log.debug("Registering Spring Security Filter");
  FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

  springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}
 
Example #30
Source File: JPAWebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring Security.
 */
private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) {
  log.debug("Registering Spring Security Filter");
  FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());

  springSecurityFilter.addMappingForUrlPatterns(disps, false, "/*");
}