Search in sources :

Example 11 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project springboot_op by SnailFastGo.

the class DruidConfiguration method statFilter.

@Bean
public FilterRegistrationBean statFilter() {
    //创建过滤器
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
    //设置过滤器过滤路径
    filterRegistrationBean.addUrlPatterns("/*");
    //忽略过滤的形式
    filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
    return filterRegistrationBean;
}
Also used : WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project cas by apereo.

the class CasCoreAuditConfiguration method casClientInfoLoggingFilter.

@Bean
public FilterRegistrationBean casClientInfoLoggingFilter() {
    final AuditProperties audit = casProperties.getAudit();
    final FilterRegistrationBean bean = new FilterRegistrationBean();
    bean.setFilter(new ClientInfoThreadLocalFilter());
    bean.setUrlPatterns(Collections.singleton("/*"));
    bean.setName("CAS Client Info Logging Filter");
    bean.setAsyncSupported(true);
    final Map<String, String> initParams = new HashMap<>();
    if (StringUtils.isNotBlank(audit.getAlternateClientAddrHeaderName())) {
        initParams.put(ClientInfoThreadLocalFilter.CONST_IP_ADDRESS_HEADER, audit.getAlternateClientAddrHeaderName());
    }
    if (StringUtils.isNotBlank(audit.getAlternateServerAddrHeaderName())) {
        initParams.put(ClientInfoThreadLocalFilter.CONST_SERVER_IP_ADDRESS_HEADER, audit.getAlternateServerAddrHeaderName());
    }
    initParams.put(ClientInfoThreadLocalFilter.CONST_USE_SERVER_HOST_ADDRESS, String.valueOf(audit.isUseServerHostAddress()));
    bean.setInitParameters(initParams);
    return bean;
}
Also used : AuditProperties(org.apereo.cas.configuration.model.core.audit.AuditProperties) HashMap(java.util.HashMap) ClientInfoThreadLocalFilter(org.apereo.inspektr.common.web.ClientInfoThreadLocalFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 13 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project cas by apereo.

the class CasFiltersConfiguration method casCorsFilter.

@ConditionalOnProperty(prefix = "cas.httpWebRequest.cors", name = "enabled", havingValue = "true")
@Bean
@RefreshScope
public FilterRegistrationBean casCorsFilter() {
    final HttpWebRequestProperties.Cors cors = casProperties.getHttpWebRequest().getCors();
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(cors.isEnabled());
    config.setAllowedOrigins(cors.getAllowOrigins());
    config.setAllowedMethods(cors.getAllowMethods());
    config.setAllowedHeaders(cors.getAllowHeaders());
    config.setMaxAge(cors.getMaxAge());
    config.setExposedHeaders(cors.getExposedHeaders());
    source.registerCorsConfiguration("/**", config);
    final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
    bean.setName("casCorsFilter");
    bean.setAsyncSupported(true);
    bean.setOrder(0);
    return bean;
}
Also used : CorsFilter(org.springframework.web.filter.CorsFilter) UrlBasedCorsConfigurationSource(org.springframework.web.cors.UrlBasedCorsConfigurationSource) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HttpWebRequestProperties(org.apereo.cas.configuration.model.core.web.security.HttpWebRequestProperties) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 14 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project cas by apereo.

the class CasFiltersConfiguration method currentCredentialsAndAuthenticationClearingFilter.

@Bean
public FilterRegistrationBean currentCredentialsAndAuthenticationClearingFilter() {
    final FilterRegistrationBean bean = new FilterRegistrationBean();
    bean.setFilter(new AuthenticationCredentialsLocalBinderClearingFilter());
    bean.setUrlPatterns(Collections.singleton("/*"));
    bean.setName("currentCredentialsAndAuthenticationClearingFilter");
    bean.setAsyncSupported(true);
    return bean;
}
Also used : AuthenticationCredentialsLocalBinderClearingFilter(org.apereo.cas.web.support.AuthenticationCredentialsLocalBinderClearingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with FilterRegistrationBean

use of org.springframework.boot.web.servlet.FilterRegistrationBean in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method orderedBeanInsertedCorrectly.

@Test
public void orderedBeanInsertedCorrectly() throws Exception {
    addWebServerFactoryBean();
    OrderedFilter filter = new OrderedFilter();
    this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
    FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
    registration.setFilter(mock(Filter.class));
    registration.setOrder(100);
    this.context.registerBeanDefinition("filterRegistrationBean", beanDefinition(registration));
    this.context.refresh();
    MockServletWebServerFactory factory = getWebServerFactory();
    verify(factory.getServletContext()).addFilter("filterBean", filter);
    verify(factory.getServletContext()).addFilter("object", registration.getFilter());
    assertThat(factory.getRegisteredFilter(0).getFilter()).isEqualTo(filter);
}
Also used : MockServletWebServerFactory(org.springframework.boot.web.servlet.server.MockServletWebServerFactory) Filter(javax.servlet.Filter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.Test)

Aggregations

FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)23 Bean (org.springframework.context.annotation.Bean)21 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)10 HashMap (java.util.HashMap)4 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 Filter (javax.servlet.Filter)2 HttpWebRequestProperties (org.apereo.cas.configuration.model.core.web.security.HttpWebRequestProperties)2 ClientInfoThreadLocalFilter (org.apereo.inspektr.common.web.ClientInfoThreadLocalFilter)2 Test (org.junit.Test)2 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)2 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)2 RegistrationBean (org.springframework.boot.web.servlet.RegistrationBean)2 WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)1 CsrfFilter (com.erudika.scoold.utils.CsrfFilter)1 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)1 DispatcherType (javax.servlet.DispatcherType)1 ServletContext (javax.servlet.ServletContext)1 AuditProperties (org.apereo.cas.configuration.model.core.audit.AuditProperties)1 ThreadContextMDCServletFilter (org.apereo.cas.logging.web.ThreadContextMDCServletFilter)1