liveBook · Manning

MapReactiveUserDetailsService

As explained in Spring Security in Action, Second Edition

MapReactiveUserDetailsService is a Spring Security ReactiveUserDetailsService implementation that stores user details in memory.

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.

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains the reactive lookup contract and bean configuration, while deferring custom implementations and deeper authentication internals.
Examples
Demonstrates user john, read authority, HTTP Basic credentials, and a reactive /hello endpoint.
What you can do after
Apply it via a Spring bean to authenticate configured in-memory users in a reactive application.
How it connects
Connects ReactiveUserDetailsService with UserDetails, PasswordEncoder, ReactiveAuthenticationManager, AuthenticationWebFilter, and SecurityContext.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.