Skip to content

Commit cc4ee65

Browse files
author
Dave Syer
committed
Add separate section in "features" docs on Security
Lists all the basic autoconfig defaults and quick pointers on how to change or disable. Fixes gh-514
1 parent 1158881 commit cc4ee65

File tree

3 files changed

+66
-22
lines changed

3 files changed

+66
-22
lines changed

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,23 +1102,6 @@ Look at {sc-spring-boot-actuator}/autoconfigure/ErrorMvcAutoConfiguration.{sc-ex
11021102
== Security
11031103

11041104

1105-
1106-
[[howto-secure-an-application]]
1107-
=== Secure an application
1108-
If Spring Security is on the classpath then web applications will be secure by default
1109-
(``basic'' authentication on all endpoints) . To add method-level security to a web
1110-
application you can simply `@EnableGlobalMethodSecurity` with your desired settings.
1111-
Additional information can be found in the {spring-security-reference}#jc-method[Spring
1112-
Security Reference].
1113-
1114-
The default `AuthenticationManager` has a single user (username ``user'' and password
1115-
random, printed at INFO level when the application starts up). You can change the
1116-
password by providing a `security.user.password`. This and other useful properties
1117-
are externalized via
1118-
{sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[`SecurityProperties`].
1119-
1120-
1121-
11221105
[[howto-switch-off-spring-boot-security-configuration]]
11231106
=== Switch off the Spring Boot security configuration
11241107
If you define a `@Configuration` with `@EnableWebSecurity` anywhere in your application
@@ -1157,7 +1140,9 @@ use this in a webapp is to inject it into a void method in a
11571140
}
11581141
----
11591142

1160-
1143+
You will get the best results if you put this in a nested class, or a standalone class (i.e.
1144+
not mixed in with a lot of other `@Beans` that might be allowed to influence the order of
1145+
instantiation). The https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-secure[secure web sample] is a useful template to follow.
11611146

11621147
[[howto-enable-https]]
11631148
=== Enable HTTPS

spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ all non-sensitive endpoints to be exposed over HTTP. The default convention is t
251251

252252
[[production-ready-sensitive-endpoints]]
253253
=== Exposing sensitive endpoints
254-
If you use ``Spring Security'' sensitive endpoints will also be exposed over HTTP. By
255-
default ``basic'' authentication will be used with the username `user` and a generated
256-
password.
254+
If you use ``Spring Security'' sensitive endpoints will be exposed over HTTP, but also
255+
protected. By default ``basic'' authentication will be used with the username `user`
256+
and a generated password (which is printed on the console when the application starts).
257257

258258
TIP: Generated passwords are logged as the application starts. Search for ``Using default
259259
password for application endpoints''.

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,66 @@ packaged as an executable archive), there are some limitations in the JSP suppor
993993
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so
994994
you can see how to set things up.
995995

996-
996+
[[boot-features-security]]
997+
== Security
998+
If Spring Security is on the classpath then web applications will be secure by default
999+
with ``basic'' authentication on all HTTP endpoints. To add method-level security to a web
1000+
application you can also add `@EnableGlobalMethodSecurity` with your desired settings.
1001+
Additional information can be found in the {spring-security-reference}#jc-method[Spring
1002+
Security Reference].
1003+
1004+
The default `AuthenticationManager` has a single user (username
1005+
``user'' and password random, printed at INFO level when the
1006+
application starts up). You can change the password by providing a
1007+
`security.user.password`. This and other useful properties are
1008+
externalized via
1009+
{sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[`SecurityProperties`]
1010+
(properties prefix "security").
1011+
1012+
The default security configuration is implemented in
1013+
`SecurityAutoConfiguration` and in the classes imported from there
1014+
(`SpringBootWebSecurityConfiguration` for web security and
1015+
`AuthenticationManagerConfiguration` for authentication configuration
1016+
which is also relevant in non-web applications). To switch off the
1017+
Boot default configuration completely in a web application you can add
1018+
a bean with `@EnableWebSecurity`. To customize it you normally use
1019+
external properties and beans of type `WebConfigurerAdapter` (e.g. to
1020+
add form-based login). There are several secure applications in the
1021+
{github-code}/spring-boot-samples/[Spring Boot samples] to get you
1022+
started with common use cases.
1023+
1024+
The basic features you get out of the box in a web application are
1025+
1026+
* An `AuthenticationManager` bean with in-memory store and a single
1027+
user (see `SecurityProperties.User` for the properties of the user).
1028+
1029+
* Ignored (unsecure) paths for common static resource locations
1030+
(`/css/**`, `/js/**`, `/images/**` and `**/favicon.ico`).
1031+
1032+
* HTTP Basic security for all other endpoints.
1033+
1034+
* Security events published to Spring's `ApplicationEventPublisher`
1035+
(successful and unsuccessful authentication and access denied).
1036+
1037+
* Common low-level features (HSTS, XSS, CSRF, caching) provided by Spring
1038+
Security are on by default.
1039+
1040+
All of the above can be switched on and off or modified using external
1041+
properties (`security.*`).
1042+
1043+
If the Actuator is also in use, you will find:
1044+
1045+
* The management endpoints are secure even if the application
1046+
endpoints are unsecure.
1047+
1048+
* Security events are transformed into `AuditEvents` and published to
1049+
the `AuditService`.
1050+
1051+
* The default user will have the "ADMIN" role as well as the "USER"
1052+
role.
1053+
1054+
The Actuator security features can be modified using external
1055+
properties (`management.security.*`).
9971056

9981057
[[boot-features-sql]]
9991058
== Working with SQL databases

0 commit comments

Comments
 (0)