getting-started.adoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. [[getting-started]]
  2. = Getting Started
  3. If you are just getting started with Spring Authorization Server, the following sections walk you through creating your first application.
  4. [[system-requirements]]
  5. == System Requirements
  6. Spring Authorization Server requires a Java 17 or higher Runtime Environment.
  7. [[installing-spring-authorization-server]]
  8. == Installing Spring Authorization Server
  9. Spring Authorization Server can be used anywhere you already use https://docs.spring.io/spring-security/reference/prerequisites.html[Spring Security].
  10. The easiest way to begin using Spring Authorization Server is by creating a https://spring.io/projects/spring-boot[Spring Boot]-based application.
  11. You can use https://start.spring.io[start.spring.io] to generate a basic project or use the https://github.com/spring-projects/spring-authorization-server/tree/main/samples/default-authorizationserver[default authorization server sample] as a guide.
  12. Then add Spring Boot's starter for Spring Authorization Server as a dependency:
  13. [tabs]
  14. ======
  15. Maven::
  16. +
  17. [[spring-boot-maven-dependency]]
  18. [source,xml,role="primary",subs="attributes,verbatim"]
  19. ----
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter-oauth2-authorization-server</artifactId>
  23. </dependency>
  24. ----
  25. Gradle::
  26. +
  27. [[spring-boot-gradle-dependency]]
  28. [source,gradle,role="secondary",subs="attributes,verbatim"]
  29. ----
  30. implementation "org.springframework.boot:spring-boot-starter-oauth2-authorization-server"
  31. ----
  32. ======
  33. TIP: See https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started.html#getting-started.installing[Installing Spring Boot] for more information on using Spring Boot with Maven or Gradle.
  34. Alternatively, you can add Spring Authorization Server without Spring Boot using the following example:
  35. [tabs]
  36. ======
  37. Maven::
  38. +
  39. [[maven-dependency]]
  40. [source,xml,role="primary",subs="attributes,verbatim"]
  41. ----
  42. <dependency>
  43. <groupId>org.springframework.security</groupId>
  44. <artifactId>spring-security-oauth2-authorization-server</artifactId>
  45. <version>{spring-authorization-server-version}</version>
  46. </dependency>
  47. ----
  48. Gradle::
  49. +
  50. [[gradle-dependency]]
  51. [source,gradle,role="secondary",subs="attributes,verbatim"]
  52. ----
  53. implementation "org.springframework.security:spring-security-oauth2-authorization-server:{spring-authorization-server-version}"
  54. ----
  55. ======
  56. [[developing-your-first-application]]
  57. == Developing Your First Application
  58. To get started, you need the minimum required components defined as a `@Bean`. When using the `spring-boot-starter-oauth2-authorization-server` dependency, define the following properties and Spring Boot will provide the necessary `@Bean` definitions for you:
  59. [[application-yml]]
  60. .application.yml
  61. [source,yaml]
  62. ----
  63. include::{docs-java}/sample/gettingstarted/application.yml[]
  64. ----
  65. TIP: Beyond the Getting Started experience, most users will want to customize the default configuration. The xref:getting-started.adoc#defining-required-components[next section] demonstrates providing all of the necessary beans yourself.
  66. [[defining-required-components]]
  67. == Defining Required Components
  68. If you want to customize the default configuration (regardless of whether you're using Spring Boot), you can define the minimum required components as a `@Bean` in a Spring `@Configuration`.
  69. These components can be defined as follows:
  70. [[sample.gettingstarted]]
  71. .SecurityConfig.java
  72. [source,java]
  73. ----
  74. include::{docs-java}/sample/gettingstarted/SecurityConfig.java[]
  75. ----
  76. This is a minimal configuration for getting started quickly. To understand what each component is used for, see the following descriptions:
  77. <1> A Spring Security filter chain for the xref:protocol-endpoints.adoc[Protocol Endpoints].
  78. <2> A Spring Security filter chain for https://docs.spring.io/spring-security/reference/servlet/authentication/index.html[authentication].
  79. <3> An instance of {spring-security-api-base-url}/org/springframework/security/core/userdetails/UserDetailsService.html[`UserDetailsService`] for retrieving users to authenticate.
  80. <4> An instance of xref:core-model-components.adoc#registered-client-repository[`RegisteredClientRepository`] for managing clients.
  81. <5> An instance of `com.nimbusds.jose.jwk.source.JWKSource` for signing access tokens.
  82. <6> An instance of `java.security.KeyPair` with keys generated on startup used to create the `JWKSource` above.
  83. <7> An instance of {spring-security-api-base-url}/org/springframework/security/oauth2/jwt/JwtDecoder.html[`JwtDecoder`] for decoding signed access tokens.
  84. <8> An instance of xref:configuration-model#configuring-authorization-server-settings[`AuthorizationServerSettings`] to configure Spring Authorization Server.