|
| 1 | +[[servlet-hello]] |
1 | 2 | = Hello Spring Security
|
2 | 3 |
|
3 |
| -This section covers a minimal Spring Security application that uses <<servlet-hello-boot,Spring Boot>>, <<servlet-hello-jc,Java Configuration>>, or <<servlet-hello-xml,XML Configuration>>. |
4 |
| -// FIXME add Spring Boot |
| 4 | +This section covers the minimum setup for how to use Spring Security with Spring Boot. |
| 5 | + |
| 6 | +[NOTE] |
| 7 | +==== |
| 8 | +The completed application can be found at {gh-samples-url}/boot/helloworld[samples/boot/helloworld] |
| 9 | +For your convenience, you can download a minimal Spring Boot + Spring Security application by https://start.spring.io/starter.zip?type=maven-project&language=java&packaging=jar&jvmVersion=1.8&groupId=example&artifactId=hello-security&name=hello-security&description=Hello%20Security&packageName=example.hello-security&dependencies=web,security[clicking here]. |
| 10 | +==== |
| 11 | + |
| 12 | +[[servlet-hello-dependencies]] |
| 13 | +== Updating Dependencies |
| 14 | + |
| 15 | +The only step you need to do is update the dependencies by using <<getting-maven-boot,Maven>> or <<getting-gradle-boot,Gradle>>. |
| 16 | + |
| 17 | +[[servlet-hello-starting]] |
| 18 | +== Starting Hello Spring Security Boot |
| 19 | + |
| 20 | +You can now https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-running-with-the-maven-plugin[run the Spring Boot application] by using the Maven Plugin's `run` goal. |
| 21 | +The following example shows how to do so (and the beginning of the output from doing so): |
| 22 | + |
| 23 | +.Running Spring Boot Application |
| 24 | +==== |
| 25 | +[source,bash] |
| 26 | +---- |
| 27 | +$ ./mvn spring-boot:run |
| 28 | +... |
| 29 | +INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration : |
| 30 | +
|
| 31 | +Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336 |
| 32 | +
|
| 33 | +... |
| 34 | +---- |
| 35 | +==== |
| 36 | + |
| 37 | + |
| 38 | +[[servlet-hello-auto-configuration]] |
| 39 | +== Spring Boot Auto Configuration |
| 40 | + |
| 41 | +// FIXME: Link to relevant portions of documentation |
| 42 | +// FIXME: Link to Spring Boot's Security Auto configuration classes |
| 43 | +// FIXME: Add a links for what user's should do next |
| 44 | + |
| 45 | +Spring Boot automatically: |
| 46 | + |
| 47 | +* Enables Spring Security's default configuration, which creates a servlet `Filter` as a bean named `springSecurityFilterChain`. |
| 48 | +This bean is responsible for all the security (protecting the application URLs, validating submitted username and passwords, redirecting to the log in form, and so on) within your application. |
| 49 | +* Creates a `UserDetailsService` bean with a username of `user` and a randomly generated password that is logged to the console. |
| 50 | +* Registers the `Filter` with a bean named `springSecurityFilterChain` with the Servlet container for every request. |
| 51 | + |
| 52 | +Spring Boot is not configuring much, but it does a lot. |
| 53 | +A summary of the features follows: |
| 54 | + |
| 55 | +* Require an authenticated user for any interaction with the application |
| 56 | +* Generate a default login form for you |
| 57 | +* Let the user with a username of `user` and a password that is logged to the console to authenticate with form-based authentication (in the preceding example, the password is `8e557245-73e2-4286-969a-ff57fe326336`) |
| 58 | +* Protects the password storage with BCrypt |
| 59 | +* Lets the user log out |
| 60 | +* https://en.wikipedia.org/wiki/Cross-site_request_forgery[CSRF attack] prevention |
| 61 | +* https://en.wikipedia.org/wiki/Session_fixation[Session Fixation] protection |
| 62 | +* Security Header integration |
| 63 | +** https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security[HTTP Strict Transport Security] for secure requests |
| 64 | +** https://msdn.microsoft.com/en-us/library/ie/gg622941(v=vs.85).aspx[X-Content-Type-Options] integration |
| 65 | +** Cache Control (can be overridden later by your application to allow caching of your static resources) |
| 66 | +** https://msdn.microsoft.com/en-us/library/dd565647(v=vs.85).aspx[X-XSS-Protection] integration |
| 67 | +** X-Frame-Options integration to help prevent https://en.wikipedia.org/wiki/Clickjacking[Clickjacking] |
| 68 | +* Integrate with the following Servlet API methods: |
| 69 | +** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getRemoteUser()[`HttpServletRequest#getRemoteUser()`] |
| 70 | +** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getUserPrincipal()[`HttpServletRequest.html#getUserPrincipal()`] |
| 71 | +** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#isUserInRole(java.lang.String)[`HttpServletRequest.html#isUserInRole(java.lang.String)`] |
| 72 | +** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#login(java.lang.String,%20java.lang.String)[`HttpServletRequest.html#login(java.lang.String, java.lang.String)`] |
| 73 | +** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#logout()[`HttpServletRequest.html#logout()`] |
5 | 74 |
|
6 |
| -include::boot.adoc[leveloffset=+1] |
7 |
| -include::java-configuration.adoc[leveloffset=+1] |
8 |
| -include::xml-configuration.adoc[leveloffset=+1] |
|
0 commit comments