'Spring security formlogin and httpbasic

I am trying to learn spring security. For just dummy service, I made 3 endpoints :

/secured - should be authenticated
/unsecured - authenticated not required
/test - random api

Now as per I learned on the web, I added the custom config like :

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/secured").authenticated()
                .antMatchers("/unsecured").permitAll()
                .and()
                .formLogin()
                .and()
                .httpBasic();
    }
}

from what I experimented, when I did this

  • /secured api is getting secured
  • /unsecured api is getting unauthenticated access
  • /test is getting unauthenticated access

my confusion is that below 2 lines are registering the matchers :

.antMatchers("/secured").authenticated()
.antMatchers("/unsecured").permitAll()

but what is the use of

.formLogin()
.and()
.httpBasic();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source