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() . 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: AuthConfiguration.java    From apollo with 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 File: CatFilterConfigure.java    From piggymetrics with 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 File: WebMVCConfig.java    From spring-boot with 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 4
Source File: SpringWebConfig.java    From spring-mvc-react with 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 5
Source File: WebSecurityConfig.java    From OpenLRW with Educational Community License v2.0 5 votes vote down vote up
@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 6
Source File: MaxKeyConfig.java    From MaxKey with 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 7
Source File: Slf4jMDCFilterConfiguration.java    From GreenSummer with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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 8
Source File: WebConfiguration.java    From spring-boot-demo with 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 9
Source File: CustomConfiguration.java    From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public FilterRegistrationBean<BasicAuthenticationFilter> basicAuthenticationFilterFilterRegistrationBean() {
    FilterRegistrationBean<BasicAuthenticationFilter> bean = new FilterRegistrationBean<>();
    bean.setFilter(new BasicAuthenticationFilter());
    bean.addUrlPatterns("/security/basic.html");
    return bean;
}
 
Example 10
Source File: CasCustomConfig.java    From CAS with 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 11
Source File: CatFilterConfigure.java    From piggymetrics with 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 File: WebMVCConfig.java    From spring-boot with 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 13
Source File: FilterConfig.java    From Sentinel-Dashboard-Nacos with 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 14
Source File: FilterOrderConfig.java    From Qualitis with 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 15
Source File: BootStrap.java    From MyBlog with 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 16
Source File: FilterConfig.java    From sdb-mall with 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 17
Source File: VMockApplication.java    From v-mock with 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 18
Source File: FilterConfig.java    From radar with 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 19
Source File: FilterConfigFactory.java    From app-engine with 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 20
Source File: DruidConfig.java    From RuoYi-Vue with 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;
}