Complete the code to define a SecurityFilterChain bean in Spring Boot.
public @Bean SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf().disable()
.authorizeHttpRequests(auth -> auth.anyRequest().[1]())
.build();
}The permitAll() method allows all requests without authentication.
Complete the code to disable CSRF protection in the SecurityFilterChain.
public @Bean SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.[1]();
return http.build();
}Calling csrf().disable() disables CSRF protection.
Fix the error in the code to require authentication for all requests.
public @Bean SecurityFilterChain securityChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth -> auth.anyRequest().[1]());
return http.build();
}The authenticated() method requires users to be logged in for all requests.
Fill both blanks to configure HTTP Basic authentication and disable CSRF.
public @Bean SecurityFilterChain securityConfig(HttpSecurity http) throws Exception {
http.[1]();
http.[2]();
return http.build();
}Use httpBasic() to enable HTTP Basic auth and csrf().disable() to disable CSRF protection.
Fill all three blanks to create a SecurityFilterChain that disables CSRF, requires authentication for all requests, and enables HTTP Basic authentication.
public @Bean SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().[1]();
http.authorizeHttpRequests(auth -> auth.anyRequest().[2]());
http.[3]();
return http.build();
}Disable CSRF with disable(), require authentication with authenticated(), and enable HTTP Basic with httpBasic().