Java Code Examples for org.springframework.boot.context.embedded.FilterRegistrationBean#addUrlPatterns()

The following examples show how to use org.springframework.boot.context.embedded.FilterRegistrationBean#addUrlPatterns() . 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 File: CorsSupportConfiguration.java    From spring-backend-boilerplate with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnExpression("${in.clouthink.daas.sbb.support.cors.enabled:true}")
@Autowired
public FilterRegistrationBean filterRegistrationBean(CorsSupportProperties corsSupportProperties) {
    final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();

    final CorsConfiguration corsConfiguration = new CorsConfiguration();
    corsConfiguration.setAllowCredentials(corsSupportProperties.isAllowCredentials());
    corsConfiguration.addAllowedOrigin(corsSupportProperties.getAllowOrigin());
    corsConfiguration.addAllowedHeader(corsSupportProperties.getAllowHeader());
    corsConfiguration.addAllowedMethod(corsSupportProperties.getAllowMethod());

    urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);

    CorsFilter corsFilter = new CorsFilter(urlBasedCorsConfigurationSource);
    FilterRegistrationBean registration = new FilterRegistrationBean(corsFilter);
    registration.addUrlPatterns("/*");
    registration.setOrder(corsSupportProperties.getOrder());
    return registration;
}
 
Example 2
Source File: CatConfig.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Bean
public FilterRegistrationBean catFilter() {
	
	FilterRegistrationBean bean = new FilterRegistrationBean();
	bean.setFilter(new CatFilter());
	bean.setName("cat-filter");
	bean.addUrlPatterns("/*");
	bean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD);
	return bean;
}
 
Example 3
Source File: OpenApiWebMvcConfigurer.java    From spring-backend-boilerplate with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean httpMethodFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(httpMethodFilter());
    registration.addUrlPatterns("/*");
    registration.setName("httpMethodFilter");
    registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
    return registration;
}
 
Example 4
Source File: OpenApiWebMvcConfigurer.java    From spring-backend-boilerplate with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean httpMethodFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(httpMethodFilter());
    registration.addUrlPatterns("/*");
    registration.setName("httpMethodFilter");
    registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
    return registration;
}
 
Example 5
Source File: ShiroAutoConfiguration.java    From spring-boot-shiro with Apache License 2.0 5 votes vote down vote up
@Bean(name = "shiroFilter")
@DependsOn("securityManager")
@ConditionalOnMissingBean
public FilterRegistrationBean filterRegistrationBean(SecurityManager securityManager) throws Exception {
    FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
    //该值缺省为false,表示生命周期由SpringApplicationContext管理,设置为true则表示由ServletContainer管理
    filterRegistration.addInitParameter("targetFilterLifecycle", "true");
    filterRegistration.setFilter((Filter) getShiroFilterFactoryBean(securityManager).getObject());
    filterRegistration.setEnabled(true);
    filterRegistration.addUrlPatterns("/*");
    return filterRegistration;
}
 
Example 6
Source File: WebApplication.java    From hello-sso-jwt-resource with MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean jwtFilter() {
    final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(new JwtFilter());
    registrationBean.setInitParameters(Collections.singletonMap("services.auth", authService));
    registrationBean.addUrlPatterns("/protected-resource");

    return registrationBean;
}
 
Example 7
Source File: MetaServerContextConfig.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean domainValidateFilter() {
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    Supplier<String> expectedDomainName = () -> {
        // toLowerCase() to match metaServerConfig retrieve info
        String dcName = FoundationService.DEFAULT.getDataCenter().toLowerCase();
        DcInfo dcInfo = metaServerConfig.getDcInofs().get(dcName);
        return dcInfo.getMetaServerAddress();
    };
    DomainValidateFilter filter = new DomainValidateFilter(()->metaServerConfig.validateDomain(), expectedDomainName);
    registrationBean.setFilter(filter);
    registrationBean.addUrlPatterns("/*");
    return registrationBean;
}