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
218d28f7
Commit
218d28f7
authored
Nov 08, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.4.x' into 1.5.x
parents
3a2d9e31
33dcd853
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
4 deletions
+109
-4
EndpointWebMvcManagementContextConfiguration.java
...nfigure/EndpointWebMvcManagementContextConfiguration.java
+14
-4
NoSpringSecurityHealthMvcEndpointIntegrationTests.java
...vc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java
+95
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java
View file @
218d28f7
...
@@ -20,7 +20,6 @@ import java.util.List;
...
@@ -20,7 +20,6 @@ import java.util.List;
import
java.util.Set
;
import
java.util.Set
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.autoconfigure.ManagementServerProperties.Security
;
import
org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint
;
import
org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.endpoint.EnvironmentEndpoint
;
import
org.springframework.boot.actuate.endpoint.EnvironmentEndpoint
;
...
@@ -51,6 +50,7 @@ import org.springframework.context.annotation.ConditionContext;
...
@@ -51,6 +50,7 @@ import org.springframework.context.annotation.ConditionContext;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.CorsConfiguration
;
...
@@ -143,9 +143,8 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -143,9 +143,8 @@ public class EndpointWebMvcManagementContextConfiguration {
@ConditionalOnBean
(
HealthEndpoint
.
class
)
@ConditionalOnBean
(
HealthEndpoint
.
class
)
@ConditionalOnEnabledEndpoint
(
"health"
)
@ConditionalOnEnabledEndpoint
(
"health"
)
public
HealthMvcEndpoint
healthMvcEndpoint
(
HealthEndpoint
delegate
)
{
public
HealthMvcEndpoint
healthMvcEndpoint
(
HealthEndpoint
delegate
)
{
Security
security
=
this
.
managementServerProperties
.
getSecurity
();
HealthMvcEndpoint
healthMvcEndpoint
=
new
HealthMvcEndpoint
(
delegate
,
boolean
secure
=
(
security
!=
null
&&
security
.
isEnabled
());
isHealthSecure
());
HealthMvcEndpoint
healthMvcEndpoint
=
new
HealthMvcEndpoint
(
delegate
,
secure
);
if
(
this
.
healthMvcEndpointProperties
.
getMapping
()
!=
null
)
{
if
(
this
.
healthMvcEndpointProperties
.
getMapping
()
!=
null
)
{
healthMvcEndpoint
healthMvcEndpoint
.
addStatusMapping
(
this
.
healthMvcEndpointProperties
.
getMapping
());
.
addStatusMapping
(
this
.
healthMvcEndpointProperties
.
getMapping
());
...
@@ -181,6 +180,17 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -181,6 +180,17 @@ public class EndpointWebMvcManagementContextConfiguration {
return
new
ShutdownMvcEndpoint
(
delegate
);
return
new
ShutdownMvcEndpoint
(
delegate
);
}
}
private
boolean
isHealthSecure
()
{
return
isSpringSecurityAvailable
()
&&
this
.
managementServerProperties
.
getSecurity
().
isEnabled
();
}
private
boolean
isSpringSecurityAvailable
()
{
return
ClassUtils
.
isPresent
(
"org.springframework.security.config.annotation.web.WebSecurityConfigurer"
,
getClass
().
getClassLoader
());
}
private
static
class
LogFileCondition
extends
SpringBootCondition
{
private
static
class
LogFileCondition
extends
SpringBootCondition
{
@Override
@Override
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java
0 → 100644
View file @
218d28f7
/*
* Copyright 2012-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
actuate
.
endpoint
.
mvc
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
;
import
org.springframework.boot.testutil.ClassPathExclusions
;
import
org.springframework.boot.testutil.FilteredClassPathRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
setup
.
MockMvcBuilders
.
webAppContextSetup
;
/**
* Integration tests for the health endpoint when Spring Security is not available.
*
* @author Andy Wilkinson
*/
@RunWith
(
FilteredClassPathRunner
.
class
)
@ClassPathExclusions
(
"spring-security-*.jar"
)
public
class
NoSpringSecurityHealthMvcEndpointIntegrationTests
{
private
AnnotationConfigWebApplicationContext
context
;
@After
public
void
closeContext
()
{
this
.
context
.
close
();
}
@Test
public
void
healthDetailIsPresent
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
setServletContext
(
new
MockServletContext
());
this
.
context
.
register
(
TestConfiguration
.
class
);
this
.
context
.
refresh
();
MockMvc
mockMvc
=
webAppContextSetup
(
this
.
context
).
build
();
mockMvc
.
perform
(
get
(
"/health"
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
containsString
(
"\"hello\":\"world\""
)));
}
@ImportAutoConfiguration
({
JacksonAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
EndpointWebMvcAutoConfiguration
.
class
,
ManagementServerPropertiesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
WebMvcAutoConfiguration
.
class
})
@Configuration
static
class
TestConfiguration
{
@Bean
public
HealthIndicator
testHealthIndicator
()
{
return
new
HealthIndicator
()
{
@Override
public
Health
health
()
{
return
Health
.
up
().
withDetail
(
"hello"
,
"world"
).
build
();
}
};
}
}
}
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