Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
5757c086
Commit
5757c086
authored
Apr 19, 2020
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x' into 2.2.x
Closes gh-21022
parents
90c0378a
6a4d98a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
36 deletions
+68
-36
ExposeExcludePropertyEndpointFilter.java
...nfigure/endpoint/ExposeExcludePropertyEndpointFilter.java
+61
-35
ExposeExcludePropertyEndpointFilterTests.java
...re/endpoint/ExposeExcludePropertyEndpointFilterTests.java
+7
-1
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ExposeExcludePropertyEndpointFilter.java
View file @
5757c086
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -20,10 +20,9 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.boot.actuate.endpoint.EndpointFilter
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
...
...
@@ -35,7 +34,7 @@ import org.springframework.util.Assert;
/**
* {@link EndpointFilter} that will filter endpoints based on {@code include} and
* {@code exclude} p
ropertie
s.
* {@code exclude} p
attern
s.
*
* @param <E> the endpoint type
* @author Phillip Webb
...
...
@@ -45,11 +44,11 @@ public class ExposeExcludePropertyEndpointFilter<E extends ExposableEndpoint<?>>
private
final
Class
<
E
>
endpointType
;
private
final
Set
<
String
>
include
;
private
final
EndpointPatterns
include
;
private
final
Set
<
String
>
exclude
;
private
final
EndpointPatterns
exclude
;
private
final
Set
<
String
>
exposeDefaults
;
private
final
EndpointPatterns
exposeDefaults
;
public
ExposeExcludePropertyEndpointFilter
(
Class
<
E
>
endpointType
,
Environment
environment
,
String
prefix
,
String
...
exposeDefaults
)
{
...
...
@@ -58,37 +57,22 @@ public class ExposeExcludePropertyEndpointFilter<E extends ExposableEndpoint<?>>
Assert
.
hasText
(
prefix
,
"Prefix must not be empty"
);
Binder
binder
=
Binder
.
get
(
environment
);
this
.
endpointType
=
endpointType
;
this
.
include
=
bind
(
binder
,
prefix
+
".include"
);
this
.
exclude
=
bind
(
binder
,
prefix
+
".exclude"
);
this
.
exposeDefaults
=
asSet
(
Arrays
.
asList
(
exposeDefaults
)
);
this
.
include
=
new
EndpointPatterns
(
bind
(
binder
,
prefix
+
".include"
)
);
this
.
exclude
=
new
EndpointPatterns
(
bind
(
binder
,
prefix
+
".exclude"
)
);
this
.
exposeDefaults
=
new
EndpointPatterns
(
exposeDefaults
);
}
public
ExposeExcludePropertyEndpointFilter
(
Class
<
E
>
endpointType
,
Collection
<
String
>
include
,
Collection
<
String
>
exclude
,
String
...
exposeDefaults
)
{
Assert
.
notNull
(
endpointType
,
"EndpointType Type must not be null"
);
this
.
endpointType
=
endpointType
;
this
.
include
=
asSet
(
include
);
this
.
exclude
=
asSet
(
exclude
);
this
.
exposeDefaults
=
asSet
(
Arrays
.
asList
(
exposeDefaults
)
);
this
.
include
=
new
EndpointPatterns
(
include
);
this
.
exclude
=
new
EndpointPatterns
(
exclude
);
this
.
exposeDefaults
=
new
EndpointPatterns
(
exposeDefaults
);
}
private
Set
<
String
>
bind
(
Binder
binder
,
String
name
)
{
return
asSet
(
binder
.
bind
(
name
,
Bindable
.
listOf
(
String
.
class
)).
map
(
this
::
cleanup
).
orElseGet
(
ArrayList:
:
new
));
}
private
List
<
String
>
cleanup
(
List
<
String
>
values
)
{
return
values
.
stream
().
map
(
this
::
cleanup
).
collect
(
Collectors
.
toList
());
}
private
String
cleanup
(
String
value
)
{
return
"*"
.
equals
(
value
)
?
"*"
:
EndpointId
.
fromPropertyValue
(
value
).
toLowerCaseString
();
}
private
Set
<
String
>
asSet
(
Collection
<
String
>
items
)
{
if
(
items
==
null
)
{
return
Collections
.
emptySet
();
}
return
items
.
stream
().
map
((
item
)
->
item
.
toLowerCase
(
Locale
.
ENGLISH
)).
collect
(
Collectors
.
toSet
());
private
List
<
String
>
bind
(
Binder
binder
,
String
name
)
{
return
binder
.
bind
(
name
,
Bindable
.
listOf
(
String
.
class
)).
orElseGet
(
ArrayList:
:
new
);
}
@Override
...
...
@@ -101,20 +85,62 @@ public class ExposeExcludePropertyEndpointFilter<E extends ExposableEndpoint<?>>
private
boolean
isExposed
(
ExposableEndpoint
<?>
endpoint
)
{
if
(
this
.
include
.
isEmpty
())
{
return
this
.
exposeDefaults
.
contains
(
"*"
)
||
contains
(
this
.
exposeDefaults
,
endpoint
);
return
this
.
exposeDefaults
.
matchesAll
()
||
this
.
exposeDefaults
.
matches
(
endpoint
);
}
return
this
.
include
.
contains
(
"*"
)
||
contains
(
this
.
include
,
endpoint
);
return
this
.
include
.
matchesAll
()
||
this
.
include
.
matches
(
endpoint
);
}
private
boolean
isExcluded
(
ExposableEndpoint
<?>
endpoint
)
{
if
(
this
.
exclude
.
isEmpty
())
{
return
false
;
}
return
this
.
exclude
.
contains
(
"*"
)
||
contains
(
this
.
exclude
,
endpoint
);
return
this
.
exclude
.
matchesAll
()
||
this
.
exclude
.
matches
(
endpoint
);
}
private
boolean
contains
(
Set
<
String
>
items
,
ExposableEndpoint
<?>
endpoint
)
{
return
items
.
contains
(
endpoint
.
getEndpointId
().
toLowerCaseString
());
/**
* A set of endpoint patterns used to match IDs.
*/
private
static
class
EndpointPatterns
{
private
final
boolean
empty
;
private
final
boolean
matchesAll
;
private
final
Set
<
EndpointId
>
endpointIds
;
EndpointPatterns
(
String
[]
patterns
)
{
this
((
patterns
!=
null
)
?
Arrays
.
asList
(
patterns
)
:
(
Collection
<
String
>)
null
);
}
EndpointPatterns
(
Collection
<
String
>
patterns
)
{
patterns
=
(
patterns
!=
null
)
?
patterns
:
Collections
.
emptySet
();
boolean
matchesAll
=
false
;
Set
<
EndpointId
>
endpointIds
=
new
LinkedHashSet
<>();
for
(
String
pattern
:
patterns
)
{
if
(
"*"
.
equals
(
pattern
))
{
matchesAll
=
true
;
}
else
{
endpointIds
.
add
(
EndpointId
.
fromPropertyValue
(
pattern
));
}
}
this
.
empty
=
patterns
.
isEmpty
();
this
.
matchesAll
=
matchesAll
;
this
.
endpointIds
=
endpointIds
;
}
boolean
isEmpty
()
{
return
this
.
empty
;
}
boolean
matchesAll
()
{
return
this
.
matchesAll
;
}
boolean
matches
(
ExposableEndpoint
<?>
endpoint
)
{
return
this
.
endpointIds
.
contains
(
endpoint
.
getEndpointId
());
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/ExposeExcludePropertyEndpointFilterTests.java
View file @
5757c086
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -147,6 +147,12 @@ class ExposeExcludePropertyEndpointFilterTests {
assertThat
(
match
(
EndpointId
.
of
(
"fooBar"
))).
isTrue
();
}
@Test
// gh-20997
public
void
matchWhenDashInName
()
throws
Exception
{
setupFilter
(
"bus-refresh"
,
""
);
assertThat
(
match
(
EndpointId
.
of
(
"bus-refresh"
))).
isTrue
();
}
private
void
setupFilter
(
String
include
,
String
exclude
)
{
MockEnvironment
environment
=
new
MockEnvironment
();
environment
.
setProperty
(
"foo.include"
,
include
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment