MapReactiveUserDetailsService is a Spring Security implementation of ReactiveUserDetailsService that retrieves user details from an in-memory map. Its lookup returns a reactive Mono<UserDetails>, allowing reactive authentication to obtain users without a custom implementation. section 17.2
Listing 17.2 The ProjectConfig class
@Configuration
public class ProjectConfig {
@Bean #1
public ReactiveUserDetailsService userDetailsService() {
var u = User.withUsername("john") #2
.password("12345")
.authorities("read")
.build();
var uds = new MapReactiveUserDetailsService(u); #3
return uds;
}
@Bean #4
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
}
Register the service as a bean, create a user with credentials and authority, and connect a PasswordEncoder for authentication. section 17.2
Authenticating an in-memory user
A configuration can store user john with password 12345 and read authority. Calling /hello with curl -u john:12345 authenticates successfully and returns a response such as Hello! or Hello john.
