Browse Source

Use direct code import

Issue gh-1231
pull/1288/head
Steve Riesenberg 3 years ago
parent
commit
d45a1fbfce
No known key found for this signature in database
GPG Key ID: 5F311AB48A55D521
  1. 6
      docs/src/docs/asciidoc/getting-started.adoc
  2. 45
      docs/src/docs/asciidoc/guides/how-to-jpa.adoc
  3. 25
      docs/src/docs/asciidoc/guides/how-to-userinfo.adoc

6
docs/src/docs/asciidoc/getting-started.adoc

@ -80,7 +80,11 @@ If you want to customize the default configuration (regardless of whether you're @@ -80,7 +80,11 @@ If you want to customize the default configuration (regardless of whether you're
These components can be defined as follows:
[[sample.gettingStarted]]
include::code:SecurityConfig[]
.SecurityConfig.java
[source,java]
----
include::{docs-java}/sample/gettingStarted/SecurityConfig.java[]
----
This is a minimal configuration for getting started quickly. To understand what each component is used for, see the following descriptions:

45
docs/src/docs/asciidoc/guides/how-to-jpa.adoc

@ -146,7 +146,10 @@ The following listing shows the `Client` entity, which is used to persist inform @@ -146,7 +146,10 @@ The following listing shows the `Client` entity, which is used to persist inform
[[sample.jpa.entity.client]]
.Client Entity
include::code:Client[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/entity/client/Client.java[]
----
[[authorization-entity]]
=== Authorization Entity
@ -155,7 +158,10 @@ The following listing shows the `Authorization` entity, which is used to persist @@ -155,7 +158,10 @@ The following listing shows the `Authorization` entity, which is used to persist
[[sample.jpa.entity.authorization]]
.Authorization Entity
include::code:Authorization[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/entity/authorization/Authorization.java[]
----
[[authorization-consent-entity]]
=== Authorization Consent Entity
@ -164,7 +170,10 @@ The following listing shows the `AuthorizationConsent` entity, which is used to @@ -164,7 +170,10 @@ The following listing shows the `AuthorizationConsent` entity, which is used to
[[sample.jpa.entity.authorizationConsent]]
.Authorization Consent Entity
include::code:AuthorizationConsent[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/entity/authorizationConsent/AuthorizationConsent.java[]
----
[[create-spring-data-repositories]]
== Create Spring Data repositories
@ -182,7 +191,10 @@ The following listing shows the `ClientRepository`, which is able to find a <<cl @@ -182,7 +191,10 @@ The following listing shows the `ClientRepository`, which is able to find a <<cl
[[sample.jpa.repository.client]]
.Client Repository
include::code:ClientRepository[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/repository/client/ClientRepository.java[]
----
[[authorization-repository]]
=== Authorization Repository
@ -192,7 +204,10 @@ It also allows querying a combination of token fields. @@ -192,7 +204,10 @@ It also allows querying a combination of token fields.
[[sample.jpa.repository.authorization]]
.Authorization Repository
include::code:AuthorizationRepository[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/repository/authorization/AuthorizationRepository.java[]
----
[[authorization-consent-repository]]
=== Authorization Consent Repository
@ -201,7 +216,10 @@ The following listing shows the `AuthorizationConsentRepository`, which is able @@ -201,7 +216,10 @@ The following listing shows the `AuthorizationConsentRepository`, which is able
[[sample.jpa.repository.authorizationConsent]]
.Authorization Consent Repository
include::code:AuthorizationConsentRepository[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/repository/authorizationConsent/AuthorizationConsentRepository.java[]
----
[[implement-core-services]]
== Implement core services
@ -224,7 +242,10 @@ The following listing shows the `JpaRegisteredClientRepository`, which uses a << @@ -224,7 +242,10 @@ The following listing shows the `JpaRegisteredClientRepository`, which uses a <<
[[sample.jpa.service.client]]
.`RegisteredClientRepository` Implementation
include::code:JpaRegisteredClientRepository[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/service/client/JpaRegisteredClientRepository.java[]
----
[[authorization-service]]
=== Authorization Service
@ -233,7 +254,10 @@ The following listing shows the `JpaOAuth2AuthorizationService`, which uses an < @@ -233,7 +254,10 @@ The following listing shows the `JpaOAuth2AuthorizationService`, which uses an <
[[sample.jpa.service.authorization]]
.`OAuth2AuthorizationService` Implementation
include::code:JpaOAuth2AuthorizationService[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/service/authorization/JpaOAuth2AuthorizationService.java[]
----
[[authorization-consent-service]]
=== Authorization Consent Service
@ -242,4 +266,7 @@ The following listing shows the `JpaOAuth2AuthorizationConsentService`, which us @@ -242,4 +266,7 @@ The following listing shows the `JpaOAuth2AuthorizationConsentService`, which us
[[sample.jpa.service.authorizationConsent]]
.`OAuth2AuthorizationConsentService` Implementation
include::code:JpaOAuth2AuthorizationConsentService[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/jpa/service/authorizationConsent/JpaOAuth2AuthorizationConsentService.java[]
----

25
docs/src/docs/asciidoc/guides/how-to-userinfo.adoc

@ -22,7 +22,10 @@ Before customizing the response, you need to enable the UserInfo endpoint. @@ -22,7 +22,10 @@ Before customizing the response, you need to enable the UserInfo endpoint.
The following listing shows how to enable the {spring-security-reference-base-url}/servlet/oauth2/resource-server/jwt.html[OAuth2 resource server configuration].
[[sample.userinfo]]
include::code:EnableUserInfoSecurityConfig[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/userinfo/EnableUserInfoSecurityConfig.java[]
----
TIP: Click on the "Expand folded text" icon in the code sample above to display the full example.
@ -50,7 +53,10 @@ The preferred way to customize the user info response is to add standard claims @@ -50,7 +53,10 @@ The preferred way to customize the user info response is to add standard claims
The following listing shows how to add claims to the `id_token`.
[[sample.userinfo.idtoken]]
include::code:IdTokenCustomizerConfig[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/userinfo/idtoken/IdTokenCustomizerConfig.java[]
----
This configuration provides the following:
@ -59,7 +65,10 @@ This configuration provides the following: @@ -59,7 +65,10 @@ This configuration provides the following:
The following listing shows a custom service for looking up user info in a domain-specific way:
include::code:OidcUserInfoService[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/userinfo/idtoken/OidcUserInfoService.java[]
----
[[customize-user-info-mapper]]
=== Customize the User Info Mapper
@ -70,7 +79,10 @@ The mapper implementation receives an instance of `OidcUserInfoAuthenticationCon @@ -70,7 +79,10 @@ The mapper implementation receives an instance of `OidcUserInfoAuthenticationCon
The following listing shows how to use the customization option that is available while working directly with the `OAuth2AuthorizationServerConfigurer`.
[[sample.userinfo.jwt]]
include::code:JwtUserInfoMapperSecurityConfig[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/userinfo/jwt/JwtUserInfoMapperSecurityConfig.java[]
----
This configuration maps claims from the access token (which is a JWT when using the xref:{docs-dir}/getting-started.adoc#sample.gettingStarted[Getting Started config]) to populate the user info response and provides the following:
@ -83,6 +95,9 @@ This configuration maps claims from the access token (which is a JWT when using @@ -83,6 +95,9 @@ This configuration maps claims from the access token (which is a JWT when using
The user info mapper is not limited to mapping claims from a JWT, but this is a simple example that demonstrates the customization option.
Similar to the <<customize-id-token,example shown earlier>> where we customize claims of the ID token, you can customize claims of the access token itself ahead of time, as in the following example:
include::code:JwtTokenCustomizerConfig[]
[source,java]
----
include::{examples-dir}/src/main/java/sample/userinfo/jwt/JwtTokenCustomizerConfig.java[]
----
Whether you customize the user info response directly or use this example and customize the access token, you can look up information in a database, perform an LDAP query, make a request to another service, or use any other means of obtaining the information you want to be presented in the user info response.

Loading…
Cancel
Save