3 Managing users
This chapter covers
- Describing a user with the UserDetails interface.
- Using the UserDetailsService in the authentication flow.
- Creating a custom implementation of UserDetailsService.
- Creating a custom implementation of UserDetailsManager.
- Using the JdbcUserDetailsManager in the authentication flow.
One of my colleagues from university cooks pretty well. He’s not a chef in a fancy restaurant, but he’s quite passionate about cooking. One day, when sharing thoughts in a discussion, I asked him about how he manages to remember so many recipes. He told me that’s easy. “You don’t have to remember the whole recipe, but the way basic ingredients match with each other. It’s like some real-world contracts that tell you what you could and what you should not mix. Then for each recipe, you only remember some tricks”.
This analogy is very similar to the way architectures work. With any robust framework, we use contracts to decouple the implementations of the framework from the application built upon it. With Java, we use interfaces to define the contracts. A programmer is similar to a chef knowing how the ingredients “work” together to choose the “implementation”. When using a framework, the programmer knows the framework's abstractions and uses them to integrate with it.
This chapter is about understanding in detail one of the fundamental roles you’ve encountered in the first example we’ve worked on in chapter 2: the UserDetailsService.