Creating our own users with a custom security policy
Spring Security has a highly pluggable architecture, which we shall take full advantage of throughout this chapter.
The key aspects of securing any application are as follows:
- Defining the source of users
- Creating access rules for the users
- Associating various parts of the app with the access rules
- Applying the policy to all aspects of the application
Let’s start with the first step and create a source of users. Spring Security comes with an interface for just this task: UserDetailsService
.
To leverage this, we’ll start by creating a SecurityConfig
Java class with the following code:
@Configuration public class SecurityConfig { @Bean public UserDetailsService userDetailsService() { UserDetailsManager userDetailsManager = new InMemoryUserDetailsManager(); userDetailsManager...