1 package cn.home1.oss.boot.autoconfigure;
2
3 import static org.apache.commons.lang3.StringUtils.isNotBlank;
4
5 import org.springframework.util.AntPathMatcher;
6
7 import java.util.function.Predicate;
8
9
10
11
12 public abstract class PathUtils {
13
14 private PathUtils() {
15 }
16
17
18
19
20
21
22 public static Predicate<String> any() {
23 return t -> true;
24 }
25
26
27
28
29
30
31 public static Predicate<String> none() {
32 return t -> false;
33 }
34
35
36
37
38
39
40
41 public static Predicate<String> regex(final String pathRegex) {
42 return input -> input.matches(pathRegex);
43 }
44
45
46
47
48
49
50
51 public static Predicate<String> ant(final String antPattern) {
52 return input -> {
53 AntPathMatcher matcher = new AntPathMatcher();
54 return matcher.match(antPattern, input);
55 };
56 }
57
58 public static Predicate<String> managementPaths(final String managementContextPath) {
59 final Predicate<String> result;
60 if (isNotBlank(managementContextPath)) {
61 result = regex(managementContextPath + "/.*")
62 .or(ant(managementContextPath))
63 .or(ant(managementContextPath + "" + ".json"))
64 .or(regex("/env(\\..+|/.*)?"))
65 .or(regex("/restart(\\..+|/.*)?"))
66 ;
67 } else {
68 result = regex("/archaius(\\..+|/.*)?")
69 .or(regex("/autoconfig(\\..+|/.*)?"))
70 .or(regex("/beans(\\..+|/.*)?"))
71 .or(regex("/configprops(\\..+|/.*)?"))
72 .or(regex("/dump(\\..+|/.*)?"))
73 .or(regex("/features(\\..+|/.*)?"))
74 .or(regex("/info(\\..+|/.*)?"))
75 .or(regex("/mappings(\\..+|/.*)?"))
76 .or(regex("/trace(\\..+|/.*)?"))
77 .or(regex("/env(\\..+|/.*)?"))
78
79 .or(regex("/pause(\\..+|/.*)?"))
80 .or(regex("/refresh(\\..+|/.*)?"))
81 .or(regex("/resume(\\..+|/.*)?"))
82 .or(regex("/actuator(\\..+|/.*)?"))
83 .or(regex("/health(\\..+|/.*)?"))
84 .or(regex("/heapdump(\\..+|/.*)?"))
85 .or(regex("/jolokia(\\..+|/.*)?"))
86 .or(regex("/logfile(\\..+|/.*)?"))
87 .or(regex("/metrics(\\..+|/.*)?"))
88 .or(regex("/restart(\\..+|/.*)?"))
89 .or(regex("/shutdown(\\..+|/.*)?"))
90 ;
91 }
92 return result;
93 }
94
95 public static Boolean isManagementPath(final String managementContextPath, final String servletPath) {
96 return managementPaths(managementContextPath).test(servletPath);
97 }
98 }