📖 Scenario: You are building a Spring Boot application that exposes actuator endpoints for monitoring. To keep your app safe, you want to secure these endpoints so only authorized users can access them.
🎯 Goal: Secure the Spring Boot actuator endpoints by setting up user credentials and restricting access to the endpoints.
📋 What You'll Learn
Create a Spring Boot application properties configuration with actuator endpoints enabled
Add a user credential configuration for basic authentication
Configure security to restrict actuator endpoints to authenticated users
Verify the actuator endpoints are secured with authentication
💡 Why This Matters
🌍 Real World
Monitoring and managing Spring Boot applications safely in production by securing sensitive actuator endpoints.
💼 Career
Spring Boot developers often need to secure actuator endpoints to protect application health and metrics data from unauthorized access.
Progress0 / 4 steps
1
Enable actuator endpoints
Create a file src/main/resources/application.properties and add these exact lines to enable all actuator endpoints and expose them over HTTP: management.endpoints.web.exposure.include=* and management.endpoint.health.show-details=always.
Spring Boot
Hint
This configuration allows all actuator endpoints to be accessible over HTTP and shows detailed health info.
2
Add user credentials for basic authentication
In the same application.properties file, add these exact lines to create a user with username admin and password secret with role ACTUATOR: spring.security.user.name=admin, spring.security.user.password=secret, and spring.security.user.roles=ACTUATOR.
Spring Boot
Hint
This sets up a basic user for authentication with the role ACTUATOR.
3
Configure security to restrict actuator endpoints
Create a Java class ActuatorSecurityConfig in package com.example.demo that is annotated with @Configuration and @EnableWebSecurity. Inside, define a SecurityFilterChain bean named securityFilterChain that restricts access so only users with role ACTUATOR can access paths starting with /actuator/. Use HTTP Basic authentication and permit all other requests without authentication.
Spring Boot
Hint
This configures HTTP Basic authentication and restricts actuator endpoints to users with ACTUATOR role.
4
Complete security setup and test
Add the @SpringBootApplication annotation to your main application class DemoApplication in package com.example.demo. Ensure the application runs and the actuator endpoints require authentication with username admin and password secret.
Spring Boot
Hint
This completes the Spring Boot app setup with secured actuator endpoints. Run the app and test accessing /actuator/health with the admin credentials.
Practice
(1/5)
1. What is the main purpose of securing Spring Boot actuator endpoints?
easy
A. To improve application performance by disabling endpoints
B. To automatically update actuator endpoints without manual configuration
C. To enable actuator endpoints for all users without restrictions
D. To protect sensitive application information from unauthorized access
Solution
Step 1: Understand actuator endpoints role
Actuator endpoints provide information about the app's health, metrics, and configuration.
Step 2: Recognize security importance
Since these endpoints expose sensitive data, securing them prevents unauthorized users from accessing this info.
Final Answer:
To protect sensitive application information from unauthorized access -> Option D
Quick Check:
Actuator security = protect info [OK]
Hint: Actuator endpoints show app info; protect them from strangers [OK]
Common Mistakes:
Thinking actuator endpoints improve performance
Assuming all endpoints should be open
Believing security auto-applies without config
2. Which property correctly exposes only the health and info actuator endpoints in application.properties?
easy
A. management.endpoints.web.expose=health,info
B. management.endpoints.web.exposure.include=health,info
C. management.endpoints.exposure.include=health,info
D. management.web.endpoints.include=health,info
Solution
Step 1: Identify correct property name
The correct property to expose endpoints is management.endpoints.web.exposure.include.
Step 2: Verify property value format
Comma-separated list of endpoints like health,info is correct.
Final Answer:
management.endpoints.web.exposure.include=health,info -> Option B
A. The requestMatchers pattern is incorrect syntax
B. The method should return void, not SecurityFilterChain
C. Actuator endpoints require login but other URLs are open, risking security
D. The configuration disables all security
Solution
Step 1: Review authorization rules order
Actuator endpoints require authentication, but all other requests are permitted without login.
Step 2: Identify security risk
This means non-actuator URLs are open, which might expose sensitive parts unintentionally.
Final Answer:
Actuator endpoints require login but other URLs are open, risking security -> Option C
Quick Check:
PermitAll on anyRequest risks open access [OK]
Hint: Check if anyRequest().permitAll() opens unwanted URLs [OK]
Common Mistakes:
Thinking method return type is wrong
Assuming requestMatchers syntax is invalid
Believing security is fully disabled
5. You want to expose only the health endpoint publicly and secure all other actuator endpoints to ADMIN role. Which configuration achieves this correctly?
hard
A. Expose health only and configure security to permit all on /actuator/health and ADMIN role on /actuator/** except health
B. Expose all endpoints and secure only /actuator/health to ADMIN role
C. Expose health and info endpoints and allow anonymous access to all actuator URLs
D. Expose no endpoints and disable security for actuator URLs
Solution
Step 1: Set exposure property
Use management.endpoints.web.exposure.include=health to expose only health publicly.
Step 2: Configure security rules
Permit all access to /actuator/health and require ADMIN role for other actuator endpoints using requestMatchers.
Final Answer:
Expose health only and configure security to permit all on /actuator/health and ADMIN role on /actuator/** except health -> Option A
Quick Check:
Expose health public + secure others ADMIN [OK]
Hint: Expose health only, secure others with ADMIN role [OK]
Common Mistakes:
Exposing too many endpoints publicly
Not securing non-health actuator endpoints
Allowing anonymous access to sensitive endpoints
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.