getting-started.adoc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. [[getting-started]]
  2. = Getting Started with WebFlux Applications
  3. This section covers the minimum setup for how to use Spring Security with Spring Boot in a reactive application.
  4. [NOTE]
  5. ====
  6. The completed application can be found {gh-samples-url}/reactive/webflux/java/hello-security[in our samples repository].
  7. For your convenience, you can download a minimal Reactive 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=webflux,security[clicking here].
  8. ====
  9. [[dependencies]]
  10. == Updating Dependencies
  11. You can add Spring Security to your Spring Boot project by adding `spring-boot-starter-security`.
  12. [tabs]
  13. ======
  14. Maven::
  15. +
  16. [source,xml,role="primary"]
  17. ----
  18. <dependency>
  19. <groupId>org.springframework.boot</groupId>
  20. <artifactId>spring-boot-starter-security</artifactId>
  21. </dependency>
  22. ----
  23. Gradle::
  24. +
  25. [source,groovy,role="secondary"]
  26. ----
  27. implementation 'org.springframework.boot:spring-boot-starter-security'
  28. ----
  29. ======
  30. [[servlet-hello-starting]]
  31. == Starting Hello Spring Security Boot
  32. 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.
  33. The following example shows how to do so (and the beginning of the output from doing so):
  34. .Running Spring Boot Application
  35. [tabs]
  36. ======
  37. Maven::
  38. +
  39. [source,bash,role="primary"]
  40. ----
  41. $ ./mvnw spring-boot:run
  42. ...
  43. INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
  44. Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336
  45. ...
  46. ----
  47. Gradle::
  48. +
  49. [source,bash,role="secondary"]
  50. ----
  51. $ ./gradlew bootRun
  52. ...
  53. INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
  54. Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336
  55. ...
  56. ----
  57. ======
  58. [[authenticating]]
  59. == Authenticating
  60. You can access the application at http://localhost:8080/ which will redirect the browser to the default log in page. You can provide the default username of `user` with the randomly generated password that is logged to the console. The browser is then taken to the originally requested page.
  61. To log out you can visit http://localhost:8080/logout and then confirming you wish to log out.
  62. [[auto-configuration]]
  63. == Spring Boot Auto Configuration
  64. Spring Boot automatically adds Spring Security which requires all requests be authenticated. It also generates a user with a randomly generated password that is logged to the console which can be used to authenticate using form or basic authentication.