-
Notifications
You must be signed in to change notification settings - Fork 40.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
Disable user details auto-configuration if the application has resource server, saml, or oauth2-client dependencies #35338
Comments
UserDetailsServiceAutoConfiguration
is wrongfully activated if jwtkSetUri is set programmatically.UserDetailsServiceAutoConfiguration
is wrongfully activated if jwtkSetUri is set programmatically for MVC application.
Thanks for the example project. It defines the following Spring Security beans:
Unfortunately, I don't think there are any beans of a type that indicates that the user details service isn't needed. When using the equivalent properties-based configuration, the following beans are defined:
The auto-configured |
@wilkinsona, thanks for your analysis! I've configured the project as documented in the spring security documentation: https://docs.spring.io/spring-security/reference/5.8/servlet/oauth2/resource-server/jwt.html#oauth2resourceserver-jwt-jwkseturi-dsl Is the documentation missing information that NimbusJwtDecoder needs to be registered manually? In our productive system OAuth2 authentication worked without registering a NimbusJwtDecoder, but we got the annoying warning message described in the first comment, which seemed to be a false positive. |
No, I don't think so. Spring Security offers multiple ways of doing the same thing. You can set the
While we figure out what we can do to fix this, you should be able to work around it by adding the following to
|
We are going to look into backing off if |
UserDetailsServiceAutoConfiguration
is wrongfully activated if jwtkSetUri is set programmatically for MVC application.UserDetailsServiceAutoConfiguration
if the application has resource server, saml, or oauth2-client dependencies
UserDetailsServiceAutoConfiguration
if the application has resource server, saml, or oauth2-client dependenciesThere are some notable differences in the behavior of Spring Security's reactive and servlet-based web security. Notably, Servlet-based web security (`@EnableWebSecurity`) works without any authentication manager, rejecting requests as not authorized. By contrast reactive-based web security (`@EnableWebFluxSecurity`) fails to start up when there's no authentication manager, either provided directly as a bean or derived from a ReactiveUserDetailsService. There are also further differences at runtime where empty Monos from all ReactiveAuthenticationManagers results in an internal error and a 500 response whereas a similar situation in the servlet implementation results in a 401. Previously, to accommodate these differences in behavior, Spring Boot's auto-configuration would behave differently. In the Servlet case, web security would be enabled whenever the necessary dependencies were on the classpath. In the reactive case, web security would back off in the absence of an authentication manager to prevent a start up failure. While this difference is rooted in Spring Security, it is undesirable and something that we want to avoid Spring Boot users being exposed to where possible. Unfortunately, the situation is more likely to occur than before as ReactiveUserDetailsServiceAutoConfiguration now backs off more readily (gh-35338). This makes it more likely that the context will contain neither a reactive authetication manager not a reactive user details service. This commit reworks the auto-configurations related to reactive security. ReactiveSecurityAutoConfiguration will now auto-configure an "empty" reactive authentication manager that denies access through Mono.error in the absence of a ReactiveAuthenticationManager, ReactiveUserDetailsService, or SecurityWebFilterChain. The last of these is to allow for the situation where a filter chain has been defined with an authentication manager configured directly on it. This configuration of an authentication manager allows `@EnableWebFluxSecurity` to be auto-configured more readily, removing one of the differences between reactive- and Servlet-based security. Corresponding updates to the auto-configurations for reactive OAuth2 support have also been made. They no longer try to auto-configure `@EnableWebFluxSecurity`, relying instead upon ReactiveSecurityAutoConfiguration, which they are ordered before, to do that instead. Closes gh-38713
Description of the Bug
A warning appears on startup when configuring an OAuth2 Resource Server for an MVC application with an individual
jwkSetUri
programmatically (e.g., not using the default spring boot property).Configuration
Taken directly from https://docs.spring.io/spring-security/reference/5.8/servlet/oauth2/resource-server/jwt.html#oauth2resourceserver-jwt-jwkseturi-dsl:
Warning
It seems that the
UserDetailsServiceAutoConfiguration
is wrongfully activated.Example repo
I've created a repository with a small example project to demonstrate the issue. This issue is present in spring boot 2.7.x (main branch of example repo) and spring boot 3.x (spring boot 3 branch of example repo).
The text was updated successfully, but these errors were encountered: