トラスト・アソシエーション・インターセプター

improve this page | report issue

概説

IBM Mobile Foundation は、IBM WebSphere のトラスト・アソシエーション・インターセプター経由で行われる外部リソースの認証を容易にするための Java ライブラリーを提供します。

Java ライブラリーは、JAR ファイル (com.ibm.mfp.oauth.tai-8.0.0.jar) として提供されます。

このチュートリアルでは、スコープ (accessRestricted) を使用して、単純な Java サーブレット TAI/GetBalance を保護する方法を示します。

前提条件:

フロー

サーバーのセットアップ

  1. セキュリティー・ツールの .zip を MobileFirst Operations Console →「ダウンロード・センター」→「ツール」タブからダウンロードします。 そこに、mfp-oauth-tai.zip アーカイブが含まれています。 この zip を解凍します。
  2. com.ibm.mfp.oauth.tai.jar ファイルを WebSphere Application Server インスタンスの usr/extension/lib 内に追加します。
  3. OAuthTai.mf ファイルを WebSphere Application Server インスタンスの usr/extension/lib/features 内に追加します。

web.xml のセットアップ

セキュリティー制約とセキュリティー・ロールを WebSphere Application Server インスタンスの web.xml ファイルに追加します。

<security-constraint>
   <web-resource-collection>
      <web-resource-name>TrustAssociationInterceptor</web-resource-name>
      <url-pattern>/TAI/GetBalance</url-pattern>
   </web-resource-collection>
   <auth-constraint>
      <role-name>TAIUserRole</role-name>
   </auth-constraint>
</security-constraint>

<security-role id="SecurityRole_TAIUserRole">
   <description>This is the role that Mobile Foundation OAuthTAI uses to protect the resource, and it is mandatory to map it to 'All Authenticated in Application' in WebSphere Application Server full profile and to 'ALL_AUTHENTICATED_USERS' in WebSphere Application Server Liberty.</description>
   <role-name>TAIUserRole</role-name>
</security-role>

server.xml

外部リソースについて WebSphere Application Server server.xml ファイルを変更します。

  • 以下の機能を組み込むように、機能マネージャーを構成します。

    <featureManager>
             <feature>jsp-2.2</feature>
             <feature>appSecurity-2.0</feature>
             <feature>usr:OAuthTai-8.0</feature>
             <feature>servlet-3.0</feature>
             <feature>jndi-1.0</feature>
    </featureManager>
    
  • セキュリティー・ロールをクラス・アノテーションとして Java サーブレットに追加します。

@ServletSecurity(@HttpConstraint(rolesAllowed = "TAIUserRole"))

servlet-2.x を使用する場合は、セキュリティー・ロールを web.xml ファイル内に定義する必要があります。

<application contextRoot="TAI" id="TrustAssociationInterceptor" location="TAI.war" name="TrustAssociationInterceptor"/>
   <application-bnd>
      <security-role name="TAIUserRole">
         <special-subject type="ALL_AUTHENTICATED_USERS"/>
      </security-role>
   </application-bnd>
</application>
  • OAuthTAI を構成します。 ここで、URL を保護対象として設定します。

    <usr_OAuthTAI id="myOAuthTAI" authorizationURL="http://localhost:9080/mfp/api" clientId="ExternalResourceId" clientSecret="ExternalResourcePass" cacheSize="500">
              <securityConstraint httpMethods="GET POST" scope="accessRestricted" securedURLs="/GetBalance"></securityConstraint>
    </usr_OAuthTAI>
    
    • authorizationURL: MobileFirst Server (http(s):/your-hostname:port/runtime-name/api) または外部 AZ サーバー (IBM DataPower など) のいずれかです。

    • clientID: リソース・サーバーは、登録済みの機密クライアントでなければなりません。 機密クライアントを登録する方法については、機密クライアントのチュートリアルを参照してください。 トークンを検証できるようにするために、機密クライアントには、許可されるスコープとして authorization.introspect必須 です。

    • clientSecret: リソース・サーバーは、登録済みの機密クライアントでなければなりません。 機密クライアントを登録する方法については、機密クライアントのチュートリアルを参照してください。
    • cacheSize (オプション): TAI は、Java-Token-Validator キャッシュを使用して、トークンおよびイントロスペクション・データの値をキャッシュに入れることで、短い時間内であれば、クライアントから要求内で渡されるトークンを再度イントロスペクトせずに済むようにします。

      デフォルト・サイズは 50,000 個分のトークンです。

      すべての要求でトークンがイントロスペクトされることを保証する必要がある場合、キャッシュの値を 0 に設定してください。

    • scope: リソース・サーバーは 1 つ以上のスコープを基準にして認証します。 スコープは、セキュリティー検査にすることも、セキュリティー検査にマップされるスコープ・エレメントにすることもできます。

TAI から入手するトークン・イントロスペクション・データの使用

TAI によってインターセプトされ、検証されたトークン情報にリソースからアクセスできます。 トークンに関して検出できるデータのリストについては、API リファレンスを参照してください。 このデータを取得するには、WSSubject API を使用します。

Map<String, String> credentials = WSSubject.getCallerSubject().getPublicCredentials(Hashtable.class).iterator().next();
JSONObject securityContext = new JSONObject(credentials.get("securityContext"));
...
securityContext.get('mfp-device')

サンプル・アプリケーション

サポートされるアプリケーション・サーバー (WebSphere Application Server フル・プロファイルおよび WebSphere Application Server Liberty プロファイル) にプロジェクトをデプロイできます。
単純な Java サーブレットをダウンロードします。

サンプルの使用法

  1. MobileFirst Operations Console で、必ず機密クライアントと秘密鍵の値を更新してください。
  2. UserLogin または PinCodeAttempts のいずれかのセキュリティー検査をデプロイします。
  3. 一致するアプリケーションを登録します。
  4. accessRestricted スコープをセキュリティー検査にマップします。
  5. クライアント・アプリケーションを更新して、サーブレット URL に WLResourceRequest を発行します。
  6. securityConstraint スコープを、クライアントが認証を受けるときに基準として必要なセキュリティー検査になるように設定します。
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on February 28, 2020