Complete the code to enable actuator endpoints in Spring Boot.
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.[1](Application.class, args); } }
The SpringApplication.run() method starts the Spring Boot application and enables actuator endpoints if configured.
Complete the code to expose all actuator endpoints in application.properties.
management.endpoints.web.exposure.include=[1]Using * exposes all actuator endpoints.
Fix the error in the security configuration to require authentication for actuator endpoints.
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .requestMatchers(EndpointRequest.toAnyEndpoint()).[1]() .anyRequest().authenticated() .and() .httpBasic(); } }
The authenticated() method requires users to be logged in to access actuator endpoints.
Fill both blanks to configure HTTP Basic authentication and disable CSRF for actuator endpoints.
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().[1]()
.and()
.authorizeRequests()
.requestMatchers(EndpointRequest.toAnyEndpoint()).authenticated()
.and()
.[2]();
}CSRF protection is disabled for actuator endpoints using csrf().disable(). HTTP Basic authentication is enabled with httpBasic().
Fill all three blanks to create a user with username 'admin', password 'secret', and role 'ACTUATOR' in memory.
@Bean
public UserDetailsService users() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("[1]")
.password("[2]")
.roles("[3]")
.build();
return new InMemoryUserDetailsManager(user);
}This code creates an in-memory user with username 'admin', password 'secret', and role 'ACTUATOR' to secure actuator endpoints.