@@ -104,6 +104,26 @@ protected void doFilterInternal(HttpServletRequest request,
104104 };
105105 }
106106
107+ /**
108+ * Configuration for Actuator endpoints.
109+ * It uses Basic Auth for Metricbeat/observability tools.
110+ */
111+ @ Bean
112+ @ Order (0 ) // Highest priority
113+ public SecurityFilterChain actuatorSecurity (HttpSecurity http , OncePerRequestFilter mdcFilter ) throws Exception {
114+ http
115+ .securityMatcher ("/actuator/**" )
116+ .authorizeHttpRequests (auth -> auth
117+ .anyRequest ().hasRole ("ADMIN" )
118+ )
119+ .httpBasic (Customizer .withDefaults ())
120+ .csrf (AbstractHttpConfigurer ::disable )
121+ .sessionManagement (sm -> sm .sessionCreationPolicy (SessionCreationPolicy .STATELESS ))
122+ .addFilterAfter (mdcFilter , UsernamePasswordAuthenticationFilter .class );
123+
124+ return http .build ();
125+ }
126+
107127 /**
108128 * Configuration for the REST API (/api/**).
109129 * It uses JWT (JSON Web Tokens) and is 'stateless', meaning the server doesn't remember the user between requests.
@@ -148,10 +168,9 @@ public SecurityFilterChain mvcSecurity(HttpSecurity http, OncePerRequestFilter m
148168 // Permit access to static resources without logging in
149169 .requestMatchers ("/css/**" , "/js/**" , "/images/**" , "/webjars/**" , "/favicon.ico" ).permitAll ()
150170 // Permit access to home, signup, and error pages
151- .requestMatchers ("/" , "/signup" , "/errors " ).permitAll ()
152- // Only users with ADMIN role can access /admin/** and Actuator
171+ .requestMatchers ("/" , "/signup" , "/error " ).permitAll ()
172+ // Only users with ADMIN role can access /admin/**
153173 .requestMatchers ("/admin/**" ).hasRole ("ADMIN" )
154- .requestMatchers (EndpointRequest .toAnyEndpoint ()).permitAll ()
155174 // Everything else requires the user to be logged in
156175 .anyRequest ().authenticated ())
157176 .formLogin (login -> login
0 commit comments