本文整理匯總了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;
}