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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations