org.springframework.boot.context.embedded.FilterRegistrationBean Java Examples

The following examples show how to use org.springframework.boot.context.embedded.FilterRegistrationBean. 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: App.java    From cerebro with GNU Affero General Public License v3.0 6 votes vote down vote up
@Bean
public FilterRegistrationBean correlationIdFilter() {
    return new FilterRegistrationBean(new Filter() {

        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
        }

        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            chain.doFilter(request, response);
        }

        @Override
        public void destroy() {
        }
    });
}
 
Example #3
Source File: WebSecurityConfig.java    From mojito with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnProperty(value = "l10n.security.oauth2.enabled", havingValue = "true")
public FilterRegistrationBean oauth2ClientFilterRegistration(OAuth2ClientContextFilter filter) {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(filter);
    registration.setOrder(-100);
    return registration;
}
 
Example #4
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 #5
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 #6
Source File: WebConfig.java    From jcart with MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean PostAuthorizationFilterRegistrationBean() {
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(postAuthorizationFilter);
    registrationBean.setOrder(Integer.MAX_VALUE);
    return registrationBean;
}
 
Example #7
Source File: WebConfig.java    From jcart with MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean securityFilterChain(@Qualifier(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) Filter securityFilter) {
    FilterRegistrationBean registration = new FilterRegistrationBean(securityFilter);
    registration.setOrder(Integer.MAX_VALUE - 1);
    registration.setName(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);
    return registration;
}
 
Example #8
Source File: RequestCorrelationConfiguration.java    From request-correlation-spring-cloud-starter with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean requestCorrelationFilterBean(RequestCorrelationFilter correlationFilter) {

    final FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
    filterRegistration.setFilter(correlationFilter);
    filterRegistration.setMatchAfter(false);
    filterRegistration.setDispatcherTypes(
            EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC));
    filterRegistration.setAsyncSupported(true);
    filterRegistration.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return filterRegistration;
}
 
Example #9
Source File: RestConfiguration.java    From moserp with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean loggingFilterRegistration() {
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(loggingFilter());
    registrationBean.setUrlPatterns(Collections.singletonList("/*"));
    registrationBean.setName("LoggingFilter");
    return registrationBean;
}
 
Example #10
Source File: FilterConfig.java    From portal-de-servicos with MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean securityHeadersFilter(@Value("${pds.piwik.url}") String urlPiwik) {
    return filter(2, new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
            filterChain.doFilter(request, response);
            response.setHeader("X-XSS-Protection", "0");
            response.setHeader("X-Content-Type-Options", "nosniff");
            response.setHeader("Content-Security-Policy", "script-src: 'self' 'unsafe-inline' '" + urlPiwik + "' 'barra.brasil.gov.br'; default-src: 'self'");
        }
    });
}
 
Example #11
Source File: MonetaSpringBootApplication.java    From moneta with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean reportCorrelationFilter() {
	FilterRegistrationBean registration =
			new FilterRegistrationBean(new RequestCorrelationFilter(),
					monetaServlet(), monetaTopicListServlet());
	return registration;
}
 
Example #12
Source File: MonetaSpringBootApplication.java    From moneta with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean monetaPerformanceFilter() {
	FilterRegistrationBean registration =
			new FilterRegistrationBean(new MonetaPerformanceFilter(),
					monetaServlet(), monetaTopicListServlet());
	return registration;
}
 
Example #13
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;
}
 
Example #14
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 #15
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 #16
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 #17
Source File: RoothubApplication.java    From Roothub with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean filterRegistrationBean() {
	FilterRegistrationBean registrationBean = new FilterRegistrationBean();
	CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
	characterEncodingFilter.setForceEncoding(true);
	characterEncodingFilter.setEncoding("UTF-8");
	registrationBean.setFilter(characterEncodingFilter);
	return registrationBean;
}
 
Example #18
Source File: FilterConfig.java    From portal-de-servicos with MIT License 4 votes vote down vote up
@Bean
public FilterRegistrationBean ticketFilter(Iterator<UUID> tickets) {
    return filter(0, new TicketFilter(tickets));
}
 
Example #19
Source File: FilterConfig.java    From portal-de-servicos with MIT License 4 votes vote down vote up
@Bean
public FilterRegistrationBean loggingFilter() {
    return filter(1, new LoggingFilter());
}
 
Example #20
Source File: DandelionConfig.java    From enhanced-pet-clinic with Apache License 2.0 4 votes vote down vote up
@Bean
public FilterRegistrationBean dandelionFilterRegistrationBean() {
	return new FilterRegistrationBean(new DandelionFilter());
}
 
Example #21
Source File: DandelionConfig.java    From enhanced-pet-clinic with Apache License 2.0 4 votes vote down vote up
@Bean
public FilterRegistrationBean datatableFilterRegistrationBean() {
	return new FilterRegistrationBean(new DatatablesFilter());
}
 
Example #22
Source File: WebMvcConfig.java    From enhanced-pet-clinic with Apache License 2.0 4 votes vote down vote up
@Bean
public FilterRegistrationBean hiddenFilterRegistrationBean() {
	return new FilterRegistrationBean(new HiddenHttpMethodFilter());
}