Spring Boot with Filter
in developCo-De with 7 comments

Spring Boot with Filter

in developCo-De with 7 comments

@WebFilter

Use FilterRegistrationBean

Filter with Autowire

Code Piece

WebFilterConfiguration

@SpringBootConfiguration
public class WebFilterConfiguration {
  @Bean
  public FilterRegistrationBean<BasicAuthFilter> basicAuthFilterFilterRegistrationBean() {
    FilterRegistrationBean<BasicAuthFilter> filterFilterRegistrationBean =
      new FilterRegistrationBean<>();
    filterFilterRegistrationBean.setFilter(getBasicAuthFilter());
    filterFilterRegistrationBean.addUrlPatterns("/open/*");
    filterFilterRegistrationBean.setOrder(Ordered.LOWEST_PRECEDENCE - 1);
    return filterFilterRegistrationBean;
  }
  @Bean
  public BasicAuthFilter getBasicAuthFilter() {
    return new BasicAuthFilter();
  }
}

Filter

public class BasicAuthFilter implements Filter {
  @Autowired private PathMatcher pathMatcher;
  @Autowired private ResourceService resourceService;
  @Autowired private UrlPathHelper urlPathHelper;

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

  @Override
  public void doFilter(
  ......
}  

Cont.

Comments are closed.