---
schema_version: "1"
id: ef5728b7852370cccaac3c07c3c30c7c6ce6f5fefab7abb4be217f70b5ed5f2a
title: OAuth2 プロバイダーの移行
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/mule-runtime/4.8/migration-oauth2-provider.md
canonical_url: https://docs.mulesoft.com/jp/mule-runtime/4.8/migration-oauth2-provider
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 97a76b7cd011f4666182b625c6ccef81fddd328d09b2d33e1911abcc803d9dc2
description: MuleSoft Documentation Site
release: "4.8"
latest: false
---
# OAuth2 プロバイダーの移行

Anypoint Enterprise Security の以前のプロバイダーは、Mule 4 の新しい OAuth2 Provider Module に置き換えられます。 ただし、アプリケーションを移行するときに考慮する必要がある設定変更がいくつかあります。

## [](#グローバル設定の移行)グローバル設定の移行

プロバイダーのグローバル設定で行われた変更とバージョン間の違いを以下に示します。

### [](#変更された属性)変更された属性

属性の状況は次のとおりです。

- 維持: 同じ名前、型、場所を使用します。
- 移動: 属性の名前と型は同じですが、設定を行う場所が変更されました。
- 変更: 型または名前が変更されましたが、場所は同じです。
- 削除: 属性は存在しません。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Mule 3 の属性</th>
<th class="tableblock halign-left valign-top">状況</th>
<th class="tableblock halign-left valign-top">Mule 4 の設定</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Name (名前)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">維持</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Name (名前)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Provider Name (プロバイダー名)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">維持</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Provider Name (プロバイダー名)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Host (ホスト)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ホストは ​<strong>Listener Config (リスナー設定)</strong>​ の Http Configuration (Http 設定) から取得されます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Port (ポート)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ポートは ​<strong>Listener Config (リスナー設定)</strong>​ の Http Configuration (Http 設定) から取得されます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Client Store Ref (クライアントストア参照)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">属性はオブジェクトストアになりました。参照または非公開オブジェクトストアの定義である必要があります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Authorization Code Store Ref (認証コードストア参照)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">移動、変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">認証コードストアは、​<strong>Authorization Config (認証設定)</strong>​ の属性として設定し、オブジェクトストアである必要があります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Token Generator Strategy (トークンジェネレーター戦略)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">維持</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Token Generator Strategy (トークンジェネレーター戦略)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Token Store Ref (トークンストア参照)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">移動、変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">トークンストアは、​<strong>Token Config (トークン設定)</strong>​ の属性として設定し、オブジェクトストアである必要があります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Login Page (ログインページ)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">移動</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ログインページは ​<strong>Authorization Config (認証設定)</strong>​ の属性として設定します。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">スコープ</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">維持</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">カンマ区切りにする必要があります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Default Scopes (デフォルトスコープ)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">維持</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">カンマ区切りにする必要があります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Supported Grant Types (サポートされる付与種別)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">維持</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">カンマ区切りにする必要があります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Authorization Endpoint Path (認証エンドポイントパス)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変更、移動</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Authorization Config (認証設定)</strong>​ の属性 ​<em>path</em>​ で設定できます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Access Token Endpoint Path (アクセストークンエンドポイントパス)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変更、移動</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Token Config (トークン設定)</strong>​ の属性 ​<em>path</em>​ で設定できます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Authorization Ttl Seconds (認証 Ttl 秒)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">認証コード Ttl は、​<strong>Authorization Code Store (認証コードストア)</strong>​ オブジェクトストアで設定された entry Ttl (入力 Ttl) から取得されます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Token Ttl Seconds (トークン Ttl 秒)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">移動、変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">トークン Ttl は ​<strong>Token Store (トークンストア)</strong>​ オブジェクトストアから取得されます。コード上の制限により、この項目を ​<strong>TokenConfig</strong>​ の属性 ​<em>tokenTtl</em>​ と ​<em>tokenTtlTimeUnit</em>​ でも設定する必要があります。​<strong>Token Store (トークンストア)</strong>​ の ​<em>entryTtl</em>​ と ​<strong>Token Config (トークン設定)</strong>​ の ​<em>tokenTtl</em>​ (および ​<em>tokenTtlTimeUnit</em>​) は同じにする必要があります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Refresh Token Ttl Seconds (更新トークン Ttl 秒)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新トークン Ttl は、​<strong>Refresh Token Strategy (更新トークン戦略)</strong>​ で設定されたオブジェクトストアの entry Ttl (入力 Ttl) から取得されます (ある場合)。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Connector (コネクタ)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">トランスポートが Mule 4 から削除されたので、この項目には意味がなくなりました。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">HttpListenerConfig</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Listener Config (リスナー設定)</strong>​ と呼ばれるようになりました。必須です。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Resource Owner Security Provider Ref (リソースオーナーセキュリティプロバイダー参照)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Ref</strong>​ が属性の名前から削除されました。Spring Security Provider (Spring セキュリティプロバイダー) が設定されている場合は、Spring Module を使用します。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Client Security Provider Ref (クライアントセキュリティプロバイダー参照)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Ref</strong>​ が属性の名前から削除されました。Spring Security Provider (Spring セキュリティプロバイダー) が設定されている場合は、Spring Module を使用します。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Enable Refresh Token (更新トークンの有効化)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">別の ​<strong>Refresh Token Strategy (更新トークン戦略)</strong>​ に設定できます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Issue New Refresh Token (更新トークンの新規発行)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">別の ​<strong>Refresh Token Strategy (更新トークン戦略)</strong>​ に設定できます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Rate Limiter (レートリミッター)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変更</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Spring bean からカスタム実装を追加する必要がなくなりました。Period Rate Limiter (期間レートリミッター) のみが実装されるようになりました。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Clients (クライアント)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">維持</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">各クライアント定義が変更されました。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Pre Flow (プリフロー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">削除</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">プリフロー機能は、このバージョンではサポートされません。</p></td>
</tr>
</tbody>
</table>

## [](#ストア)ストア

Authentication Code (認証コード)、Token (トークン)、または Refresh token (更新トークン) ストアはなくなりました。これらのカスタム実装を参照できる属性はありません。 ストレージ設定は、オブジェクトストアで行われるようになりました。

カスタム動作が必要な場合は、オブジェクトストアのカスタム実装を使用してそれらの属性を設定します。

## [](#セキュリティプロバイダー)セキュリティプロバイダー

Mule 4 では、アプリケーション設定を Spring から完全に分離したので、Spirng bean を参照して設定された一部の属性の設定方法が変更されました。

Spring セキュリティプロバイダーは引き続き使用できますが、その場合、アプリケーションが機能するには Spring Module が必要です。

## [](#更新トークン属性)更新トークン属性

Mule 3 には、更新トークンの動作を設定できる 2 つの属性がありました。さまざまな更新トークン戦略が使用されるようになったので、次のように設定する必要があります。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Enable Refresh Token (更新トークンの有効化)</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Issue New Refresh Token (更新トークンの新規発行)</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Refresh Token Strategy (更新トークン戦略)</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">False</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新トークン戦略なし</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">True</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">False</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1 つの更新トークン戦略</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">True</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">複数の更新トークン戦略</p></td>
</tr>
</tbody>
</table>

## [](#clients-クライアント)Clients (クライアント)

どちらの Mule バージョンでも、認証サーバーに要求を実行できるクライアントのリストを定義する可能性があります。

クライアントを追加する方法は、一部の属性名以外は変わりありません。新しいバージョンの制限により、子要素の名前は、​_clients_​ および ​_client_​ プレフィックスを追加して変更する必要がありました。

- Redirect Uri(s) → Client Redirect Uris(s)
- Authorized Grant Type(s) → Client Authorized Grant Type(s)
- Scope(s) → Client Scope(s)

## [](#操作)操作

Mule 3 のモジュールで使用可能な操作と Mule 4 で行われた変更を以下に示します

### [](#validate-client)Validate Client

この操作は Mule 4 から削除されました。

### [](#validate)Validate

この操作は、​**Validate Token**​ と呼ばれるようになりました。

Oauth2 プロバイダーの操作は HTTP にリンクされなくなったので、検証するトークンを解決する式が必要です。

Mule 3 では、トークン検証後、関連するリソースオーナー認証がある場合、そのリソースオーナー認証で新しいセキュリティコンテキストが作成されました。さらに、トークン情報を持つトークン保有者が _mule.oauth2.access\_token\_store\_holder_ というフロー変数に保存されました。  
Mule 4 では、その同じ情報が若干異なる方法で保存されます。トークン検証後、​`#[authentication]`​ によってアクセス可能なトークン認証を使用してセキュリティコンテキストが作成されます。変数内のトークン所有者は、そのトークン認証の属性 ​`#[authentication.tokenHolder]`​ として保存されます。同時に、関連するリソースオーナーがある場合、その情報には ​`#[authentication.tokenHolder.resourceOwnerAuthentication]`​ を評価して到達できます。

### [](#create-client)Create Client

この操作は、​**Fail If Present (存在する場合は失敗)**​ という新しい属性が追加された以外は変わりありません。

**Fail If Present (存在する場合は失敗)**​ では、追加されるクライアントと同じ ID を持つクライアントが既存する場合にどうするかを指定できます。

- true の場合、操作は失敗します。
- false の場合、クライアント情報が更新されます。

### [](#delete-client)Delete Client

この操作は変わりありません。

### [](#revoke-token)Revoke Token

この操作は変わりありません。

## [](#例)例

Mule 3 と Mule 4 で同じアプリケーションを設定した例を次に示します。

アプリケーションには、トークンを付与する Oauth2 プロバイダーと HTTP 要求をリスンするフローがあり、あるロジックを処理する前にトークン検証があります。

Mule 4 設定では Spring Module と Object Store Connector が使用されている点に留意してください。

どちらの場合も、アプリケーションは複数のファイルに分割されています。

Mule 3 の場合は、共通設定と実際の OAuth2 プロバイダー設定に 1 つずつ、2 つのファイルがあります。  
Mule 4 の場合は、bean 定義、共通設定、実際の OAuth2 プロバイダー設定に 1 つずつ、3 つのファイルがあります。

### [](#mule-3)Mule 3

#### [](#共通設定)共通設定

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
    xmlns:ss="http://www.springframework.org/schema/security"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/current/mule-spring-security.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <global-property name="allSupportedGrantTypes"
                     value="AUTHORIZATION_CODE IMPLICIT RESOURCE_OWNER_PASSWORD_CREDENTIALS CLIENT_CREDENTIALS" />

    <spring:beans>
        <spring:bean name="rateLimiter"
                     class="org.mule.modules.oauth2.provider.ratelimit.SimpleInMemoryRateLimiter" />

        <spring:bean name="clientObjectStore"
                     class="org.mule.util.store.InMemoryObjectStore" />
        <spring:bean name="authorizationCodeObjectStore"
                     class="org.mule.util.store.InMemoryObjectStore" />
        <spring:bean name="tokenObjectStore"
                     class="org.mule.util.store.InMemoryObjectStore" />
        <spring:bean name="refreshTokenObjectStore"
                     class="org.mule.util.store.InMemoryObjectStore" />

        <spring:bean name="clientStore"
                     class="org.mule.modules.oauth2.provider.client.ObjectStoreClientStore"
                     p:objectStore-ref="clientObjectStore" />

        <spring:bean name="tokenStore"
                     class="org.mule.modules.oauth2.provider.token.ObjectStoreTokenStore"
                     p:refreshTokenObjectStore-ref="refreshTokenObjectStore"
                     p:accessTokenObjectStore-ref="tokenObjectStore"/>

        <spring:bean name="authorizationCodeStore"
                     class="org.mule.modules.oauth2.provider.code.ObjectStoreAuthorizationCode"
                     p:objectStore-ref="authorizationCodeObjectStore" />

        <ss:authentication-manager id="resourceOwnerAuthenticationManager">
            <ss:authentication-provider>
                <ss:user-service id="resourceOwnerUserService">
                    <ss:user name="rousr"
                             password="ropwd+%"
                             authorities="RESOURCE_OWNER" />
                </ss:user-service>
            </ss:authentication-provider>
        </ss:authentication-manager>

        <ss:authentication-manager id="clientAuthenticationManager">
            <ss:authentication-provider>
                <ss:user-service id="clientUserService">
                    <ss:user name="clusr"
                             password="clpwd+%"
                             authorities="CLIENT" />
                </ss:user-service>
            </ss:authentication-provider>
        </ss:authentication-manager>
    </spring:beans>

    <mule-ss:security-manager>
        <mule-ss:delegate-security-provider
            name="resourceOwnerSecurityProvider"
            delegate-ref="resourceOwnerAuthenticationManager" />
        <mule-ss:delegate-security-provider
            name="clientSecurityProvider"
            delegate-ref="clientAuthenticationManager" />
    </mule-ss:security-manager>
</mule>
```

#### [](#アプリケーション設定)アプリケーション設定

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:oauth2-provider="http://www.mulesoft.org/schema/mule/oauth2-provider"
      xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xsi:schemaLocation=
        "http://www.mulesoft.org/schema/mule/oauth2-provider http://www.mulesoft.org/schema/mule/oauth2-provider/current/mule-oauth2-provider.xsd
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

    <oauth2-provider:config name="OAuth2Provider"
                            providerName="Test OAuth2Provider"
                            loginPage="static/auth.html"
                            authorizationEndpointPath="authorize"
                            accessTokenEndpointPath="token"
                            host="localhost"
                            port="8081"
                            resourceOwnerSecurityProvider-ref="resourceOwnerSecurityProvider"
                            clientSecurityProvider-ref="clientSecurityProvider"
                            clientStore-ref="clientStore"
                            tokenStore-ref="tokenStore"
                            authorizationCodeStore-ref="authorizationCodeStore"
                            rateLimiter-ref="rateLimiter"
                            scopes="GUEST USER ADMIN"
                            defaultScopes="USER"
                            supportedGrantTypes="${allSupportedGrantTypes}"
                            authorizationTtlSeconds="600"
                            tokenTtlSeconds="86400"
                            refreshTokenTtlSeconds="-1"
                            enableRefreshToken="true"
                            issueNewRefreshToken="true">

        <oauth2-provider:clients>
            <oauth2-provider:client clientId="clientId1"
                                    secret="clientSecret1"
                                    principal="clusr"
                                    type="CONFIDENTIAL">
                <oauth2-provider:redirect-uris>
                    <oauth2-provider:redirect-uri>
                        http://fake/redirect
                    </oauth2-provider:redirect-uri>
                </oauth2-provider:redirect-uris>
                <oauth2-provider:authorized-grant-types>
                    <oauth2-provider:authorized-grant-type>
                        AUTHORIZATION_CODE
                    </oauth2-provider:authorized-grant-type>
                </oauth2-provider:authorized-grant-types>
            </oauth2-provider:client>
        </oauth2-provider:clients>
    </oauth2-provider:config>

    <flow name="protected-resource-flow">
        <http:inbound-endpoint host="localhost"
                               port="8081"
                               path="protected"/>
        <oauth2-provider:validate />
        <flow-ref name="additionalLogic"/>
    </flow>

</mule>
```

### [](#mule-4)Mule 4

#### [](#bean-設定)Bean 設定

```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:ss="http://www.springframework.org/schema/security"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-{version}.xsd
       http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-{version}.xsd">

        <ss:authentication-manager id="resourceOwnerAuthenticationManager">
            <ss:authentication-provider>
                <ss:user-service id="resourceOwnerUserService">
                    <ss:user name="rousr"
                             password="ropwd+%"
                             authorities="RESOURCE_OWNER" />
                </ss:user-service>
            </ss:authentication-provider>
        </ss:authentication-manager>

        <ss:authentication-manager id="clientAuthenticationManager">
            <ss:authentication-provider>
                <ss:user-service id="clientUserService">
                    <ss:user name="clusr"
                             password="clpwd+%"
                             authorities="CLIENT" />
                </ss:user-service>
            </ss:authentication-provider>
        </ss:authentication-manager>
</beans>
```

#### [](#共通設定-2)共通設定

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:spring="http://www.mulesoft.org/schema/mule/spring"
      xmlns:os="http://www.mulesoft.org/schema/mule/os"

      xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/spring http://www.mulesoft.org/schema/mule/spring/current/mule-spring.xsd
        http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd">

    <spring:config name="springConfig" files="common-config-beans.xml"/>

    <global-property name="allSupportedGrantTypes" value="AUTHORIZATION_CODE,IMPLICIT,RESOURCE_OWNER_PASSWORD_CREDENTIALS,CLIENT_CREDENTIALS"/>

    <os:object-store name="clientObjectStore"
                     persistent="true"/>
    <os:object-store name="authorizationCodeObjectStore"
                     entryTtl="600"
                     entryTtlUnit="SECONDS"
                     persistent="true"/>
    <os:object-store name="tokenObjectStore"
                     entryTtl="86400"
                     entryTtlUnit="SECONDS"
                     persistent="true"/>

    <spring:security-manager>
        <spring:delegate-security-provider name="clientSecurityProvider"
                                           delegate-ref="clientAuthenticationManager"/>
        <spring:delegate-security-provider name="resourceOwnerSecurityProvider"
                                           delegate-ref="resourceOwnerAuthenticationManager"/>
    </spring:security-manager>

</mule>
```

#### [](#アプリケーション設定-2)アプリケーション設定

```xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:oauth2-provider="http://www.mulesoft.org/schema/mule/oauth2-provider"
      xmlns:http="http://www.mulesoft.org/schema/mule/http"
      xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/oauth2-provider http://www.mulesoft.org/schema/mule/oauth2-provider/current/mule-oauth2-provider.xsd
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

    <http:listener-config name="listenerConfig">
        <http:listener-connection host="localhost"
                                  port="8081"/>
    </http:listener-config>

    <oauth2-provider:config name="OAuth2Provider"
                            providerName="Test OAuth2Provider"
                            resourceOwnerSecurityProvider="resourceOwnerSecurityProvider"
                            clientSecurityProvider="clientSecurityProvider"
                            supportedGrantTypes="${allSupportedGrantTypes}"
                            listenerConfig="listenerConfig"
                            clientStore="clientObjectStore"
                            scopes="GUEST,USER,ADMIN"
                            defaultScopes="USER"
                            supportedGrantTypes="${allSupportedGrantTypes}">
        <oauth2-provider:client-validation-rate-limiter>
            <oauth2-provider:period-rate-limiter/>
        </oauth2-provider:client-validation-rate-limiter>
        <oauth2-provider:token-config path="/token"
                                      tokenStore="tokenObjectStore"
                                      tokenTtl="86400"
                                      tokenTtlTimeUnit="SECONDS">
            <oauth2-provider:refresh-token-strategy>
                <oauth2-provider:multiple-refresh-tokens/>
            </oauth2-provider:refresh-token-strategy>
        </oauth2-provider:token-config>
        <oauth2-provider:authorization-config loginPage="static/auth.html"
                                              path="/authorize"
                                              authorizationCodeStore="authorizationCodeObjectStore"/>
        <oauth2-provider:clients>
            <oauth2-provider:client clientId="clientId1"
                                    secret="clientSecret1"
                                    principal="clusr"
                                    type="CONFIDENTIAL">
                <oauth2-provider:client-redirect-uris>
                    <oauth2-provider:client-redirect-uri>
                        http://fake/redirect
                    </oauth2-provider:client-redirect-uri>
                </oauth2-provider:client-redirect-uris>
                <oauth2-provider:client-authorized-grant-types>
                    <oauth2-provider:client-authorized-grant-type>
                        AUTHORIZATION_CODE
                    </oauth2-provider:client-authorized-grant-type>
                </oauth2-provider:client-authorized-grant-types>
            </oauth2-provider:client>
        </oauth2-provider:clients>
    </oauth2-provider:config>


    <flow name="protected-resource-flow">
        <http:listener path="/protected" config-ref="listenerConfig"/>
        <oauth2-provider:validate-token config-ref="OAuth2Provider"/>
        <flow-ref name="additionalLogic"/>
    </flow>

</mule>
```

## [](#関連情報)関連情報

- [OAuth2 プロバイダードキュメントリファレンス](https://docs.mulesoft.com/jp/oauth2-provider-module/latest/oauth2-provider-module-reference)