For my SpringBoot project I configured Spring Security with a custom filter in order to authenticate the REST APIs.
Now I have two APIs sets and I need to have two different filters:
E.g. /api/** FilterA /admin/** FilterB
I tried to configure the Spring Security in this way:
//session management
http
.anonymous().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.csrf().disable();
//filter
http
.antMatcher("/api/**")
.addFilterBefore(new FilterA(), AbstractPreAuthenticatedProcessingFilter.class)
.authorizeRequests();
//filter
http
.antMatcher("/admin/**")
.addFilterBefore(new FilterB(), AbstractPreAuthenticatedProcessingFilter.class)
.authorizeRequests()
.anyRequest()
.authenticated();
http
.exceptionHandling().authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED));
This not works fine: Filter B validate /api/** requests also. Is it possible to have this? How can I configure it in order to reach the goal?