You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using sec:authorize in JSPX causes 'java.lang.NullPointerException: Cannot invoke "jakarta.servlet.ServletRegistration.getClassName()" because "registration" is null'
#15363
We are encountering an issue with the sec:authorize expression in JSPX files after upgrading to Spring Security 6.
We've created a simple Spring Boot application to reproduce the exception: jsp-demo.zip
In example.jspx, the sec:authorize expression is used.
When accessing the URL http://localhost:8080/jsp-demo/, the following exception is thrown:
java.lang.NullPointerException: Cannot invoke "jakarta.servlet.ServletRegistration.getClassName()" because "registration" is null
at org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry$DispatcherServletRequestMatcher.matches(AbstractRequestMatcherRegistry.java:514) ~[spring-security-config-6.3.1.jar:6.3.1]
at org.springframework.security.web.util.matcher.OrRequestMatcher.matches(OrRequestMatcher.java:58) ~[spring-security-web-6.3.1.jar:6.3.1]
Is there something missing in our configuration, or is this a bug?
The text was updated successfully, but these errors were encountered:
Note that #13562 has been filed to simplify the construction of MvcRequestMatcher.Builder.
Regarding what is going on:
When an application has DispatcherServlet and non-DispatcherServlets in its deployment, Spring Security must know which servlet a given request is destined for to compute the correct request matcher. In many cases, it can determine this on its own by inspecting the HttpServletRequest instance.
In the case of <sec:authorize url="/somepath">, though, there is only a mock request, so the container cannot provide the needed servlet information. Because of this and other factors, it is often necessary for a JSP-based application to use requestMatchers(RequestMatcher) instead of requestMatchers(String) to create your authorization rules.
When you do, you should determine whether the described endpoint is an MVC endpoint or not. If it is, you should use MvcRequestMatcher instead of AntPathRequestMatcher.
Steps Forward:
I believe for this ticket, we should improve the error message. Spring Security should be able to detect a mock request and then provide a more informative error message accordingly.
Hello,
We are encountering an issue with the
sec:authorize
expression in JSPX files after upgrading to Spring Security 6.We've created a simple Spring Boot application to reproduce the exception:
jsp-demo.zip
example.jspx
, thesec:authorize
expression is used.http://localhost:8080/jsp-demo/
, the following exception is thrown:Is there something missing in our configuration, or is this a bug?
The text was updated successfully, but these errors were encountered: