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
b58923a4
Commit
b58923a4
authored
Jul 17, 2017
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
03344209
0f8a819a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
1 deletion
+96
-1
ManagementWebSecurityAutoConfiguration.java
...autoconfigure/ManagementWebSecurityAutoConfiguration.java
+1
-1
pom.xml
spring-boot-samples/spring-boot-sample-actuator/pom.xml
+5
-0
CorsSampleActuatorApplicationTests.java
...a/sample/actuator/CorsSampleActuatorApplicationTests.java
+88
-0
application-cors.properties
...e-actuator/src/test/resources/application-cors.properties
+2
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfiguration.java
View file @
b58923a4
...
...
@@ -224,7 +224,7 @@ public class ManagementWebSecurityAutoConfiguration {
http
.
requestMatcher
(
matcher
);
// ... but permitAll() for the non-sensitive ones
configurePermittedRequests
(
http
.
authorizeRequests
());
http
.
httpBasic
().
authenticationEntryPoint
(
entryPoint
);
http
.
httpBasic
().
authenticationEntryPoint
(
entryPoint
)
.
and
().
cors
()
;
// No cookies for management endpoints by default
http
.
csrf
().
disable
();
http
.
sessionManagement
()
...
...
spring-boot-samples/spring-boot-sample-actuator/pom.xml
View file @
b58923a4
...
...
@@ -37,6 +37,11 @@
<artifactId>
spring-boot-starter-jdbc
</artifactId>
</dependency>
<!-- Runtime -->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
...
...
spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/CorsSampleActuatorApplicationTests.java
0 → 100644
View file @
b58923a4
package
sample
.
actuator
;
import
java.net.URI
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.LocalHostUriTemplateHandler
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.RequestEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration test for cors preflight requests to management endpoints.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
@DirtiesContext
@ActiveProfiles
(
"cors"
)
public
class
CorsSampleActuatorApplicationTests
{
private
TestRestTemplate
testRestTemplate
;
@Autowired
ApplicationContext
applicationContext
;
@Before
public
void
setUp
()
throws
Exception
{
RestTemplate
restTemplate
=
new
RestTemplate
();
LocalHostUriTemplateHandler
handler
=
new
LocalHostUriTemplateHandler
(
this
.
applicationContext
.
getEnvironment
(),
"http"
);
restTemplate
.
setUriTemplateHandler
(
handler
);
restTemplate
.
setRequestFactory
(
new
HttpComponentsClientHttpRequestFactory
());
this
.
testRestTemplate
=
new
TestRestTemplate
(
restTemplate
);
}
@Test
public
void
sensitiveEndpointShouldReturnUnauthorized
()
throws
Exception
{
ResponseEntity
<
Map
>
entity
=
this
.
testRestTemplate
.
getForEntity
(
"/env"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
@Test
public
void
preflightRequestForInsensitiveShouldReturnOk
()
throws
Exception
{
RequestEntity
<?>
healthRequest
=
RequestEntity
.
options
(
new
URI
(
"/health"
))
.
header
(
"Origin"
,
"http://localhost:8080"
)
.
header
(
"Access-Control-Request-Method"
,
"GET"
)
.
build
();
ResponseEntity
<
Map
>
exchange
=
this
.
testRestTemplate
.
exchange
(
healthRequest
,
Map
.
class
);
assertThat
(
exchange
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
@Test
public
void
preflightRequestForSensitiveEndpointShouldReturnOk
()
throws
Exception
{
RequestEntity
<?>
entity
=
RequestEntity
.
options
(
new
URI
(
"/env"
))
.
header
(
"Origin"
,
"http://localhost:8080"
)
.
header
(
"Access-Control-Request-Method"
,
"GET"
)
.
build
();
ResponseEntity
<
Map
>
env
=
this
.
testRestTemplate
.
exchange
(
entity
,
Map
.
class
);
assertThat
(
env
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
@Test
public
void
preflightRequestWhenCorsConfigInvalidShouldReturnForbidden
()
throws
Exception
{
RequestEntity
<?>
entity
=
RequestEntity
.
options
(
new
URI
(
"/health"
))
.
header
(
"Origin"
,
"http://localhost:9095"
)
.
header
(
"Access-Control-Request-Method"
,
"GET"
)
.
build
();
ResponseEntity
<
byte
[]>
exchange
=
this
.
testRestTemplate
.
exchange
(
entity
,
byte
[].
class
);
assertThat
(
exchange
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
FORBIDDEN
);
}
}
spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-cors.properties
0 → 100644
View file @
b58923a4
endpoints.cors.allowed-origins
=
http://localhost:8080
endpoints.cors.allowed-methods
=
GET
\ No newline at end of file
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