I want to configure my spring application security, all of requests should be authenticated before being served.
So I created a filter chain bean:
@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http)
throws Exception {
return http
.authorizeRequests().anyRequest().authenticated()
.and().formLogin()
.and().build();
}
I also found out authorizeRequests method has an overload version which accepts an Customizer interface parameter. So I tried the parameterized version.
@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http)
throws Exception {
return http
.authorizeRequests(authorizeRequests ->
authorizeRequests.anyRequest().authenticated()
)
.formLogin()
.and().build();
}
I noticed parameterized authorizeRequests method would return the same HttpSecurity object so you can keep configuring without calling and().
Is that the only difference between them ? If that so, wouldn't this overloaded version seemed to be redundant ?