Skip to content
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

Even when spring.security.user.name or spring.security.user.password has been configured, user details auto-configuration still backs off when resource server is on the classpath #38864

Closed
rozagerardo opened this issue Dec 19, 2023 · 2 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@rozagerardo
Copy link

We've introduced the following feature with Boot 3.2:

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#auto-configured-user-details-service

Auto-configured User Details Service

The auto-configured InMemoryUserDetailsManager now backs off when one or more of spring-security-oauth2-client, spring-security-oauth2-resource-server, and spring-security-saml2-service-provider is on the classpath. Similarly, in reactive applications, the auto-configured MapReactiveUserDetailsService now backs off when one or more of spring-security-oauth2-client and spring-security-oauth2-resource-server is one the classpath.

If you are using one of the above dependencies yet still require an InMemoryUserDetailsManager or MapReactiveUserDetailsService in your application, define the required bean in your application.

Since spring-security-oauth2-authorization-server brings the spring-security-oauth2-resource-server as one of its dependencies, the default User Details Service backs off and the login authentication method fails with the minimal configuration suggested by the AS docs (here).

IMO it's expected and desirable (for a minimal configuration, of course) that a user can log in using the user/password authentication method to grant access to the OAuth2 Client to its resources.

So, I'd personally change the feature behavior to back off the default InMemoryUserDetailsManager for the conditions given above, and if the spring-security-oauth2-resource-server is not present in the dependencies.

Let me know what you think. This has also been reported as an Spring Authorization Server issue:

spring-projects/spring-authorization-server#1475

I guess before they can act upon this, it's on the Spring Boot's project to decide whether the default behavior should accommodate to the Spring AS minimal config (as I suggested above), or if it's ok as it is, and the Spring AS has to modify the minimal config guidelines, instructing to define a InMemoryUserDetailsManager bean in the context as well.

@wilkinsona
Copy link
Member

So, I'd personally change the feature behavior to back off the default InMemoryUserDetailsManager for the conditions given above, and if the spring-security-oauth2-resource-server is not present in the dependencies.

We can't do that, I'm afraid. Avoiding the warning about the generated password when using resource server was one of the primary motivators for #35338.

We think we may be able to improve the situation here by changing the conditions so that the auto-configuration does not back off if you've set spring.security.user.name and/or spring.security.user.password. That won't restore things exactly as they were in 3.1, but I think it's a good compromise. Authorization Server's minimal setup will then work with the small addition of setting spring.security.user.password

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Jan 17, 2024
@wilkinsona wilkinsona changed the title "InMemoryUserDetailsManager backing off" 3.2.0 feature messes up Authorization Server minimal configuration Even when spring.security.user.name or spring.security.user.password has been configured, user details auto-configuration still backs off when resource server is on the classpath Jan 17, 2024
@wilkinsona wilkinsona added this to the 3.2.x milestone Jan 17, 2024
@rozagerardo
Copy link
Author

rozagerardo commented Jan 18, 2024

Thanks for the response @wilkinsona. Sounds like a suitable solution to me.

I have also been getting familiarized a little bit with the conditional mechanism for auto-configurations, and I think I understand why the logic I suggested wouldn't be achievable. (BTW, I now see I made an error in my suggestion, I meant "if the spring-security-oauth2-authorization-server is not present in the dependencies.", not the RS one of course, but I guess you got the point anyway😄).

Thanks for looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants