本文整理汇总了Java中org.springframework.boot.web.servlet.FilterRegistrationBean类的典型用法代码示例。如果您正苦于以下问题:Java FilterRegistrationBean类的具体用法?Java FilterRegistrationBean怎么用?Java FilterRegistrationBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilterRegistrationBean类属于org.springframework.boot.web.servlet包,在下文中一共展示了FilterRegistrationBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shallowEtagHeaderFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean shallowEtagHeaderFilter() {
FilterRegistrationBean frb = new FilterRegistrationBean();
frb.setFilter(new OneTimeETagGenerationFilter());
frb.addUrlPatterns(
"/backoffice/*",
"*.html",
"*.js",
"*.css",
"/fonts/*",
"/bower_components/*",
"/components/*",
"/img/*"
);
return frb;
}
示例2: corsFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
FilterRegistrationBean corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return bean;
}
示例3: corsFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
source.registerCorsConfiguration("/**", config);
final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
示例4: casCorsFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@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;
}
示例5: responseHeadersSecurityFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@RefreshScope
@Bean
public FilterRegistrationBean responseHeadersSecurityFilter() {
final HttpWebRequestProperties.Header header = casProperties.getHttpWebRequest().getHeader();
final Map<String, String> initParams = new HashMap<>();
initParams.put("enableCacheControl", BooleanUtils.toStringTrueFalse(header.isCache()));
initParams.put("enableXContentTypeOptions", BooleanUtils.toStringTrueFalse(header.isXcontent()));
initParams.put("enableStrictTransportSecurity", BooleanUtils.toStringTrueFalse(header.isHsts()));
initParams.put("enableXFrameOptions", BooleanUtils.toStringTrueFalse(header.isXframe()));
initParams.put("enableXSSProtection", BooleanUtils.toStringTrueFalse(header.isXss()));
final FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new ResponseHeadersEnforcementFilter());
bean.setUrlPatterns(Collections.singleton("/*"));
bean.setInitParameters(initParams);
bean.setName("responseHeadersSecurityFilter");
bean.setAsyncSupported(true);
return bean;
}
示例6: requestParameterSecurityFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@RefreshScope
@Bean
public FilterRegistrationBean requestParameterSecurityFilter() {
final Map<String, String> initParams = new HashMap<>();
initParams.put(RequestParameterPolicyEnforcementFilter.PARAMETERS_TO_CHECK,
casProperties.getHttpWebRequest().getParamsToCheck());
initParams.put(RequestParameterPolicyEnforcementFilter.CHARACTERS_TO_FORBID, "none");
initParams.put(RequestParameterPolicyEnforcementFilter.ALLOW_MULTI_VALUED_PARAMETERS,
BooleanUtils.toStringTrueFalse(casProperties.getHttpWebRequest().isAllowMultiValueParameters()));
initParams.put(RequestParameterPolicyEnforcementFilter.ONLY_POST_PARAMETERS,
casProperties.getHttpWebRequest().getOnlyPostParams());
final FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new RequestParameterPolicyEnforcementFilter());
bean.setUrlPatterns(Collections.singleton("/*"));
bean.setName("requestParameterSecurityFilter");
bean.setInitParameters(initParams);
bean.setAsyncSupported(true);
return bean;
}
示例7: corsFilterBean
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
/**
* <a href="https://github.com/spring-projects/spring-boot/issues/5834#issuecomment-296370088">See explanation here</a>
*/
@Bean
public FilterRegistrationBean corsFilterBean() {
final CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Collections.singletonList("*"));
configuration.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"));
// setAllowCredentials(true) is important, otherwise:
// The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
configuration.setAllowCredentials(true);
// setAllowedHeaders is important! Without it, OPTIONS preflight request
// will fail with 403 Invalid CORS request
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type"));
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
FilterRegistrationBean corsFilter = new FilterRegistrationBean(new CorsFilter(source));
corsFilter.setOrder(Ordered.HIGHEST_PRECEDENCE);
return corsFilter;
}
示例8: filterRegistrationBean
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean filterRegistrationBean(DruidDataSourceProperties druidDataSourceProperties) {
log.debug("druid web-stat-filter init...");
DruidWebStatProperties properties = druidDataSourceProperties.getWebStat();
FilterRegistrationBean registration = new FilterRegistrationBean();
WebStatFilter filter = new WebStatFilter();
registration.setFilter(filter);
registration.addUrlPatterns(properties.getUrlPatterns());
registration.addInitParameter("exclusions", properties.getExclusions());
registration.addInitParameter("sessionStatEnable", Boolean.toString(properties.isSessionStatEnable()));
if (!StringUtils.isEmpty(properties.getSessionStatMaxCount())) {
registration.addInitParameter("sessionStatMaxCount",Integer.toString(properties.getSessionStatMaxCount()));
}
if (!StringUtils.isEmpty(properties.getPrincipalSessionName())) {
registration.addInitParameter("principalSessionName", properties.getPrincipalSessionName());
}
if (!StringUtils.isEmpty(properties.getPrincipalCookieName())) {
registration.addInitParameter("principalCookieName", properties.getPrincipalCookieName());
}
registration.addInitParameter("profileEnable", Boolean.toString(properties.isProfileEnable()));
return registration;
}
示例9: corsFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
source.registerCorsConfiguration("/**", config);
// return new CorsFilter(source);
final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
示例10: initCorsFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
/**
* CORS:
* <p>
* Do not do any of below, which are the wrong way to attempt solving the ajax problem:
* - http.authorizeRequests().antMatchers(HttpMethod.OPTIONS, "/**").permitAll();
* - web.ignoring().antMatchers(HttpMethod.OPTIONS)
* <p>
* Global CORS configuration
* https://spring.io/blog/2015/06/08/cors-support-in-spring-framework
* https://docs.spring.io/spring-security/site/docs/current/reference/html/cors.html
* <p>
* Solution 1
* add CrossOrigin annotation to Controller class or methods
* <p>
* Solution 2
* override addCorsMappings(CorsRegistry registry) method of WebMvcConfigurerAdapter class
* <p>
* <p>
* The follow method will override CORS Configuration provided by Spring MVC.
*/
@Bean
public FilterRegistrationBean initCorsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
// setAllowCredentials(true) is important, otherwise:
// The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
config.setAllowCredentials(true);
// setAllowedHeaders is important! Without it, OPTIONS preflight request
// will fail with 403 Invalid CORS request
config.setAllowedHeaders(ImmutableList.of("Authorization", "Cache-Control", "Content-Type"));
config.addAllowedMethod("*");
String origins = this.applicationConfig.getAllowedOrigins();
if (origins != null && !"".equals(origins)) {
config.setAllowedOrigins(Arrays.asList(StringHelper.splitWithoutWhitespace(origins, ",")));
}
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return bean;
}
示例11: getFilterRegistrationBean
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
private FilterRegistrationBean getFilterRegistrationBean(int position) {
Integer filterCount = 0;
if(properties.getFilters().size() >= (position+1)) {
Bucket4JConfiguration filter = properties.getFilters().get(position);
filterCount++;
FilterConfiguration filterConfig = buildFilterConfig(filter, cacheManager, servletFilterExpressionParser(), beanFactory);
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setName("bucket4JRequestFilter" + position);
registration.setFilter(new ServletRequestFilter(filterConfig));
registration.addUrlPatterns(filter.getUrl());
registration.setOrder(filter.getFilterOrder());
return registration;
}
return null;
}
开发者ID:MarcGiffing,项目名称:bucket4j-spring-boot-starter,代码行数:21,代码来源:Bucket4JAutoConfigurationServletFilter.java
示例12: oauth2ClientFilterRegistration
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean<OAuth2ClientContextFilter> oauth2ClientFilterRegistration(
OAuth2ClientContextFilter filter, SecurityProperties security) {
FilterRegistrationBean<OAuth2ClientContextFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(filter);
registration.setOrder(security.getFilter().getOrder() - 10);
return registration;
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:9,代码来源:OAuth2RestOperationsConfiguration.java
示例13: traceWebFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
FilterRegistrationBean traceWebFilter(HttpTracing httpTracing) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(TracingFilter.create(httpTracing));
filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return filterRegistrationBean;
}
示例14: filterRegistrationBean
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registration = new FilterRegistrationBean(new SessionFilter(this));
registration.addUrlPatterns("/*");
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
return registration;
}
示例15: statFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean statFilter(){
//创建过滤器
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
//设置过滤器过滤路径
filterRegistrationBean.addUrlPatterns("/*");
//忽略过滤的形式
filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
}