Challenge - 5 Problems
SecurityFilterChain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the effect of this SecurityFilterChain configuration?
Consider this Spring Boot SecurityFilterChain bean configuration. What will be the behavior when a user tries to access the "/admin" endpoint without authentication?
Spring Boot
import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.web.SecurityFilterChain; @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests(auth -> auth .requestMatchers("/admin").authenticated() .anyRequest().permitAll() ) .formLogin(); return http.build(); }
Attempts:
2 left
💡 Hint
Think about what .authenticated() means and what formLogin() does.
✗ Incorrect
The configuration requires authentication for "/admin" and enables form login. So unauthenticated users are redirected to the login page.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this SecurityFilterChain configuration
Which option correctly fixes the syntax error in this Spring SecurityFilterChain configuration snippet?
Spring Boot
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/user").hasRole("USER")
.anyRequest().authenticated()
)
.formLogin()
.and()
.csrf().disable();Attempts:
2 left
💡 Hint
Check how method chaining works in HttpSecurity configuration.
✗ Incorrect
In the new lambda style, .and() is not needed; chaining .csrf().disable() directly after .formLogin() is correct.
❓ state_output
advanced2:00remaining
What is the value of 'isCsrfEnabled' after this configuration?
Given this SecurityFilterChain configuration, what is the value of the boolean variable 'isCsrfEnabled' after the filter chain is built?
Spring Boot
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.web.SecurityFilterChain; boolean isCsrfEnabled; @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .csrf(csrf -> csrf.disable()) .authorizeHttpRequests(auth -> auth.anyRequest().permitAll()); isCsrfEnabled = http.getConfigurer(org.springframework.security.config.annotation.web.configurers.CsrfConfigurer.class) != null; return http.build(); }
Attempts:
2 left
💡 Hint
Disabling CSRF removes its configurer from HttpSecurity.
✗ Incorrect
Calling csrf.disable() disables CSRF protection and removes its configurer, so getConfigurer returns null, making isCsrfEnabled false.
🔧 Debug
advanced2:00remaining
Why does this SecurityFilterChain configuration cause a runtime error?
This SecurityFilterChain configuration throws an exception at runtime. What is the cause?
Spring Boot
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/**").hasAuthority("ADMIN")
.anyRequest().authenticated()
)
.httpBasic()
.csrf(csrf -> csrf.disable())
.build();Attempts:
2 left
💡 Hint
Check how SecurityFilterChain beans are created and returned.
✗ Incorrect
Calling .build() on HttpSecurity outside a @Bean method or without returning it causes runtime errors because Spring Security expects a bean of type SecurityFilterChain.
🧠 Conceptual
expert2:00remaining
Which option best describes the role of SecurityFilterChain in Spring Security?
Select the most accurate description of what a SecurityFilterChain does in a Spring Boot application.
Attempts:
2 left
💡 Hint
Think about what filters do in web security.
✗ Incorrect
SecurityFilterChain is a chain of filters that intercept HTTP requests to apply security checks like authentication and authorization.