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
387faa78
Commit
387faa78
authored
Nov 10, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4383 from rwinch/gh-4368
* pr/4383: Secure actuator when all endpoints are sensitive
parents
8c642bec
c6e08eb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
ManagementWebSecurityAutoConfiguration.java
...autoconfigure/ManagementWebSecurityAutoConfiguration.java
+7
-2
ManagementWebSecurityAutoConfigurationTests.java
...onfigure/ManagementWebSecurityAutoConfigurationTests.java
+24
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfiguration.java
View file @
387faa78
...
@@ -67,6 +67,7 @@ import org.springframework.security.web.AuthenticationEntryPoint;
...
@@ -67,6 +67,7 @@ import org.springframework.security.web.AuthenticationEntryPoint;
import
org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint
;
import
org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint
;
import
org.springframework.security.web.util.matcher.AntPathRequestMatcher
;
import
org.springframework.security.web.util.matcher.AntPathRequestMatcher
;
import
org.springframework.security.web.util.matcher.AnyRequestMatcher
;
import
org.springframework.security.web.util.matcher.AnyRequestMatcher
;
import
org.springframework.security.web.util.matcher.NegatedRequestMatcher
;
import
org.springframework.security.web.util.matcher.OrRequestMatcher
;
import
org.springframework.security.web.util.matcher.OrRequestMatcher
;
import
org.springframework.security.web.util.matcher.RequestMatcher
;
import
org.springframework.security.web.util.matcher.RequestMatcher
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
...
@@ -95,6 +96,9 @@ public class ManagementWebSecurityAutoConfiguration {
...
@@ -95,6 +96,9 @@ public class ManagementWebSecurityAutoConfiguration {
private
static
final
String
[]
NO_PATHS
=
new
String
[
0
];
private
static
final
String
[]
NO_PATHS
=
new
String
[
0
];
private
static
final
RequestMatcher
MATCH_NONE
=
new
NegatedRequestMatcher
(
AnyRequestMatcher
.
INSTANCE
);
@Bean
@Bean
@ConditionalOnMissingBean
({
IgnoredPathsWebSecurityConfigurerAdapter
.
class
})
@ConditionalOnMissingBean
({
IgnoredPathsWebSecurityConfigurerAdapter
.
class
})
public
IgnoredPathsWebSecurityConfigurerAdapter
ignoredPathsWebSecurityConfigurerAdapter
()
{
public
IgnoredPathsWebSecurityConfigurerAdapter
ignoredPathsWebSecurityConfigurerAdapter
()
{
...
@@ -332,8 +336,7 @@ public class ManagementWebSecurityAutoConfiguration {
...
@@ -332,8 +336,7 @@ public class ManagementWebSecurityAutoConfiguration {
for
(
String
path
:
this
.
endpointPaths
.
getPaths
(
endpointHandlerMapping
))
{
for
(
String
path
:
this
.
endpointPaths
.
getPaths
(
endpointHandlerMapping
))
{
matchers
.
add
(
new
AntPathRequestMatcher
(
server
.
getPath
(
path
)));
matchers
.
add
(
new
AntPathRequestMatcher
(
server
.
getPath
(
path
)));
}
}
return
(
matchers
.
isEmpty
()
?
AnyRequestMatcher
.
INSTANCE
return
(
matchers
.
isEmpty
()
?
MATCH_NONE
:
new
OrRequestMatcher
(
matchers
));
:
new
OrRequestMatcher
(
matchers
));
}
}
}
}
...
@@ -345,10 +348,12 @@ public class ManagementWebSecurityAutoConfiguration {
...
@@ -345,10 +348,12 @@ public class ManagementWebSecurityAutoConfiguration {
ALL
,
ALL
,
NON_SENSITIVE
{
NON_SENSITIVE
{
@Override
@Override
protected
boolean
isIncluded
(
MvcEndpoint
endpoint
)
{
protected
boolean
isIncluded
(
MvcEndpoint
endpoint
)
{
return
!
endpoint
.
isSensitive
();
return
!
endpoint
.
isSensitive
();
}
}
};
};
public
String
[]
getPaths
(
EndpointHandlerMapping
endpointHandlerMapping
)
{
public
String
[]
getPaths
(
EndpointHandlerMapping
endpointHandlerMapping
)
{
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfigurationTests.java
View file @
387faa78
...
@@ -61,6 +61,9 @@ import static org.junit.Assert.assertEquals;
...
@@ -61,6 +61,9 @@ import static org.junit.Assert.assertEquals;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
security
.
test
.
web
.
servlet
.
setup
.
SecurityMockMvcConfigurers
.
springSecurity
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/**
/**
* Tests for {@link ManagementWebSecurityAutoConfiguration}.
* Tests for {@link ManagementWebSecurityAutoConfiguration}.
...
@@ -231,6 +234,27 @@ public class ManagementWebSecurityAutoConfigurationTests {
...
@@ -231,6 +234,27 @@ public class ManagementWebSecurityAutoConfigurationTests {
.
andExpect
(
springAuthenticateRealmHeader
());
.
andExpect
(
springAuthenticateRealmHeader
());
}
}
@Test
public
void
testMarkAllEndpointsSensitive
()
throws
Exception
{
// gh-4368
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
setServletContext
(
new
MockServletContext
());
this
.
context
.
register
(
WebConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"endpoints.sensitive:true"
);
this
.
context
.
refresh
();
MockMvc
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
context
)
//
.
apply
(
springSecurity
())
//
.
build
();
mockMvc
//
.
perform
(
get
(
"/health"
))
//
.
andExpect
(
status
().
isUnauthorized
());
mockMvc
//
.
perform
(
get
(
"/info"
))
//
.
andExpect
(
status
().
isUnauthorized
());
}
private
ResultMatcher
springAuthenticateRealmHeader
()
{
private
ResultMatcher
springAuthenticateRealmHeader
()
{
return
MockMvcResultMatchers
.
header
().
string
(
"www-authenticate"
,
return
MockMvcResultMatchers
.
header
().
string
(
"www-authenticate"
,
Matchers
.
containsString
(
"realm=\"Spring\""
));
Matchers
.
containsString
(
"realm=\"Spring\""
));
...
...
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