concept authentication method in category spring

appears as: n authentication method, authentication method, uthentication method
Spring Security in Action

This is an excerpt from Manning's book Spring Security in Action.

Spring Boot also chooses an authentication method when configuring the defaults. This authentication method Spring chooses by default is the HTTP Basic access authentication and is the most straightforward access authentication method. Basic authentication only requires the client to send a username and a password through the HTTP Authorization header. In the value of the header, the client attaches the prefix Basic, followed by the Base64 encoding of the string that contains the username and password, separated by a colon (:).

This chapter covers the remaining parts of the authentication flow (the shaded boxes in figure 5.1). Then, in chapters 7 and 8, you’ll learn how authorization works, which is the process that follows authentication in the HTTP request. We have to discuss how to implement the AuthenticationProvider. To be able to do this, you first have to know how Spring Security understands a request in the authentication process. To give a clear description of how to represent a request, we start with the Authentication interface. Once we have discussed this, we go further and observe what happens with the details of a request after successful authentication. After successful authentication, we discuss the SecurityContext and the way Spring Security manages it. Close to the end of the chapter, you will learn how we could customize the HTTP Basic authentication method. Together with this, we’ll also discuss another option of authentication method we could use for our applications, the Form Login.

To change the authentication method to form login, in the configure(HttpSecurity http) method of the configuration class, instead of httpBasic(), call the formLogin() method of the HttpSecurity parameter. Listing 5.19 presents this change.

Listing 5.19 Changing the authentication method to form login
@Configuration
public class ProjectConfig
  extends WebSecurityConfigurerAdapter {
 
  @Override
  protected void configure(HttpSecurity http)
    throws Exception {
    http.formLogin();
    http.authorizeRequests().anyRequest().authenticated();
  }
}
Figure 9.13 We add our custom authentication filter at the location where the BasicAuthenticationFilter would have been if we were using HTTP Basic as an authentication method. This means our custom filter has the same ordering value.