0
0
Spring Bootframework~10 mins

Spring Security auto-configuration in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable Spring Security auto-configuration in a Spring Boot application.

Spring Boot
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.[1](Application.class, args);
    }
}
Drag options to blanks, or click blank then click option'
Astart
Brun
Claunch
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'launch' instead of 'run' causes compilation errors.
Forgetting to call any method to start the application.
2fill in blank
medium

Complete the code to add a dependency that triggers Spring Security auto-configuration in Maven's pom.xml.

Spring Boot
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-[1]</artifactId>
</dependency>
Drag options to blanks, or click blank then click option'
Asecurity
Bweb
Cdata-jpa
Dthymeleaf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'web' or 'data-jpa' does not enable security auto-configuration.
Forgetting to add the security starter dependency.
3fill in blank
hard

Fix the error in the code to disable Spring Security auto-configuration in a Spring Boot test.

Spring Boot
@SpringBootTest(
  exclude = [1].class
)
public class SecurityDisabledTest {}
Drag options to blanks, or click blank then click option'
AEnableWebSecurity
BWebSecurityConfigurerAdapter
CSecurityAutoConfiguration
DSecurityFilterChain
Attempts:
3 left
💡 Hint
Common Mistakes
Excluding WebSecurityConfigurerAdapter does not disable auto-configuration.
Using EnableWebSecurity or SecurityFilterChain classes here is incorrect.
4fill in blank
hard

Fill both blanks to customize HTTP security by disabling CSRF and permitting all requests.

Spring Boot
@Configuration
@EnableWebSecurity
public class SecurityConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.csrf().[1]();
        http.authorizeHttpRequests().anyRequest().[2]();
        return http.build();
    }
}
Drag options to blanks, or click blank then click option'
Adisable
BpermitAll
Cauthenticated
Denable
Attempts:
3 left
💡 Hint
Common Mistakes
Using csrf().enable() instead of disable() causes errors.
Using authenticated() instead of permitAll() restricts access.
5fill in blank
hard

Fill both blanks to create a password encoder bean using BCryptPasswordEncoder.

Spring Boot
@Configuration
public class PasswordConfig {
    @Bean
    public [1] passwordEncoder() {
        return new [2]();
    }
}
Drag options to blanks, or click blank then click option'
APasswordEncoder
BBCryptPasswordEncoder
CPasswordEncoderImpl
DSecurityConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using PasswordEncoderImpl which does not exist.
Returning SecurityConfig instead of a password encoder.