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.

3.1      Implementing authentication in Spring Security

3.2      Describing the user

3.2.1   Demystifying the definition of the UserDetails contract

3.2.2   Detailing on the GrantedAuthority contract

3.2.3   Writing the minimal implementation of the UserDetails

3.2.4   Using a builder to create instances of the UserDetails type

3.2.5   Combining multiple responsibilities related to the user

3.3      Instructing Spring Security on how to manage the users

3.3.1   Understanding the UserDetailsService contract

3.3.2   Implementing the UserDetailsService contract

3.3.3   Implementing the UserDetailsManager contract

3.4      Summary

sitemap