Think about which endpoints provide non-sensitive information by default.
By default, Spring Boot actuator exposes only the health and info endpoints publicly. Other endpoints require authentication.
Remember the difference between hasRole and hasAuthority in Spring Security.
The hasRole("ADMIN") method automatically prefixes the role with ROLE_. Using hasAuthority("ROLE_ADMIN") is valid but less common. Option B uses the correct and common pattern.
http.authorizeHttpRequests() .requestMatchers("/actuator/**").authenticated() .and() .httpBasic();
Think about how Spring Security processes multiple rules and their order.
Spring Security applies rules in order. If a more permissive rule matches before the restrictive one, the restrictive rule is ignored. The configuration likely has a rule permitting access before this one.
Consider what the wildcard * means in this context.
The wildcard * means all actuator endpoints are exposed over HTTP, including sensitive ones like shutdown or metrics.
Think about balancing functionality and security in production.
Best practice is to expose only needed endpoints, secure them with role-based authentication, and use HTTPS to protect data in transit.