getting-started.adoc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. [[servlet-hello]]
  2. = Hello Spring Security
  3. This section covers the minimum setup for how to use Spring Security with Spring Boot.
  4. [NOTE]
  5. ====
  6. The completed application can be found {gh-samples-url}/servlet/spring-boot/java/hello-security[in our samples repository].
  7. 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].
  8. ====
  9. [[servlet-hello-dependencies]]
  10. == Updating Dependencies
  11. The only step you need to do is update the dependencies by using xref:getting-spring-security.adoc#getting-maven-boot[Maven] or xref:getting-spring-security.adoc#getting-gradle-boot[Gradle].
  12. [[servlet-hello-starting]]
  13. == Starting Hello Spring Security Boot
  14. 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.
  15. The following example shows how to do so (and the beginning of the output from doing so):
  16. .Running Spring Boot Application
  17. [source,bash]
  18. ----
  19. $ ./mvn spring-boot:run
  20. ...
  21. INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
  22. Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336
  23. ...
  24. ----
  25. [[servlet-hello-auto-configuration]]
  26. == Spring Boot Auto Configuration
  27. // FIXME: Link to relevant portions of documentation
  28. // FIXME: Link to Spring Boot's Security Auto configuration classes
  29. // FIXME: Add a links for what user's should do next
  30. Spring Boot automatically:
  31. * Enables Spring Security's default configuration, which creates a servlet `Filter` as a bean named `springSecurityFilterChain`.
  32. 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.
  33. * Creates a `UserDetailsService` bean with a username of `user` and a randomly generated password that is logged to the console.
  34. * Registers the `Filter` with a bean named `springSecurityFilterChain` with the Servlet container for every request.
  35. Spring Boot is not configuring much, but it does a lot.
  36. A summary of the features follows:
  37. * Require an authenticated user for any interaction with the application
  38. * Generate a default login form for you
  39. * 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`)
  40. * Protects the password storage with BCrypt
  41. * Lets the user log out
  42. * https://en.wikipedia.org/wiki/Cross-site_request_forgery[CSRF attack] prevention
  43. * https://en.wikipedia.org/wiki/Session_fixation[Session Fixation] protection
  44. * Security Header integration
  45. ** https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security[HTTP Strict Transport Security] for secure requests
  46. ** https://msdn.microsoft.com/en-us/library/ie/gg622941(v=vs.85).aspx[X-Content-Type-Options] integration
  47. ** Cache Control (can be overridden later by your application to allow caching of your static resources)
  48. ** https://msdn.microsoft.com/en-us/library/dd565647(v=vs.85).aspx[X-XSS-Protection] integration
  49. ** X-Frame-Options integration to help prevent https://en.wikipedia.org/wiki/Clickjacking[Clickjacking]
  50. * Integrate with the following Servlet API methods:
  51. ** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getRemoteUser()[`HttpServletRequest#getRemoteUser()`]
  52. ** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getUserPrincipal()[`HttpServletRequest.html#getUserPrincipal()`]
  53. ** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#isUserInRole(java.lang.String)[`HttpServletRequest.html#isUserInRole(java.lang.String)`]
  54. ** 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)`]
  55. ** https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#logout()[`HttpServletRequest.html#logout()`]