Description
If I have a security application that doesn't actually perform any authentication and just parses an Authorization
header for a JWT token (a separate service that issues them may, on the other hand, perform some authentication), I'm unlikly to actually register any AuthenticationManager
s or UserDetailsService
s. As a result, I will likely trigger all these conditionals and have a pointless UserDetailsService
that matches against its in-memory map of one fake user in my context
@AutoConfiguration(before = ReactiveSecurityAutoConfiguration.class, after = RSocketMessagingAutoConfiguration.class)
@ConditionalOnClass({ ReactiveAuthenticationManager.class })
@ConditionalOnMissingClass({ "org.springframework.security.oauth2.client.registration.ClientRegistrationRepository",
"org.springframework.security.oauth2.server.resource.introspection.ReactiveOpaqueTokenIntrospector" })
@ConditionalOnMissingBean(
value = { ReactiveAuthenticationManager.class, ReactiveUserDetailsService.class,
ReactiveAuthenticationManagerResolver.class },
type = { "org.springframework.security.oauth2.jwt.ReactiveJwtDecoder" })
@Conditional(ReactiveUserDetailsServiceAutoConfiguration.ReactiveUserDetailsServiceCondition.class)
@EnableConfigurationProperties(SecurityProperties.class)
public class ReactiveUserDetailsServiceAutoConfiguration {
// SecurityProperties
public static class User {
/**
* Default user name.
*/
private String name = "user";
/**
* Password for the default user name.
*/
private String password = UUID.randomUUID().toString();
Besides, it reflects on my console output (in case the password stays a random UUID, the config prints this info message):
INFO 4528 --- [dynamic-gateway] [ main] ctiveUserDetailsServiceAutoConfiguration :
Using generated security password: 1d4b62fc-c703-4df9-a35f-8de5d5c7baab
It's not a tragedy since I don't inject it anywhere, but it feels wrong. I could register some stub AuthenticationManager
to avoid a match, but it's a kludge. Frankly, I don't see any purpose in extending Spring's autoconfiguration magic to UserDetailsService
. Even when you only start learning Spring Security, you can easily register some simple implementation, as you showed in your tutorial. In fact, it's even less straightforward for a beginner to go looking in their console output for the default password for their default user (which they may never suspect about)