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
4882544c
Commit
4882544c
authored
Aug 13, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-6540
parent
dced154f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
14 deletions
+23
-14
HealthMvcEndpoint.java
...ramework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java
+1
-5
HealthMvcEndpointTests.java
...ork/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java
+22
-9
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java
View file @
4882544c
...
...
@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.endpoint.mvc;
import
java.security.Principal
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -190,10 +189,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
if
(
isSpringSecurityAuthentication
(
principal
))
{
Authentication
authentication
=
(
Authentication
)
principal
;
List
<
String
>
roles
=
Arrays
.
asList
(
StringUtils
.
trimArrayElements
(
StringUtils
.
commaDelimitedListToStringArray
(
this
.
roleResolver
.
getProperty
(
"roles"
))));
if
(
roles
.
isEmpty
())
{
roles
=
Collections
.
singletonList
(
"ROLE_ADMIN"
);
}
.
commaDelimitedListToStringArray
(
this
.
roleResolver
.
getProperty
(
"roles"
,
"ROLE_ADMIN"
))));
for
(
GrantedAuthority
authority
:
authentication
.
getAuthorities
())
{
String
name
=
authority
.
getAuthority
();
for
(
String
role
:
roles
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java
View file @
4882544c
...
...
@@ -60,13 +60,17 @@ public class HealthMvcEndpointTests {
private
MockEnvironment
environment
;
private
UsernamePasswordAuthenticationToken
user
=
new
UsernamePasswordAuthenticationToken
(
"user"
,
"password"
,
AuthorityUtils
.
commaSeparatedStringToAuthorityList
(
"ROLE_USER"
));
private
UsernamePasswordAuthenticationToken
user
=
createAuthenticationToken
(
"ROLE_USER"
);
private
UsernamePasswordAuthenticationToken
admin
=
createAuthenticationToken
(
"ROLE_ADMIN"
);
private
UsernamePasswordAuthenticationToken
hero
=
createAuthenticationToken
(
"ROLE_HERO"
);
private
UsernamePasswordAuthenticationToken
admin
=
new
UsernamePasswordAuthenticationToken
(
private
UsernamePasswordAuthenticationToken
createAuthenticationToken
(
String
authority
)
{
return
new
UsernamePasswordAuthenticationToken
(
"user"
,
"password"
,
AuthorityUtils
.
commaSeparatedStringToAuthorityList
(
"ROLE_ADMIN"
));
AuthorityUtils
.
commaSeparatedStringToAuthorityList
(
authority
));
}
@Before
public
void
init
()
{
...
...
@@ -147,17 +151,26 @@ public class HealthMvcEndpointTests {
@Test
public
void
secureCustomRole
()
{
this
.
mvc
=
new
HealthMvcEndpoint
(
this
.
endpoint
,
false
);
this
.
mvc
.
setEnvironment
(
this
.
environment
);
this
.
environment
.
getPropertySources
().
addLast
(
SECURITY_ROLES
);
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
this
.
user
);
Object
result
=
this
.
mvc
.
invoke
(
this
.
hero
);
assertThat
(
result
instanceof
Health
).
isTrue
();
assertThat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
();
assertThat
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)).
isEqualTo
(
"bar"
);
}
@Test
public
void
secureCustomRoleNoAccess
()
{
this
.
environment
.
getPropertySources
().
addLast
(
SECURITY_ROLES
);
given
(
this
.
endpoint
.
invoke
())
.
willReturn
(
new
Health
.
Builder
().
up
().
withDetail
(
"foo"
,
"bar"
).
build
());
Object
result
=
this
.
mvc
.
invoke
(
this
.
admin
);
assertThat
(
result
instanceof
Health
).
isTrue
();
assertThat
(((
Health
)
result
).
getStatus
()
==
Status
.
UP
).
isTrue
();
assertThat
(((
Health
)
result
).
getDetails
().
get
(
"foo"
)).
isNull
();
}
@Test
public
void
healthIsCached
()
{
given
(
this
.
endpoint
.
getTimeToLive
()).
willReturn
(
10000L
);
...
...
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