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

The following examples show how to use org.springframework.boot.web.servlet.FilterRegistrationBean#setFilter() . 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: apollo   File: AuthConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public FilterRegistrationBean assertionHolder() {
  FilterRegistrationBean assertionHolderFilter = new FilterRegistrationBean();

  Map<String, String> filterInitParam = Maps.newHashMap();
  filterInitParam.put("/openapi.*", "exclude");

  assertionHolderFilter.setInitParameters(filterInitParam);

  assertionHolderFilter.setFilter(
      filter("com.ctrip.framework.apollo.sso.filter.ApolloAssertionThreadLocalFilter"));
  assertionHolderFilter.addUrlPatterns("/*");
  assertionHolderFilter.setOrder(4);

  return assertionHolderFilter;
}
 
Example 2
Source Project: piggymetrics   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 3
Source Project: app-engine   File: FilterConfigFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean headerFilterChain() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    Filter headerFilter = new HeaderResponseFilter();
    registration.setFilter(headerFilter);
    registration.setOrder(Integer.MAX_VALUE);
    return registration;
}
 
Example 4
Source Project: radar   File: FilterConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean ppdfilter() {
  FilterRegistrationBean openApiFilter = new FilterRegistrationBean();
  openApiFilter.setFilter(new LogFilter());
  openApiFilter.addUrlPatterns("/*");
  return openApiFilter;
}
 
Example 5
Source Project: v-mock   File: VMockApplication.java    License: MIT License 5 votes vote down vote up
/**
 * 主要逻辑的filter
 */
@Bean
public FilterRegistrationBean mockFilter() {
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(new MockFilter());
    // order -> 1
    registrationBean.setOrder(1);
    // filter all request start with [/vmock]
    registrationBean.addUrlPatterns(CommonConst.RESTFUL_PATH + "/*");
    return registrationBean;
}
 
Example 6
Source Project: sdb-mall   File: FilterConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean shiroFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(new DelegatingFilterProxy("shiroFilter"));
    //该值缺省为false,表示生命周期由SpringApplicationContext管理,设置为true则表示由ServletContainer管理
    registration.addInitParameter("targetFilterLifecycle", "true");
    registration.setEnabled(true);
    registration.setOrder(Integer.MAX_VALUE - 1);
    registration.addUrlPatterns("/*");
    return registration;
}
 
Example 7
Source Project: MyBlog   File: BootStrap.java    License: Apache License 2.0 5 votes vote down vote up
/*********************************************************************************************************/
//shiro设置
@Bean
public FilterRegistrationBean filterRegistrationBean() {
    FilterRegistrationBean<DelegatingFilterProxy> registration = new FilterRegistrationBean<>();
    registration.setFilter(new DelegatingFilterProxy());
    registration.addUrlPatterns("/api/*");
    registration.addInitParameter("targetFilterLifecycle", "true");
    registration.setName("shiroFilter");//名字必须和ShiroFilterFactoryBean一样
    return registration;
}
 
Example 8
Source Project: Qualitis   File: FilterOrderConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean characterEncodingFilter() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(new CharacterEncodingFilter("UTF-8"));
    registration.addUrlPatterns("/*");
    registration.setOrder(0);
    return registration;
}
 
Example 9
@Bean
public FilterRegistrationBean sentinelFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(new CommonFilter());
    registration.addUrlPatterns("/*");
    registration.setName("sentinelFilter");
    registration.setOrder(1);

    return registration;
}
 
Example 10
Source Project: spring-boot   File: WebMVCConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 自定义,并注册 filter
 * 将代理服务器发来的请求包含的IP地址转换成真正的用户IP
 *
 * @return
 */
@Bean
public FilterRegistrationBean remoteIpFilter() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(new RemoteIpFilter());
    registration.addUrlPatterns("/*");
    registration.setName("RemoteIpFilter");
    log.info("RemoteIpFilter initialized");
    return registration;
}
 
Example 11
Source Project: piggymetrics   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 12
Source Project: CAS   File: CasCustomConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 该过滤器使得可以通过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。
 * 比如AssertionHolder.getAssertion().getPrincipal().getName()。
 * 这个类把Assertion信息放在ThreadLocal变量中,这样应用程序不在web层也能够获取到当前登录信息
 *
 * @return
 */
@Bean
public FilterRegistrationBean assertionThreadLocalFilter() {
    FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
    filterRegistration.setFilter(new AssertionThreadLocalFilter());
    filterRegistration.setEnabled(true);
    if (autoconfig.getAssertionFilters().size() > 0) {
        filterRegistration.setUrlPatterns(autoconfig.getAssertionFilters());
    } else {
        filterRegistration.addUrlPatterns("/*");
    }
    filterRegistration.setOrder(7);
    return filterRegistration;
}
 
Example 13
@Bean
public FilterRegistrationBean<BasicAuthenticationFilter> basicAuthenticationFilterFilterRegistrationBean() {
    FilterRegistrationBean<BasicAuthenticationFilter> bean = new FilterRegistrationBean<>();
    bean.setFilter(new BasicAuthenticationFilter());
    bean.addUrlPatterns("/security/basic.html");
    return bean;
}
 
Example 14
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;
}
 
Example 15
@Bean
public FilterRegistrationBean servletRegistrationBean() {
    final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    final Slf4jMDCFilter log4jMDCFilterFilter = new Slf4jMDCFilter(responseHeader, mdcTokenKey, mdcClientIpKey, requestHeader);
    registrationBean.setFilter(log4jMDCFilterFilter);
    registrationBean.setOrder(2);
    return registrationBean;
}
 
Example 16
Source Project: MaxKey   File: MaxKeyConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean<TokenEndpointAuthenticationFilter> TokenEndpointAuthenticationFilter() {
    _logger.debug("TokenEndpointAuthenticationFilter init ");
    FilterRegistrationBean<TokenEndpointAuthenticationFilter> registration = new FilterRegistrationBean<TokenEndpointAuthenticationFilter>();
    registration.setFilter(new TokenEndpointAuthenticationFilter());
    registration.addUrlPatterns("/oauth/v20/token/*");
    registration.setName("TokenEndpointAuthenticationFilter");
    registration.setOrder(1);
    return registration;
}
 
Example 17
@Bean
public FilterRegistrationBean xAPIHeaderFilterBean() {
  FilterRegistrationBean registrationBean = new FilterRegistrationBean();
  registrationBean.setFilter(xAPIHeaderFilter);
  List<String> urls = new ArrayList<String>(1);
  urls.add("/xAPI/*");
  registrationBean.setUrlPatterns(urls);
  registrationBean.setOrder(4);
  return registrationBean;
}
 
Example 18
Source Project: spring-mvc-react   File: SpringWebConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean filterRegistrationBean() {
	CharacterEncodingFilter filter = new CharacterEncodingFilter();
	filter.setEncoding("UTF-8");

	FilterRegistrationBean registrationBean = new FilterRegistrationBean();
	registrationBean.setFilter(filter);
	registrationBean.addUrlPatterns("/*");
	return registrationBean;
}
 
Example 19
Source Project: spring-boot   File: WebMVCConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 自定义,并注册 filter (通过 FilterRegistrationBean),增加 XSSFilter
 *
 * @return
 */
@Bean
public FilterRegistrationBean someFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(new XSSFilter());
    registration.addUrlPatterns("/*");
    registration.setName("XSSFilter");
    log.info("XSSFilter initialized");
    return registration;
}
 
Example 20
Source Project: RuoYi-Vue   File: DruidConfig.java    License: MIT License 4 votes vote down vote up
/**
 * 去除监控页面底部的广告
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
@ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true")
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
{
    // 获取web监控页面的参数
    DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
    // 提取common.js的配置路径
    String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
    String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
    final String filePath = "support/http/resources/js/common.js";
    // 创建filter进行过滤
    Filter filter = new Filter()
    {
        @Override
        public void init(javax.servlet.FilterConfig filterConfig) throws ServletException
        {
        }
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                throws IOException, ServletException
        {
            chain.doFilter(request, response);
            // 重置缓冲区,响应头不会被重置
            response.resetBuffer();
            // 获取common.js
            String text = Utils.readFromResource(filePath);
            // 正则替换banner, 除去底部的广告信息
            text = text.replaceAll("<a.*?banner\"></a><br/>", "");
            text = text.replaceAll("powered.*?shrek.wang</a>", "");
            response.getWriter().write(text);
        }
        @Override
        public void destroy()
        {
        }
    };
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(filter);
    registrationBean.addUrlPatterns(commonJsPattern);
    return registrationBean;
}