ソースを参照

Polish "How-to: Implement core services with JPA"

Issue gh-690
Issue gh-714
Steve Riesenberg 3 年 前
コミット
3cc89f925e
1 ファイル変更32 行追加22 行削除
  1. 32 22
      docs/src/docs/asciidoc/guides/how-to-jpa.adoc

+ 32 - 22
docs/src/docs/asciidoc/guides/how-to-jpa.adoc

@@ -1,7 +1,5 @@
 [[how-to-jpa]]
 = How-to: Implement core services with JPA
-:toc: left
-:toclevels: 3
 :index-link: ../how-to.html
 :docs-dir: ..
 :examples-dir: ../examples
@@ -9,19 +7,24 @@
 [[jpa-getting-started]]
 == Getting Started
 
-In this guide, we will demonstrate how to implement the xref:{docs-dir}/core-model-components.adoc#core-model-components[core services] of xref:{docs-dir}/index.adoc#top[Spring Authorization Server] with JPA. The purpose of this guide is to provide a starting point for implementing these services yourself, with the intention that you will make modifications as necessary to suit your needs.
+This guide shows how to implement the xref:{docs-dir}/core-model-components.adoc#core-model-components[core services] of xref:{docs-dir}/index.adoc#top[Spring Authorization Server] with JPA.
+The purpose of this guide is to provide a starting point for implementing these services yourself, with the intention that you can make modifications to suit your needs.
 
 [[jpa-define-data-model]]
 == Define the data model
 
-This guide seeks to provide a starting point for the data model and uses the simplest possible structure and data types. To come up with the initial schema, we begin by reviewing the xref:{docs-dir}/core-model-components.adoc#core-model-components[domain objects] used by the core services. Please note:
+This guide provides a starting point for the data model and uses the simplest possible structure and data types.
+To come up with the initial schema, we begin by reviewing the xref:{docs-dir}/core-model-components.adoc#core-model-components[domain objects] used by the core services.
 
-NOTE: Except for token, state, metadata, settings and claims values, we will use the JPA default column length of 255 for all columns. In reality, the length and even type of columns you use may need to be customized. Your mileage may vary and you are encouraged to experiment and test before deploying to production.
+NOTE: Except for token, state, metadata, settings, and claims values, we use the JPA default column length of 255 for all columns.
+In reality, the length and even type of columns you use may need to be customized.
+You are encouraged to experiment and test before deploying to production.
 
 [[jpa-client-schema]]
 === Client Schema
 
-The xref:{docs-dir}/core-model-components.adoc#registered-client[`RegisteredClient`] domain object contains a few multi-valued fields and some settings fields that require storing arbitrary key/value data. The following is an example that we will use to create a JPA entity.
+The xref:{docs-dir}/core-model-components.adoc#registered-client[`RegisteredClient`] domain object contains a few multi-valued fields and some settings fields that require storing arbitrary key/value data.
+The following listing shows the `client` schema.
 
 .Client Schema
 [source,sql]
@@ -32,11 +35,13 @@ include::{examples-dir}/src/main/resources/oauth2-registered-client-schema.sql[]
 [[jpa-authorization-schema]]
 === Authorization Schema
 
-The xref:{docs-dir}/core-model-components.adoc#oauth2-authorization[`OAuth2Authorization`] domain object is more complex, and contains several multi-valued fields as well as numerous arbitrarily long token values, metadata, settings and claims values. The built-in JDBC implementation utilizes a flattened structure that prefers performance over normalization, which we adopt here as well.
+The xref:{docs-dir}/core-model-components.adoc#oauth2-authorization[`OAuth2Authorization`] domain object is more complex and contains several multi-valued fields as well as numerous arbitrarily long token values, metadata, settings and claims values.
+The built-in JDBC implementation utilizes a flattened structure that prefers performance over normalization, which we adopt here as well.
 
-CAUTION: It has been difficult to find a flattened database schema that works well in all cases and with all database vendors. You may need to normalize or heavily alter the following schema for your needs.
+CAUTION: It has been difficult to find a flattened database schema that works well in all cases and with all database vendors.
+You may need to normalize or heavily alter the following schema for your needs.
 
-The following is an example that we will use to create a JPA entity.
+The following listing shows the `authorization` schema.
 
 .Authorization Schema
 [source,sql]
@@ -47,7 +52,8 @@ include::{examples-dir}/src/main/resources/oauth2-authorization-schema.sql[]
 [[jpa-authorization-consent-schema]]
 === Authorization Consent Schema
 
-The xref:{docs-dir}/core-model-components.adoc#oauth2-authorization-consent[`OAuth2AuthorizationConsent`] domain object is the simplest to model, and only contains a single multi-valued field in addition to a composite key.  The following is an example that we will use to create a JPA entity.
+The xref:{docs-dir}/core-model-components.adoc#oauth2-authorization-consent[`OAuth2AuthorizationConsent`] domain object is the simplest to model and contains only a single multi-valued field in addition to a composite key.
+The following listing shows the `authorizationConsent` schema.
 
 .Authorization Consent Schema
 [source,sql]
@@ -60,12 +66,13 @@ include::{examples-dir}/src/main/resources/oauth2-authorization-consent-schema.s
 
 The preceding schema examples provide a reference for the structure of the entities we need to create.
 
-NOTE: The following entities are minimally annotated and are just examples. They allow the schema to be created dynamically and therefore do not require the above sql scripts to be executed manually.
+NOTE: The following entities are minimally annotated and are just examples.
+They allow the schema to be created dynamically and therefore do not require the above sql scripts to be executed manually.
 
 [[jpa-client-entity]]
 === Client Entity
 
-The following is an example of the `Client` entity which is used to persist information mapped from the xref:{docs-dir}/core-model-components.adoc#registered-client[`RegisteredClient`] domain object.
+The following listing shows the `Client` entity, which is used to persist information mapped from the xref:{docs-dir}/core-model-components.adoc#registered-client[`RegisteredClient`] domain object.
 
 .Client Entity
 [source,java]
@@ -76,7 +83,7 @@ include::{examples-dir}/src/main/java/sample/jpa/Client.java[tag=class]
 [[jpa-authorization-entity]]
 === Authorization Entity
 
-The following is an example of the `Authorization` entity which is used to persist information mapped from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization[`OAuth2Authorization`] domain object.
+The following listing shows the `Authorization` entity, which is used to persist information mapped from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization[`OAuth2Authorization`] domain object.
 
 .Authorization Entity
 [source,java]
@@ -87,7 +94,7 @@ include::{examples-dir}/src/main/java/sample/jpa/Authorization.java[tag=class]
 [[jpa-authorization-consent-entity]]
 === Authorization Consent Entity
 
-The following is an example of the `AuthorizationConsent` entity which is used to persist information mapped from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization-consent[`OAuth2AuthorizationConsent`] domain object.
+The following listing shows the `AuthorizationConsent` entity, which is used to persist information mapped from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization-consent[`OAuth2AuthorizationConsent`] domain object.
 
 .Authorization Consent Entity
 [source,java]
@@ -103,7 +110,7 @@ By closely examining the interfaces of each core service and reviewing the `Jdbc
 [[jpa-client-repository]]
 === Client Repository
 
-The following is an example of the `ClientRepository` capable of finding a <<jpa-client-entity,`Client`>> by the `id` and `clientId` fields.
+The following listing shows the `ClientRepository`, which is able to find a <<jpa-client-entity,`Client`>> by the `id` and `clientId` fields.
 
 .Client Repository
 [source,java]
@@ -114,7 +121,8 @@ include::{examples-dir}/src/main/java/sample/jpa/ClientRepository.java[tag=class
 [[jpa-authorization-repository]]
 === Authorization Repository
 
-The following is an example of the `AuthorizationRepository` capable of finding an <<jpa-authorization-entity,`Authorization`>> by the `id` field as well as the `state`, `authorizationCodeValue`, `accessTokenValue` and `refreshTokenValue` token fields. It also allows querying a combination of token fields.
+The following listing shows the `AuthorizationRepository`, which is able to find an <<jpa-authorization-entity,`Authorization`>> by the `id` field as well as the `state`, `authorizationCodeValue`, `accessTokenValue` and `refreshTokenValue` token fields.
+It also allows querying a combination of token fields.
 
 .Authorization Repository
 [source,java]
@@ -125,7 +133,7 @@ include::{examples-dir}/src/main/java/sample/jpa/AuthorizationRepository.java[ta
 [[jpa-authorization-consent-repository]]
 === Authorization Consent Repository
 
-The following is an example of the `AuthorizationConsentRepository` capable of finding and deleting an <<jpa-authorization-consent-entity,`AuthorizationConsent`>> by the `registeredClientId` and `principalName` fields, which form a composite primary key.
+The following listing shows the `AuthorizationConsentRepository`, which is able to find and delete an <<jpa-authorization-consent-entity,`AuthorizationConsent`>> by the `registeredClientId` and `principalName` fields that form a composite primary key.
 
 .Authorization Consent Repository
 [source,java]
@@ -136,14 +144,16 @@ include::{examples-dir}/src/main/java/sample/jpa/AuthorizationConsentRepository.
 [[jpa-implement-core-services]]
 == Implement core services
 
-With the above <<jpa-create-jpa-entities,entities>> and <<jpa-create-spring-data-repositories,repositories>>, we can begin implementing the core services. By reviewing the `Jdbc` implementations, we can derive a minimal set of internal utilities for converting to/from string values for enumerations and reading/writing JSON data for attributes, settings, metadata and claims fields.
+With the above <<jpa-create-jpa-entities,entities>> and <<jpa-create-spring-data-repositories,repositories>>, we can begin implementing the core services.
+By reviewing the `Jdbc` implementations, we can derive a minimal set of internal utilities for converting to and from string values for enumerations and reading and writing JSON data for attributes, settings, metadata and claims fields.
 
-CAUTION: Keep in mind that writing JSON data to text columns with a fixed length has proven problematic with the `Jdbc` implementations. While these examples continue to do so, you may need to split these fields out into a separate table or data store that supports arbitrarily long data values.
+CAUTION: Keep in mind that writing JSON data to text columns with a fixed length has proven problematic with the `Jdbc` implementations.
+While these examples continue to do so, you may need to split these fields out into a separate table or data store that supports arbitrarily long data values.
 
 [[jpa-registered-client-repository]]
 === Registered Client Repository
 
-The following is an example of the `JpaRegisteredClientRepository` which uses a <<jpa-client-repository,`ClientRepository`>> for persisting a <<jpa-client-entity,`Client`>>, and maps to/from the xref:{docs-dir}/core-model-components.adoc#registered-client[`RegisteredClient`] domain object.
+The following listing shows the `JpaRegisteredClientRepository`, which uses a <<jpa-client-repository,`ClientRepository`>> for persisting a <<jpa-client-entity,`Client`>> and maps to and from the xref:{docs-dir}/core-model-components.adoc#registered-client[`RegisteredClient`] domain object.
 
 .`RegisteredClientRepository` Implementation
 [source,java]
@@ -154,7 +164,7 @@ include::{examples-dir}/src/main/java/sample/jpa/JpaRegisteredClientRepository.j
 [[jpa-authorization-service]]
 === Authorization Service
 
-The following is an example of the `JpaOAuth2AuthorizationService` which uses an <<jpa-authorization-repository,`AuthorizationRepository`>> for persisting an <<jpa-authorization-entity,`Authorization`>>, and maps to/from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization[`OAuth2Authorization`] domain object.
+The following listing shows the `JpaOAuth2AuthorizationService`, which uses an <<jpa-authorization-repository,`AuthorizationRepository`>> for persisting an <<jpa-authorization-entity,`Authorization`>> and maps to and from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization[`OAuth2Authorization`] domain object.
 
 .`OAuth2AuthorizationService` Implementation
 [source,java]
@@ -165,7 +175,7 @@ include::{examples-dir}/src/main/java/sample/jpa/JpaOAuth2AuthorizationService.j
 [[jpa-authorization-consent-service]]
 === Authorization Consent Service
 
-The following is an example of the `JpaOAuth2AuthorizationConsentService` which uses an <<jpa-authorization-consent-repository,`AuthorizationConsentRepository`>> for persisting an <<jpa-authorization-consent-entity,`AuthorizationConsent`>>, and maps to/from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization-consent[`OAuth2AuthorizationConsent`] domain object.
+The following listing shows the `JpaOAuth2AuthorizationConsentService`, which uses an <<jpa-authorization-consent-repository,`AuthorizationConsentRepository`>> for persisting an <<jpa-authorization-consent-entity,`AuthorizationConsent`>> and maps to and from the xref:{docs-dir}/core-model-components.adoc#oauth2-authorization-consent[`OAuth2AuthorizationConsent`] domain object.
 
 .`OAuth2AuthorizationConsentService` Implementation
 [source,java]