0

I've created manually a new spring FilterChainProxy:

private FilterChainProxy getCustomFilterChainProxy()
{
    List<SecurityFilterChain> securityFilterChains = new ArrayList<SecurityFilterChain>();
    securityFilterChains.add(new DefaultSecurityFilterChain( new AntPathRequestMatcher("/**"), new MyFilter1()));
    securityFilterChains.add(new DefaultSecurityFilterChain( new AntPathRequestMatcher("/admin/**"), new MyFilter2()));

    return new FilterChainProxy(securityFilterChains);      
}

And considering that I have a new HttpServletRequest, I would like to check the request against the custom FilterChainProxy. Something like this:

FilterChainProxy customFilterChainProxy = getCustomFilterChainProxy();
customFilterChainProxy.doFilter(request, null, (FilterChain) customFilterChainProxy.getFilterChains() );

But I'm struggling in correctly define the FilterChain used in the 3rd parameter of the doFilter() method.

How can I do this ?

Thanks.

Kleyson Rios
  • 2,597
  • 5
  • 40
  • 65

1 Answers1

0

Why don't you write an integration test, using MockMvc with .apply(SecurityMockMvcConfigurers.springSecurity()) Here is a link to an post about integration MockMvc and SpringSecurity.

It is extremely useful, and allows you to test your login, and protected services. I often find myself writing/modifying the test before I try to see if it works in a browser.

Community
  • 1
  • 1
Klaus Groenbaek
  • 4,820
  • 2
  • 15
  • 30