From 8e583f6f73e2ec67e9e88891ae44a927f8ee7bf3 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 4 Jan 2022 12:06:20 -0800 Subject: [PATCH] Apply exclusion rules to child contributors Update `IncludeExcludeGroupMemberPredicate` so that exclusion rules are also applied to child contributors. The restores the behavior of Spring Boot 2.5.x where `management.endpoint.health.group.mygroup.exclude=db` would exclude 'db/one', 'db/two' etc. Fixes gh-29251 --- .../IncludeExcludeGroupMemberPredicate.java | 20 +++++++++++++------ ...cludeExcludeGroupMemberPredicateTests.java | 8 +++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java index f9464232c449..928822b12ba1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,10 +41,7 @@ class IncludeExcludeGroupMemberPredicate implements Predicate { @Override public boolean test(String name) { - return testCleanName(clean(name)); - } - - private boolean testCleanName(String name) { + name = clean(name); return isIncluded(name) && !isExcluded(name); } @@ -64,7 +61,18 @@ private boolean isIncludedName(String name) { } private boolean isExcluded(String name) { - return this.exclude.contains("*") || this.exclude.contains(name); + return this.exclude.contains("*") || isExcludedName(name); + } + + private boolean isExcludedName(String name) { + if (this.exclude.contains(name)) { + return true; + } + if (name.contains("/")) { + String parent = name.substring(0, name.lastIndexOf("/")); + return isExcludedName(parent); + } + return false; } private Set clean(Set names) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java index 71fdd6deb983..1033cb595bc5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,6 +112,12 @@ void specifiedIncludeShouldNotIncludeExcludedNested() { assertThat(predicate).accepts("test/a").rejects("test/b").rejects("foo"); } + @Test // gh-29251 + void specifiedExcludeShouldExcludeNestedChildren() { + Predicate predicate = include("*").exclude("test"); + assertThat(predicate).rejects("test").rejects("test/a").rejects("test/a").accepts("other"); + } + private Builder include(String... include) { return new Builder(include); }