5 Implementing authentication

 

This chapter covers

  • Implementing authentication logic using a custom AuthenticationProvider

  • Using the HTTP Basic and form-based login authentication methods

  • Understanding and managing the SecurityContext component

In chapters 3 and 4, we covered a few of the components acting in the authentication flow. We discussed UserDetails and how to define the prototype to describe a user in Spring Security. We then used UserDetails in examples where you learned how the UserDetailsService and UserDetailsManager contracts work and how you can implement these. We discussed and used the leading implementations of these interfaces in examples as well. Finally, you learned how a PasswordEncoder manages the passwords and how to use one, as well as the Spring Security crypto module (SSCM) with its encryptors and key generators.

The AuthenticationProvider layer, however, is the one responsible for the logic of authentication. The AuthenticationProvider is where you find the conditions and instructions that decide whether to authenticate a request or not. The component that delegates this responsibility to the AuthenticationProvider is the AuthenticationManager, which receives the request from the HTTP filter layer. We’ll discuss the filters layer in detail in chapter 9. In this chapter, let’s look at the authentication process, which has only two possible results:

5.1 Understanding the AuthenticationProvider

5.1.1 Representing the request during authentication

5.1.2 Implementing custom authentication logic

5.1.3 Applying custom authentication logic

5.2 Using the SecurityContext

5.2.1 Using a holding strategy for the security context

5.2.2 Using a holding strategy for asynchronous calls

5.2.3 Using a holding strategy for standalone applications

5.2.4 Forwarding the security context with DelegatingSecurityContextRunnable

5.2.5 Forwarding the security context with DelegatingSecurityContextExecutorService

5.3 Understanding HTTP Basic and form-based login authentications

5.3.1 Using and configuring HTTP Basic

5.3.2 Implementing authentication with form-based login

Summary

sitemap