spring-security: requestMatchers does not execute .permitAll() for not registered Bean
Describe the bug version
- spring boot 3.0.1
- spring security 6.0.1
not execute .permitAll()
just not registered controller.
To Reproduce
requestMatchers dose not execute .permitAll().
localhost:8080/data request response is 403 forbidden.
(“/data” URL is not mvcMatcher, not registered controller API)
but, all include matcher (“/**”) execute .permitAll().
Expected behavior
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/data").permitAll()
)
localhost:8080/data request expected 404 Not Found;
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 15 (2 by maintainers)
I found the cause.
Error page (“/error”) is created about 404 by request “/data” but, I didn’t handled error page. processed
authorizeHttpRequestsdefault denied. I solved this issue by “/error”.permitAllor.ignoring()Debugging through this annotation
@EnableWebSecurity(debug = true)this is my mistake. thank u @marcusdacoregio It you have any advice, comment please!
this saved me after many hours. thank you
In your dev environment, it is good to set the logging level of Spring Security to TRACE, this way you can debug faster what is happening in the filter chain. To do that change your
application.propertiesto include:logging.level.org.springframework.security=TRACEGlad you figured it out!
In my case, the following worked:
.requestMatchers("/", "index.html").permitAll()I just had to write the file’s extention 😃
Hi, @chrisegb
Did you get it to work? For me works when I add
.dispatcherTypeMatchers(FORWARD, ERROR).permitAll()before.requestMatchers("/...").permitAll()See Spring Security docs.
An example code:
Happy New Year!
Hi @rnjsrntkd95,
is your security configuration class annotated with
@EnableWebSecurityand@Configuration? If it is, can you share a minimal, reproducible sample so we simulate it on our side?