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

The following examples show how to use org.springframework.boot.context.embedded.FilterRegistrationBean. 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
@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 Project: cerebro   Source File: App.java    License: 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
@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 4
@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
@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 Project: spring-boot-shiro   Source File: ShiroAutoConfiguration.java    License: 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 7
Source Project: hello-sso-jwt-resource   Source File: WebApplication.java    License: 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 8
Source Project: mojito   Source File: WebSecurityConfig.java    License: Apache License 2.0 5 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 9
Source Project: x-pipe   Source File: MetaServerContextConfig.java    License: 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 10
Source Project: x-pipe   Source File: CatConfig.java    License: Apache License 2.0 5 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 11
Source Project: moneta   Source File: MonetaSpringBootApplication.java    License: 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 12
Source Project: moneta   Source File: MonetaSpringBootApplication.java    License: 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 13
Source Project: portal-de-servicos   Source File: FilterConfig.java    License: 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 14
Source Project: moserp   Source File: RestConfiguration.java    License: 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 15
@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 16
Source Project: jcart   Source File: WebConfig.java    License: 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 17
Source Project: jcart   Source File: WebConfig.java    License: 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 18
Source Project: portal-de-servicos   Source File: FilterConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public FilterRegistrationBean ticketFilter(Iterator<UUID> tickets) {
    return filter(0, new TicketFilter(tickets));
}
 
Example 19
Source Project: portal-de-servicos   Source File: FilterConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public FilterRegistrationBean loggingFilter() {
    return filter(1, new LoggingFilter());
}
 
Example 20
Source Project: enhanced-pet-clinic   Source File: DandelionConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public FilterRegistrationBean dandelionFilterRegistrationBean() {
	return new FilterRegistrationBean(new DandelionFilter());
}
 
Example 21
Source Project: enhanced-pet-clinic   Source File: DandelionConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public FilterRegistrationBean datatableFilterRegistrationBean() {
	return new FilterRegistrationBean(new DatatablesFilter());
}
 
Example 22
Source Project: enhanced-pet-clinic   Source File: WebMvcConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public FilterRegistrationBean hiddenFilterRegistrationBean() {
	return new FilterRegistrationBean(new HiddenHttpMethodFilter());
}