-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible bug in AbstractRequestMatcherRegistry#requireOnlyPathMappedDispatcherServlet? (DispatcherServlet not found when resolving request matcher) #15684
Comments
Perhaps I'm starting to understand the logic behind this implementation, which is probably as intended. So, Spring Security uses MVC matchers when using TBH, it was not easy to grasp this and I think the documentation is not so clear. Looking at the documentation at:
it seems to suggest that just having Spring Web MVC on the classpath makes usage of Is my understanding right? |
Thanks for reaching out, @mauromol. You can see a more detailed explanation in the 6.x documentation. There may be value in updating the 5.8.x documentation to include this. I will summarize a bit of it here in order to address your questions.
Close. Because Spring MVC endpoints are expressed without the servlet path, Spring Security can only safely compute them when
I don't think that's the case, though I'd welcome a unit test to demonstrate what you are surmising from the code. The method in question might be better named The intent is that the configuration fail with Spring MVC if either one of these is true:
In those cases, the application must clarify whether each is an MVC endpoint or not. You can see this tested for in Does this help? |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Hi Josh, I admit I was wrong: even though I read that code multiple times, I didn't get that the key is this exit condition from the loop: if (pathDispatcherServlet != null) {
return null;
} I wasn't seeing it, and so I assumed the loop was going on and finally taking the last dispatcher servlet instance matching the required conditions. Anyway, it's probably a bit unusual as a way to implement the algorithm you mentioned, but it's right, so please apologize. Still, I don't fully grasp why you really need to do all of this anyway. "Because Spring MVC endpoints are expressed without the servlet path"... right, but... since we're serving a request and hence we have the HTTP request at hand, its context path and servlet path, can't some URL matching be done to determine if the incoming request is served by any of the registered DispatcherServlets, whatever is their mapping? I also did a quick look at the Spring Security 6 docs, but it didn't help (perhaps I didn't find it?). The main issue is that: if you have a regular web application with some servlets, and you register even a single DispatcherServlet along with them, the |
This isn't true unless
I'd recommend taking a look at the unit tests in
I do agree that it would be nice to alert the developer sooner. Perhaps there is an evolution of the DSL that would make the configuration unambiguous. You can follow #13562 and its linked issues to learn more about this. |
Describe the bug
Once I added a
DispatcherServlet
to my EAR application deployed on JBoss 7.4, I started to get the following exception:To Reproduce
Adding a security filter chain with some request matchers; something like this:
Expected behavior
I would expect Spring Security to find my
DispatcherServlet
mapping and so to use aMvcRequestMatcher
.Please have a look at this line:
spring-security/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistry.java
Line 289 in e90a6b6
Shouldn't it be
continue
instead ofreturn null
, just like it is forrequireOneRootDispatcherServlet
?Otherwise this loop will always end on the first mapping if it's not a
DispatcherServlet
...Please note I'm on Spring Security 5.8.13 and that line is number 408 instead.
The text was updated successfully, but these errors were encountered: