Java 类org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EmbeddedWebApplicationContextTests.java   
@Test
public void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames()
        throws Exception {
    addEmbeddedServletContainerFactoryBean();
    DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean(
            "filterBean");
    this.context.registerBeanDefinition("initializerBean",
            beanDefinition(initializer));
    BeanDefinition filterBeanDefinition = beanDefinition(
            new IllegalStateException("Create FilterBean Failure"));
    filterBeanDefinition.setLazyInit(true);
    this.context.registerBeanDefinition("filterBean", filterBeanDefinition);
    this.context.refresh();
    ServletContext servletContext = getEmbeddedServletContainerFactory()
            .getServletContext();
    verify(servletContext, atMost(1)).addFilter(anyString(),
            this.filterCaptor.capture());
    // Up to this point the filterBean should not have been created, calling
    // the delegate proxy will trigger creation and an exception
    this.thrown.expect(BeanCreationException.class);
    this.thrown.expectMessage("Create FilterBean Failure");
    this.filterCaptor.getValue().init(new MockFilterConfig());
    this.filterCaptor.getValue().doFilter(new MockHttpServletRequest(),
            new MockHttpServletResponse(), new MockFilterChain());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void defaultFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).isNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void customFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context,
            "security.filter-dispatcher-types:INCLUDE,ERROR");
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).containsOnly(DispatcherType.INCLUDE,
            DispatcherType.ERROR);
}
项目:spring-boot-concourse    文件:EmbeddedWebApplicationContextTests.java   
@Test
public void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames()
        throws Exception {
    addEmbeddedServletContainerFactoryBean();
    DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean(
            "filterBean");
    this.context.registerBeanDefinition("initializerBean",
            beanDefinition(initializer));
    BeanDefinition filterBeanDefinition = beanDefinition(
            new IllegalStateException("Create FilterBean Failure"));
    filterBeanDefinition.setLazyInit(true);
    this.context.registerBeanDefinition("filterBean", filterBeanDefinition);
    this.context.refresh();
    ServletContext servletContext = getEmbeddedServletContainerFactory()
            .getServletContext();
    verify(servletContext, atMost(1)).addFilter(anyString(),
            this.filterCaptor.capture());
    // Up to this point the filterBean should not have been created, calling
    // the delegate proxy will trigger creation and an exception
    this.thrown.expect(BeanCreationException.class);
    this.thrown.expectMessage("Create FilterBean Failure");
    this.filterCaptor.getValue().init(new MockFilterConfig());
    this.filterCaptor.getValue().doFilter(new MockHttpServletRequest(),
            new MockHttpServletResponse(), new MockFilterChain());
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void defaultFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).isNull();
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void customFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context,
            "security.filter-dispatcher-types:INCLUDE,ERROR");
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).containsOnly(DispatcherType.INCLUDE,
            DispatcherType.ERROR);
}
项目:incubator-servicecomb-java-chassis    文件:LoggingFilterConfig.java   
@Bean
DelegatingFilterProxyRegistrationBean delegatingFilterProxyRegistrationBean() {
  DelegatingFilterProxyRegistrationBean bean = new DelegatingFilterProxyRegistrationBean("traceLoggingFilter");

  bean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
  bean.setOrder(Ordered.LOWEST_PRECEDENCE);
  return bean;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringBootMockMvcBuilderCustomizer.java   
private void addFilters(ConfigurableMockMvcBuilder<?> builder) {
    ServletContextInitializerBeans Initializers = new ServletContextInitializerBeans(
            this.context);
    for (ServletContextInitializer initializer : Initializers) {
        if (initializer instanceof FilterRegistrationBean) {
            addFilter(builder, (FilterRegistrationBean) initializer);
        }
        if (initializer instanceof DelegatingFilterProxyRegistrationBean) {
            addFilter(builder, (DelegatingFilterProxyRegistrationBean) initializer);
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityFilterAutoConfiguration.java   
@Bean
@ConditionalOnBean(name = DEFAULT_FILTER_NAME)
public DelegatingFilterProxyRegistrationBean securityFilterChainRegistration(
        SecurityProperties securityProperties) {
    DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean(
            DEFAULT_FILTER_NAME);
    registration.setOrder(securityProperties.getFilterOrder());
    registration.setDispatcherTypes(getDispatcherTypes(securityProperties));
    return registration;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultFilterOrderWithSecurityAdapter() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(WebSecurity.class, SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(
                    FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 100);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultFilterOrder() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(
                    FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 100);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testCustomFilterOrder() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "security.filter-order:12345");
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(12345);
}
项目:spring-boot-concourse    文件:SpringBootMockMvcBuilderCustomizer.java   
private void addFilters(ConfigurableMockMvcBuilder<?> builder) {
    ServletContextInitializerBeans Initializers = new ServletContextInitializerBeans(
            this.context);
    for (ServletContextInitializer initializer : Initializers) {
        if (initializer instanceof FilterRegistrationBean) {
            addFilter(builder, (FilterRegistrationBean) initializer);
        }
        if (initializer instanceof DelegatingFilterProxyRegistrationBean) {
            addFilter(builder, (DelegatingFilterProxyRegistrationBean) initializer);
        }
    }
}
项目:spring-boot-concourse    文件:SecurityFilterAutoConfiguration.java   
@Bean
@ConditionalOnBean(name = DEFAULT_FILTER_NAME)
public DelegatingFilterProxyRegistrationBean securityFilterChainRegistration(
        SecurityProperties securityProperties) {
    DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean(
            DEFAULT_FILTER_NAME);
    registration.setOrder(securityProperties.getFilterOrder());
    registration.setDispatcherTypes(getDispatcherTypes(securityProperties));
    return registration;
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultFilterOrderWithSecurityAdapter() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(WebSecurity.class, SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(
                    FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 100);
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultFilterOrder() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(
                    FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 100);
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testCustomFilterOrder() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "security.filter-order:12345");
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(12345);
}
项目:spring-cloud-samples    文件:HystrixPluginsConfig.java   
@Bean
public DelegatingFilterProxyRegistrationBean userInsertingMdcFilterRegistrationBean() {
    DelegatingFilterProxyRegistrationBean registrationBean = new DelegatingFilterProxyRegistrationBean("hystrixRequestContextEnablerFilter", new ServletRegistrationBean[0]);
    registrationBean.setOrder(Integer.MAX_VALUE - 1);
    return registrationBean;
}
项目:spring-cloud-samples    文件:HystrixPluginsConfig.java   
@Bean
public DelegatingFilterProxyRegistrationBean setterInsertingMdcFilterRegistrationBean() {
    DelegatingFilterProxyRegistrationBean registrationBean = new DelegatingFilterProxyRegistrationBean("securityContextHystrixRequestVariableSetterFilter", new ServletRegistrationBean[0]);
    registrationBean.setOrder(Integer.MAX_VALUE);
    return registrationBean;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringBootMockMvcBuilderCustomizer.java   
private void addFilter(ConfigurableMockMvcBuilder<?> builder,
        DelegatingFilterProxyRegistrationBean registration) {
    addFilter(builder, registration.getFilter(), registration.getUrlPatterns());
}
项目:spring-boot-concourse    文件:SpringBootMockMvcBuilderCustomizer.java   
private void addFilter(ConfigurableMockMvcBuilder<?> builder,
        DelegatingFilterProxyRegistrationBean registration) {
    addFilter(builder, registration.getFilter(), registration.getUrlPatterns());
}