Skip to content

Commit a4b0be0

Browse files
committed
Polish
1 parent 220f8cd commit a4b0be0

File tree

29 files changed

+467
-350
lines changed

29 files changed

+467
-350
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java

+42-29
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ private EndpointRequest() {
5959
}
6060

6161
/**
62-
* Returns a matcher that includes all {@link Endpoint actuator endpoints}. It also includes
63-
* the links endpoint which is present at the base path of the actuator endpoints. The
64-
* {@link EndpointServerWebExchangeMatcher#excluding(Class...) excluding} method can
65-
* be used to further remove specific endpoints if required. For example:
66-
* <pre class="code">
62+
* Returns a matcher that includes all {@link Endpoint actuator endpoints}. It also
63+
* includes the links endpoint which is present at the base path of the actuator
64+
* endpoints. The {@link EndpointServerWebExchangeMatcher#excluding(Class...)
65+
* excluding} method can be used to further remove specific endpoints if required. For
66+
* example: <pre class="code">
6767
* EndpointRequest.toAnyEndpoint().excluding(ShutdownEndpoint.class)
6868
* </pre>
6969
* @return the configured {@link ServerWebExchangeMatcher}
@@ -97,11 +97,13 @@ public static EndpointServerWebExchangeMatcher to(String... endpoints) {
9797
}
9898

9999
/**
100-
* Returns a matcher that matches only on the links endpoint. It can be used when security configuration
101-
* for the links endpoint is different from the other {@link Endpoint actuator endpoints}. The
102-
* {@link EndpointServerWebExchangeMatcher#excludingLinks() excludingLinks} method can be used in combination with this
103-
* to remove the links endpoint from {@link EndpointRequest#toAnyEndpoint() toAnyEndpoint}.
104-
* For example: <pre class="code">
100+
* Returns a matcher that matches only on the links endpoint. It can be used when
101+
* security configuration for the links endpoint is different from the other
102+
* {@link Endpoint actuator endpoints}. The
103+
* {@link EndpointServerWebExchangeMatcher#excludingLinks() excludingLinks} method can
104+
* be used in combination with this to remove the links endpoint from
105+
* {@link EndpointRequest#toAnyEndpoint() toAnyEndpoint}. For example:
106+
* <pre class="code">
105107
* EndpointRequest.toLinks()
106108
* </pre>
107109
* @return the configured {@link ServerWebExchangeMatcher}
@@ -121,20 +123,24 @@ public static final class EndpointServerWebExchangeMatcher
121123

122124
private final List<Object> excludes;
123125

124-
private ServerWebExchangeMatcher delegate;
126+
private final boolean includeLinks;
125127

126-
private boolean includeLinks;
128+
private ServerWebExchangeMatcher delegate;
127129

128130
private EndpointServerWebExchangeMatcher(boolean includeLinks) {
129131
this(Collections.emptyList(), Collections.emptyList(), includeLinks);
130132
}
131133

132-
private EndpointServerWebExchangeMatcher(Class<?>[] endpoints, boolean includeLinks) {
133-
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
134+
private EndpointServerWebExchangeMatcher(Class<?>[] endpoints,
135+
boolean includeLinks) {
136+
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(),
137+
includeLinks);
134138
}
135139

136-
private EndpointServerWebExchangeMatcher(String[] endpoints, boolean includeLinks) {
137-
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
140+
private EndpointServerWebExchangeMatcher(String[] endpoints,
141+
boolean includeLinks) {
142+
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(),
143+
includeLinks);
138144
}
139145

140146
private EndpointServerWebExchangeMatcher(List<Object> includes,
@@ -148,17 +154,20 @@ private EndpointServerWebExchangeMatcher(List<Object> includes,
148154
public EndpointServerWebExchangeMatcher excluding(Class<?>... endpoints) {
149155
List<Object> excludes = new ArrayList<>(this.excludes);
150156
excludes.addAll(Arrays.asList((Object[]) endpoints));
151-
return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks);
157+
return new EndpointServerWebExchangeMatcher(this.includes, excludes,
158+
this.includeLinks);
152159
}
153160

154161
public EndpointServerWebExchangeMatcher excluding(String... endpoints) {
155162
List<Object> excludes = new ArrayList<>(this.excludes);
156163
excludes.addAll(Arrays.asList((Object[]) endpoints));
157-
return new EndpointServerWebExchangeMatcher(this.includes, excludes, this.includeLinks);
164+
return new EndpointServerWebExchangeMatcher(this.includes, excludes,
165+
this.includeLinks);
158166
}
159167

160168
public EndpointServerWebExchangeMatcher excludingLinks() {
161-
return new EndpointServerWebExchangeMatcher(this.includes, this.excludes, false);
169+
return new EndpointServerWebExchangeMatcher(this.includes, this.excludes,
170+
false);
162171
}
163172

164173
@Override
@@ -185,8 +194,10 @@ private ServerWebExchangeMatcher createDelegate(
185194
streamPaths(this.includes, pathMappedEndpoints).forEach(paths::add);
186195
streamPaths(this.excludes, pathMappedEndpoints).forEach(paths::remove);
187196
List<ServerWebExchangeMatcher> delegateMatchers = getDelegateMatchers(paths);
188-
if (this.includeLinks && StringUtils.hasText(pathMappedEndpoints.getBasePath())) {
189-
delegateMatchers.add(new PathPatternParserServerWebExchangeMatcher(pathMappedEndpoints.getBasePath()));
197+
if (this.includeLinks
198+
&& StringUtils.hasText(pathMappedEndpoints.getBasePath())) {
199+
delegateMatchers.add(new PathPatternParserServerWebExchangeMatcher(
200+
pathMappedEndpoints.getBasePath()));
190201
}
191202
return new OrServerWebExchangeMatcher(delegateMatchers);
192203
}
@@ -241,15 +252,17 @@ private LinksServerWebExchangeMatcher() {
241252
}
242253

243254
@Override
244-
protected void initialized(Supplier<WebEndpointProperties> propertiesSupplier) {
245-
WebEndpointProperties webEndpointProperties = propertiesSupplier.get();
246-
if (StringUtils.hasText(webEndpointProperties.getBasePath())) {
247-
this.delegate = new PathPatternParserServerWebExchangeMatcher(
248-
webEndpointProperties.getBasePath());
249-
}
250-
else {
251-
this.delegate = EMPTY_MATCHER;
255+
protected void initialized(Supplier<WebEndpointProperties> properties) {
256+
this.delegate = createDelegate(properties.get());
257+
}
258+
259+
private ServerWebExchangeMatcher createDelegate(
260+
WebEndpointProperties properties) {
261+
if (StringUtils.hasText(properties.getBasePath())) {
262+
return new PathPatternParserServerWebExchangeMatcher(
263+
properties.getBasePath());
252264
}
265+
return EMPTY_MATCHER;
253266
}
254267

255268
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java

+33-22
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ private EndpointRequest() {
5757
}
5858

5959
/**
60-
* Returns a matcher that includes all {@link Endpoint actuator endpoints}. It also includes
61-
* the links endpoint which is present at the base path of the actuator endpoints. The
62-
* {@link EndpointRequestMatcher#excluding(Class...) excluding} method can be used to
63-
* further remove specific endpoints if required. For example: <pre class="code">
60+
* Returns a matcher that includes all {@link Endpoint actuator endpoints}. It also
61+
* includes the links endpoint which is present at the base path of the actuator
62+
* endpoints. The {@link EndpointRequestMatcher#excluding(Class...) excluding} method
63+
* can be used to further remove specific endpoints if required. For example:
64+
* <pre class="code">
6465
* EndpointRequest.toAnyEndpoint().excluding(ShutdownEndpoint.class)
6566
* </pre>
6667
* @return the configured {@link RequestMatcher}
@@ -94,11 +95,13 @@ public static EndpointRequestMatcher to(String... endpoints) {
9495
}
9596

9697
/**
97-
* Returns a matcher that matches only on the links endpoint. It can be used when security configuration
98-
* for the links endpoint is different from the other {@link Endpoint actuator endpoints}. The
99-
* {@link EndpointRequestMatcher#excludingLinks() excludingLinks} method can be used in combination with this
100-
* to remove the links endpoint from {@link EndpointRequest#toAnyEndpoint() toAnyEndpoint}.
101-
* For example: <pre class="code">
98+
* Returns a matcher that matches only on the links endpoint. It can be used when
99+
* security configuration for the links endpoint is different from the other
100+
* {@link Endpoint actuator endpoints}. The
101+
* {@link EndpointRequestMatcher#excludingLinks() excludingLinks} method can be used
102+
* in combination with this to remove the links endpoint from
103+
* {@link EndpointRequest#toAnyEndpoint() toAnyEndpoint}. For example:
104+
* <pre class="code">
102105
* EndpointRequest.toLinks()
103106
* </pre>
104107
* @return the configured {@link RequestMatcher}
@@ -126,14 +129,17 @@ private EndpointRequestMatcher(boolean includeLinks) {
126129
}
127130

128131
private EndpointRequestMatcher(Class<?>[] endpoints, boolean includeLinks) {
129-
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
132+
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(),
133+
includeLinks);
130134
}
131135

132136
private EndpointRequestMatcher(String[] endpoints, boolean includeLinks) {
133-
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
137+
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(),
138+
includeLinks);
134139
}
135140

136-
private EndpointRequestMatcher(List<Object> includes, List<Object> excludes, boolean includeLinks) {
141+
private EndpointRequestMatcher(List<Object> includes, List<Object> excludes,
142+
boolean includeLinks) {
137143
super(PathMappedEndpoints.class);
138144
this.includes = includes;
139145
this.excludes = excludes;
@@ -179,8 +185,10 @@ private RequestMatcher createDelegate(PathMappedEndpoints pathMappedEndpoints) {
179185
streamPaths(this.includes, pathMappedEndpoints).forEach(paths::add);
180186
streamPaths(this.excludes, pathMappedEndpoints).forEach(paths::remove);
181187
List<RequestMatcher> delegateMatchers = getDelegateMatchers(paths);
182-
if (this.includeLinks && StringUtils.hasText(pathMappedEndpoints.getBasePath())) {
183-
delegateMatchers.add(new AntPathRequestMatcher(pathMappedEndpoints.getBasePath()));
188+
if (this.includeLinks
189+
&& StringUtils.hasText(pathMappedEndpoints.getBasePath())) {
190+
delegateMatchers.add(
191+
new AntPathRequestMatcher(pathMappedEndpoints.getBasePath()));
184192
}
185193
return new OrRequestMatcher(delegateMatchers);
186194
}
@@ -234,20 +242,23 @@ private LinksRequestMatcher() {
234242
}
235243

236244
@Override
237-
protected void initialized(Supplier<WebEndpointProperties> propertiesSupplier) {
238-
WebEndpointProperties webEndpointProperties = propertiesSupplier.get();
239-
if (StringUtils.hasText(webEndpointProperties.getBasePath())) {
240-
this.delegate = new AntPathRequestMatcher(webEndpointProperties.getBasePath());
241-
}
242-
else {
243-
this.delegate = EMPTY_MATCHER;
245+
protected void initialized(Supplier<WebEndpointProperties> properties) {
246+
this.delegate = createDelegate(properties.get());
247+
}
248+
249+
private RequestMatcher createDelegate(WebEndpointProperties properties) {
250+
if (StringUtils.hasText(properties.getBasePath())) {
251+
return new AntPathRequestMatcher(properties.getBasePath());
244252
}
253+
return EMPTY_MATCHER;
245254
}
246255

247256
@Override
248-
protected boolean matches(HttpServletRequest request, Supplier<WebEndpointProperties> context) {
257+
protected boolean matches(HttpServletRequest request,
258+
Supplier<WebEndpointProperties> context) {
249259
return this.delegate.matches(request);
250260
}
261+
251262
}
252263

253264
}

0 commit comments

Comments
 (0)