getting-started.adoc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ====
  13. .Maven
  14. [source,xml,role="primary"]
  15. ----
  16. <dependency>
  17. <groupId>org.springframework.boot</groupId>
  18. <artifactId>spring-boot-starter-security</artifactId>
  19. </dependency>
  20. ----
  21. .Gradle
  22. [source,groovy,role="secondary"]
  23. ----
  24. implementation 'org.springframework.boot:spring-boot-starter-security'
  25. ----
  26. ====
  27. [[servlet-hello-starting]]
  28. == Starting Hello Spring Security Boot
  29. 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.
  30. The following example shows how to do so (and the beginning of the output from doing so):
  31. .Running Spring Boot Application
  32. ====
  33. .Maven
  34. [source,bash,role="primary"]
  35. ----
  36. $ ./mvnw spring-boot:run
  37. ...
  38. INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
  39. Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336
  40. ...
  41. ----
  42. .Gradle
  43. [source,bash,role="secondary"]
  44. ----
  45. $ ./gradlew bootRun
  46. ...
  47. INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
  48. Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336
  49. ...
  50. ----
  51. ====
  52. [[authenticating]]
  53. == Authenticating
  54. 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 orginally requested page.
  55. To log out you can visit http://localhost:8080/logout and then confirming you wish to log out.
  56. [[auto-configuration]]
  57. == Spring Boot Auto Configuration
  58. 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.