concept user management in category spring

This is an excerpt from Manning's book Spring Security in Action.
If you’ve authentication and authorization, it also means that you should have some users with valid credentials. Depending on your choice, you could have your application managing the credentials for the users, or you could choose to benefit from another system to do this (for example, you might want to let the user log in with their Facebook, GitHub, or LinkedIn credentials). In any of these cases, Spring Security helps you with a relatively easy way of configuring user management. You can choose to store user information in a database, use a web-service, or connect to another platform. The abstractions used in Spring Security’s architecture make it decoupled, which allows you to choose any implementation fit for your application.
As part of user management, we’ll use the UserDetailsService and UserDetailsManager interfaces. The UserDetailsService is only responsible for retrieving the user by its username. This action is the only one needed by the framework to complete authentication. The UserDetailsManager adds behavior that refers to adding, modifying, or deleting the user, which is required functionality in most of the applications. The separation between the two contracts is an excellent example of the “interface segregation” principle. Separating the interfaces allows for better flexibility as the framework doesn’t force you to implement behavior if your app doesn’t need it. If the app only needs to authenticate the users, then implementing the UserDetailsService contract is enough to cover the desired functionality. To manage the users, the UserDetailsService and the UserDetailsManager components need a way to represent them.
Figure 3.2 Dependencies between the components involved in user management. The UserDetailsService returns the details of a user finding the user by its name. The UserDetails contract describes the user. A user has one or more authorities ( represented by the GrantedAuthority interface). The UserDetailsManager contract extends UserDetailsService to add operations with the user, such as create, delete or change of its password.
![]()
Listing 19.6 The configuration class declares components for the user management
@Configuration public class ProjectConfig { @Bean public ReactiveUserDetailsService userDetailsService() { var u = User.withUsername("john") .password("12345") .authorities("read") .build(); var uds = new MapReactiveUserDetailsService(u); return uds; } @Bean public PasswordEncoder passwordEncoder() { return NoOpPasswordEncoder.getInstance(); } // … }