|
17 | 17 | package org.springframework.boot.actuate.autoconfigure; |
18 | 18 |
|
19 | 19 | import java.io.IOException; |
20 | | -import java.lang.annotation.ElementType; |
21 | | -import java.lang.annotation.Retention; |
22 | | -import java.lang.annotation.RetentionPolicy; |
23 | | -import java.lang.annotation.Target; |
24 | 20 | import java.util.List; |
25 | 21 |
|
26 | 22 | import javax.servlet.Filter; |
|
38 | 34 | import org.springframework.beans.factory.SmartInitializingSingleton; |
39 | 35 | import org.springframework.beans.factory.annotation.Autowired; |
40 | 36 | import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties.Security; |
| 37 | +import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint; |
41 | 38 | import org.springframework.boot.actuate.endpoint.Endpoint; |
42 | 39 | import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint; |
43 | 40 | import org.springframework.boot.actuate.endpoint.HealthEndpoint; |
|
53 | 50 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; |
54 | 51 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
55 | 52 | import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; |
56 | | -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; |
57 | 53 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
58 | 54 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
59 | 55 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
60 | 56 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; |
61 | | -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; |
62 | 57 | import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; |
63 | 58 | import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; |
64 | 59 | import org.springframework.boot.autoconfigure.web.ServerProperties; |
65 | 60 | import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; |
66 | | -import org.springframework.boot.bind.RelaxedPropertyResolver; |
67 | 61 | import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; |
68 | 62 | import org.springframework.boot.context.embedded.EmbeddedServletContainerException; |
69 | 63 | import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; |
|
73 | 67 | import org.springframework.context.ApplicationListener; |
74 | 68 | import org.springframework.context.ConfigurableApplicationContext; |
75 | 69 | import org.springframework.context.annotation.Bean; |
76 | | -import org.springframework.context.annotation.ConditionContext; |
77 | | -import org.springframework.context.annotation.Conditional; |
78 | 70 | import org.springframework.context.annotation.Configuration; |
79 | 71 | import org.springframework.context.event.ContextClosedEvent; |
80 | | -import org.springframework.core.annotation.AnnotationAttributes; |
81 | 72 | import org.springframework.core.env.ConfigurableEnvironment; |
82 | 73 | import org.springframework.core.env.PropertySource; |
83 | | -import org.springframework.core.type.AnnotatedTypeMetadata; |
84 | 74 | import org.springframework.web.context.WebApplicationContext; |
85 | 75 | import org.springframework.web.filter.OncePerRequestFilter; |
86 | 76 | import org.springframework.web.servlet.DispatcherServlet; |
@@ -343,78 +333,4 @@ public static ManagementServerPort get(BeanFactory beanFactory) { |
343 | 333 |
|
344 | 334 | } |
345 | 335 |
|
346 | | - /** |
347 | | - * {@link Conditional} that checks whether or not an endpoint is enabled. Matches if |
348 | | - * the value of the {@code endpoints.<name>.enabled} property is {@code true}. Does |
349 | | - * not match if the property's value or {@code enabledByDefault} is {@code false}. |
350 | | - * Otherwise, matches if the value of the {@code endpoints.enabled} property is |
351 | | - * {@code true} or if the property is not configured. |
352 | | - * |
353 | | - * @since 1.2.4 |
354 | | - */ |
355 | | - @Conditional(OnEnabledEndpointCondition.class) |
356 | | - @Retention(RetentionPolicy.RUNTIME) |
357 | | - @Target(ElementType.METHOD) |
358 | | - public static @interface ConditionalOnEnabledEndpoint { |
359 | | - |
360 | | - /** |
361 | | - * The name of the endpoint. |
362 | | - * @return The name of the endpoint |
363 | | - */ |
364 | | - public String value(); |
365 | | - |
366 | | - /** |
367 | | - * Returns whether or not the endpoint is enabled by default. |
368 | | - * @return {@code true} if the endpoint is enabled by default, otherwise |
369 | | - * {@code false} |
370 | | - */ |
371 | | - public boolean enabledByDefault() default true; |
372 | | - |
373 | | - } |
374 | | - |
375 | | - private static class OnEnabledEndpointCondition extends SpringBootCondition { |
376 | | - |
377 | | - @Override |
378 | | - public ConditionOutcome getMatchOutcome(ConditionContext context, |
379 | | - AnnotatedTypeMetadata metadata) { |
380 | | - AnnotationAttributes annotationAttributes = AnnotationAttributes |
381 | | - .fromMap(metadata |
382 | | - .getAnnotationAttributes(ConditionalOnEnabledEndpoint.class |
383 | | - .getName())); |
384 | | - String endpointName = annotationAttributes.getString("value"); |
385 | | - boolean enabledByDefault = annotationAttributes |
386 | | - .getBoolean("enabledByDefault"); |
387 | | - ConditionOutcome specificEndpointOutcome = determineSpecificEndpointOutcome( |
388 | | - endpointName, enabledByDefault, context); |
389 | | - if (specificEndpointOutcome != null) { |
390 | | - return specificEndpointOutcome; |
391 | | - } |
392 | | - return determineAllEndpointsOutcome(context); |
393 | | - |
394 | | - } |
395 | | - |
396 | | - private ConditionOutcome determineSpecificEndpointOutcome(String endpointName, |
397 | | - boolean enabledByDefault, ConditionContext context) { |
398 | | - RelaxedPropertyResolver endpointPropertyResolver = new RelaxedPropertyResolver( |
399 | | - context.getEnvironment(), "endpoints." + endpointName + "."); |
400 | | - if (endpointPropertyResolver.containsProperty("enabled") || !enabledByDefault) { |
401 | | - boolean match = endpointPropertyResolver.getProperty("enabled", |
402 | | - Boolean.class, enabledByDefault); |
403 | | - return new ConditionOutcome(match, "The " + endpointName + " is " |
404 | | - + (match ? "enabled" : "disabled")); |
405 | | - } |
406 | | - return null; |
407 | | - } |
408 | | - |
409 | | - private ConditionOutcome determineAllEndpointsOutcome(ConditionContext context) { |
410 | | - RelaxedPropertyResolver allEndpointsPropertyResolver = new RelaxedPropertyResolver( |
411 | | - context.getEnvironment(), "endpoints."); |
412 | | - boolean match = Boolean.valueOf(allEndpointsPropertyResolver.getProperty( |
413 | | - "enabled", "true")); |
414 | | - return new ConditionOutcome(match, "All endpoints are " |
415 | | - + (match ? "enabled" : "disabled") + " by default"); |
416 | | - } |
417 | | - |
418 | | - } |
419 | | - |
420 | 336 | } |
0 commit comments