Java Code Examples for org.springframework.boot.web.servlet.FilterRegistrationBean#setOrder()

The following examples show how to use org.springframework.boot.web.servlet.FilterRegistrationBean#setOrder() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: supplierShop   File: FilterConfig.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public FilterRegistrationBean xssFilterRegistration()
{
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setDispatcherTypes(DispatcherType.REQUEST);
    registration.setFilter(new XssFilter());
    registration.addUrlPatterns(StringUtils.split(urlPatterns, ","));
    registration.setName("xssFilter");
    registration.setOrder(Integer.MAX_VALUE);
    Map<String, String> initParameters = new HashMap<String, String>();
    initParameters.put("excludes", excludes);
    initParameters.put("enabled", enabled);
    registration.setInitParameters(initParameters);
    return registration;
}
 
Example 2
/**
 * 解决跨域问题
 *
 * @return 跨域声明
 */
@Bean
public FilterRegistrationBean corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.setAllowedOrigins(allowedOrigins);
    config.addAllowedHeader("*");
    config.setMaxAge(18000L);
    config.addAllowedMethod("*");
    //添加response暴露的header
    String[] responseHeader =
            {"date", "content-encoding", "server", "etag", "vary", "Cache-Control", "Last-Modified",
                    "content-type", "transfer-encoding", "connection", "x-application-context"};
    config.setExposedHeaders(Arrays.asList(responseHeader));
    source.registerCorsConfiguration("/**", config);

    FilterRegistrationBean bean = new FilterRegistrationBean<>(new CorsFilter(source));
    bean.setOrder(0);
    return bean;
}
 
Example 3
@Bean
public FilterRegistrationBean springMvcDelegatingFilterProxy() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    SpringMvcSofaTracerFilter filter = new SpringMvcSofaTracerFilter();
    filterRegistrationBean.setFilter(filter);
    List<String> urlPatterns = openTracingSpringProperties.getUrlPatterns();
    if (urlPatterns == null || urlPatterns.size() <= 0) {
        filterRegistrationBean.addUrlPatterns("/*");
    } else {
        filterRegistrationBean.setUrlPatterns(urlPatterns);
    }
    filterRegistrationBean.setName(filter.getFilterName());
    filterRegistrationBean.setAsyncSupported(true);
    filterRegistrationBean.setOrder(openTracingSpringProperties.getFilterOrder());
    return filterRegistrationBean;
}
 
Example 4
@Bean
public FilterRegistrationBean oauth2ClientFilterRegistration(OAuth2ClientContextFilter filter) {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(filter);
    registration.setOrder(-100);
    return registration;
}
 
Example 5
Source Project: RuoYi   File: FilterConfig.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes" , "unchecked"})
@Bean
public FilterRegistrationBean xssFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setDispatcherTypes(DispatcherType.REQUEST);
    registration.setFilter(new XssFilter());
    registration.addUrlPatterns(StrUtil.split(urlPatterns, ","));
    registration.setName("xssFilter");
    registration.setOrder(Integer.MAX_VALUE);
    Map<String, String> initParameters = new HashMap<>();
    initParameters.put("excludes" , excludes);
    initParameters.put("enabled" , enabled);
    registration.setInitParameters(initParameters);
    return registration;
}
 
Example 6
@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;
}
 
Example 7
/**
 * Add an authentication filter to the web application context if edison.ldap property is set to {@code enabled}'.
 * All routes starting with the value of the {@code edison.ldap.prefix} property will be secured by LDAP. If no
 * property is set this will default to all routes starting with '/internal'.
 *
 * @param ldapProperties the properties used to configure LDAP
 * @param ldapConnectionFactory the connection factory used to build the LdapAuthenticationFilter
 * @return FilterRegistrationBean
 */
@Bean
public FilterRegistrationBean<LdapAuthenticationFilter> ldapAuthenticationFilter(final LdapProperties ldapProperties,
                                                       final LdapConnectionFactory ldapConnectionFactory) {
    FilterRegistrationBean<LdapAuthenticationFilter> filterRegistration = new FilterRegistrationBean<>();
    filterRegistration.setFilter(new LdapAuthenticationFilter(ldapProperties, ldapConnectionFactory));
    filterRegistration.setOrder(Ordered.LOWEST_PRECEDENCE - 1);
    ldapProperties.getPrefixes().forEach(prefix -> filterRegistration.addUrlPatterns(String.format("%s/*", prefix)));
    return filterRegistration;
}
 
Example 8
Source Project: cat_lab   File: CatFilterConfigure.java    License: MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean catFilter() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    CatServletFilter filter = new CatServletFilter();
    registration.setFilter(filter);
    registration.addUrlPatterns("/*");
    registration.setName("cat-filter");
    registration.setOrder(1);
    return registration;
}
 
Example 9
Source Project: sdb-mall   File: FilterConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean xssFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setDispatcherTypes(DispatcherType.REQUEST);
    registration.setFilter(new XssFilter());
    registration.addUrlPatterns("/*");
    registration.setName("xssFilter");
    registration.setOrder(Integer.MAX_VALUE);
    return registration;
}
 
Example 10
Source Project: Sentinel   File: FilterConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean sentinelFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(new CommonFilter());
    registration.addUrlPatterns("/*");
    registration.setName("sentinelFilter");
    registration.setOrder(1);

    return registration;
}
 
Example 11
Source Project: ReCiter   File: Application.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean squigglyRequestFilter() {
    FilterRegistrationBean filter = new FilterRegistrationBean();
    filter.setFilter(new SquigglyRequestFilter());
    filter.setOrder(1);
    return filter;
}
 
Example 12
@Bean
@ConditionalOnBean(name = "httpTraceFilter")
public FilterRegistrationBean<?> traceFilterRegistration(
		@Qualifier("httpTraceFilter") Filter filter) {
	FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>();
	bean.setFilter(filter);
	bean.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
	return bean;
}
 
Example 13
Source Project: x7   File: CorsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean corsFilterRegistration(CorsFilter corsFilter) {

    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(corsFilter);
    registration.addUrlPatterns("/*");
    registration.setName(CorsFilter.class.getSimpleName());
    registration.setOrder(1);
    return registration;
}
 
Example 14
/**
 * Add an authentication filter that requires a certain LDAP role to access secured paths.
 * All routes starting with the value of the {@code edison.ldap.prefixes} property will be secured by LDAP.
 * If no property is set this will default to all routes starting with '/internal'.
 *
 * @param ldapProperties the properties used to configure LDAP
 * @return FilterRegistrationBean
 */
@Bean
@ConditionalOnProperty(prefix = "edison.ldap", name = "required-role")
public FilterRegistrationBean<LdapRoleAuthenticationFilter> ldapRoleAuthenticationFilter(final LdapProperties ldapProperties) {
    FilterRegistrationBean<LdapRoleAuthenticationFilter> filterRegistration = new FilterRegistrationBean<>();
    filterRegistration.setFilter(new LdapRoleAuthenticationFilter(ldapProperties));
    filterRegistration.setOrder(Ordered.LOWEST_PRECEDENCE);
    ldapProperties.getPrefixes().forEach(prefix -> filterRegistration.addUrlPatterns(String.format("%s/*", prefix)));
    return filterRegistration;
}
 
Example 15
@Bean
public FilterRegistrationBean restFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(restFilter());
    registration.addUrlPatterns("/rest/*");
    registration.setName("RESTFilter");
    registration.setOrder(3);
    return registration;
}
 
Example 16
Source Project: springboot-guide   File: MyFilterConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean<MyFilter2> setUpMyFilter2() {
    FilterRegistrationBean<MyFilter2> filterRegistrationBean = new FilterRegistrationBean<>();
    filterRegistrationBean.setOrder(1);
    filterRegistrationBean.setFilter(myFilter2);
    filterRegistrationBean.setUrlPatterns(new ArrayList<>(Arrays.asList("/api/*")));
    return filterRegistrationBean;
}
 
Example 17
Source Project: ZTuoExchange_framework   File: CorsConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean corsFilter() {
     UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
     CorsConfiguration config = new CorsConfiguration();
     config.addAllowedOrigin("*");
     config.setAllowCredentials(true);
     config.addAllowedHeader("*");
     config.addAllowedMethod("*");
     source.registerCorsConfiguration("/**", config);
     FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
     bean.setOrder(0);
     return bean;
}
 
Example 18
Source Project: staffjoy   File: FaradayConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean<NakedDomainFilter> nakedDomainFilterRegistrationBean(EnvConfig envConfig) {
    FilterRegistrationBean<NakedDomainFilter> registrationBean =
            new FilterRegistrationBean<>(new NakedDomainFilter(envConfig));
    registrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE + 90); // before ReverseProxyFilter
    return registrationBean;
}
 
Example 19
/**
 * Filter to protect the hawkBit server DDI download interface against
 * to many requests.
 * 
 * @param securityProperties
 *            for filter configuration
 *
 * @return the spring filter registration bean for registering a denial
 *         of service protection filter in the filter chain
 */
@Bean
@ConditionalOnProperty(prefix = "hawkbit.server.security.dos.filter", name = "enabled", matchIfMissing = true)
public FilterRegistrationBean<DosFilter> dosDDiDlFilter(final HawkbitSecurityProperties securityProperties) {

    final FilterRegistrationBean<DosFilter> filterRegBean = dosFilter(Arrays.asList(DDI_DL_ANT_MATCHER),
            securityProperties.getDos().getFilter(), securityProperties.getClients());
    filterRegBean.setOrder(DOS_FILTER_ORDER);
    filterRegBean.setName("dosDDiDlFilter");

    return filterRegBean;
}
 
Example 20
Source Project: spring-boot-demo   File: WebConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean customFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    //注入过滤器
    registration.setFilter(new CustomFilter());
    //过滤器名称
    registration.setName("CustomFilter");
    //拦截规则
    registration.addUrlPatterns("/*");
    //过滤器顺序
    registration.setOrder(1);
    return registration;
}