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
2ba01008
Commit
2ba01008
authored
Sep 04, 2013
by
Dave Syer
Committed by
Phillip Webb
Sep 06, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add headers external properties for security filters
parent
759aa785
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
2 deletions
+110
-2
SecurityAutoConfiguration.java
...boot/actuate/autoconfigure/SecurityAutoConfiguration.java
+35
-2
SecurityProperties.java
...framework/boot/actuate/properties/SecurityProperties.java
+75
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/SecurityAutoConfiguration.java
View file @
2ba01008
...
...
@@ -29,6 +29,7 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
import
org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping
;
import
org.springframework.boot.actuate.properties.ManagementServerProperties
;
import
org.springframework.boot.actuate.properties.SecurityProperties
;
import
org.springframework.boot.actuate.properties.SecurityProperties.Headers
;
import
org.springframework.boot.actuate.properties.SecurityProperties.User
;
import
org.springframework.boot.actuate.web.ErrorController
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
...
...
@@ -52,8 +53,11 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity;
import
org.springframework.security.config.annotation.web.builders.WebSecurity.IgnoredRequestConfigurer
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.configurers.HeadersConfigurer
;
import
org.springframework.security.web.AuthenticationEntryPoint
;
import
org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint
;
import
org.springframework.security.web.header.writers.HstsHeaderWriter
;
import
org.springframework.security.web.util.AnyRequestMatcher
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for security of a web application or
...
...
@@ -149,11 +153,15 @@ public class SecurityAutoConfiguration {
.
and
().
httpBasic
()
//
.
and
().
anonymous
().
disable
();
}
// Remove this when session creation is disabled by default
http
.
csrf
().
disable
();
if
(!
this
.
security
.
isEnableCsrf
())
{
http
.
csrf
().
disable
();
}
// No cookies for application endpoints by default
http
.
sessionManagement
().
sessionCreationPolicy
(
this
.
security
.
getSessions
());
SecurityAutoConfiguration
.
configureHeaders
(
http
.
headers
(),
this
.
security
.
getHeaders
());
}
private
String
[]
getSecureApplicationPaths
()
{
...
...
@@ -234,6 +242,9 @@ public class SecurityAutoConfiguration {
http
.
sessionManagement
().
sessionCreationPolicy
(
this
.
security
.
getManagement
().
getSessions
());
SecurityAutoConfiguration
.
configureHeaders
(
http
.
headers
(),
this
.
security
.
getHeaders
());
}
@Override
...
...
@@ -299,4 +310,26 @@ public class SecurityAutoConfiguration {
}
private
static
void
configureHeaders
(
HeadersConfigurer
<?>
configurer
,
SecurityProperties
.
Headers
headers
)
throws
Exception
{
if
(
headers
.
getHsts
()
!=
Headers
.
HSTS
.
none
)
{
boolean
includeSubdomains
=
headers
.
getHsts
()
==
Headers
.
HSTS
.
all
;
HstsHeaderWriter
writer
=
new
HstsHeaderWriter
(
includeSubdomains
);
writer
.
setRequestMatcher
(
new
AnyRequestMatcher
());
configurer
.
addHeaderWriter
(
writer
);
}
if
(
headers
.
isContentType
())
{
configurer
.
contentTypeOptions
();
}
if
(
headers
.
isXss
())
{
configurer
.
xssProtection
();
}
if
(
headers
.
isCache
())
{
configurer
.
cacheControl
();
}
if
(
headers
.
isFrame
())
{
configurer
.
frameOptions
();
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/SecurityProperties.java
View file @
2ba01008
...
...
@@ -32,8 +32,13 @@ public class SecurityProperties {
private
boolean
requireSsl
;
// Flip this when session creation is disabled by default
private
boolean
enableCsrf
=
false
;
private
Basic
basic
=
new
Basic
();
private
Headers
headers
=
new
Headers
();
private
SessionCreationPolicy
sessions
=
SessionCreationPolicy
.
STATELESS
;
private
String
[]
ignored
=
new
String
[]
{
"/css/**"
,
"/js/**"
,
"/images/**"
,
...
...
@@ -43,6 +48,10 @@ public class SecurityProperties {
private
User
user
=
new
User
();
public
Headers
getHeaders
()
{
return
this
.
headers
;
}
public
User
getUser
()
{
return
this
.
user
;
}
...
...
@@ -75,6 +84,14 @@ public class SecurityProperties {
this
.
requireSsl
=
requireSsl
;
}
public
boolean
isEnableCsrf
()
{
return
this
.
enableCsrf
;
}
public
void
setEnableCsrf
(
boolean
enableCsrf
)
{
this
.
enableCsrf
=
enableCsrf
;
}
public
void
setIgnored
(
String
...
ignored
)
{
this
.
ignored
=
ignored
;
}
...
...
@@ -83,6 +100,64 @@ public class SecurityProperties {
return
this
.
ignored
;
}
public
static
class
Headers
{
public
static
enum
HSTS
{
none
,
domain
,
all
}
private
boolean
xss
;
private
boolean
cache
;
private
boolean
frame
;
private
boolean
contentType
;
private
HSTS
hsts
=
HSTS
.
all
;
public
boolean
isXss
()
{
return
this
.
xss
;
}
public
void
setXss
(
boolean
xss
)
{
this
.
xss
=
xss
;
}
public
boolean
isCache
()
{
return
this
.
cache
;
}
public
void
setCache
(
boolean
cache
)
{
this
.
cache
=
cache
;
}
public
boolean
isFrame
()
{
return
this
.
frame
;
}
public
void
setFrame
(
boolean
frame
)
{
this
.
frame
=
frame
;
}
public
boolean
isContentType
()
{
return
this
.
contentType
;
}
public
void
setContentType
(
boolean
contentType
)
{
this
.
contentType
=
contentType
;
}
public
HSTS
getHsts
()
{
return
this
.
hsts
;
}
public
void
setHsts
(
HSTS
hsts
)
{
this
.
hsts
=
hsts
;
}
}
public
static
class
Basic
{
private
boolean
enabled
=
true
;
...
...
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