Spring セキュリティを使用したコンポーネントの認証

このバージョンの Mule は、拡張サポートが終了する 2023 年 5 月 2 日にその すべてのサポート​が終了しました。

このバージョンの Mule を使用する CloudHub には新しいアプリケーションをデプロイできなくなります。許可されるのはアプリケーションへのインプレース更新のみになります。

標準サポートが適用されている最新バージョンの Mule 4 にアップグレード​することをお勧めします。これにより、最新の修正とセキュリティ機能強化を備えたアプリケーションが実行されます。

ユーザが呼び出せるメソッドをロールごとに限定するために、Spring セキュリティ機能を使用した認証を Mule コンポーネントで設定する方法を学習します。

Spring セキュリティ認証マネージャの設定

Spring セキュリティインターフェース認証マネージャは、認証プロバイダオブジェクトのチェーン内での要求の受け渡しを管理します。フローコンポーネントへのコールでセキュリティを確保するには、設定済みの ​authenticationManager​ をアプリケーションコンテキストに追加する必要があります。

次の例では、保護されているプロセッサへのアクセスレベルが異なるロールを定義しています。

  <ss:authentication-manager alias="authenticationManager">
    <ss:authentication-provider>
      <ss:user-service id="userService">
        <ss:user name="admin" password="admin" authorities="ROLE_ADMIN" />
        <ss:user name="joe" password="secret" authorities="ROLE_ADMIN" />
        <ss:user name="anon" password="anon" authorities="ROLE_ANON" />
        <ss:user name="user" password="password" authorities="ROLE_ANON" />
        <ss:user name="ross" password="ross" authorities="ROLE_ANON" />
        <ss:user name="marie" password="marie" authorities="ROLE_ANON" />
      </ss:user-service>
    </ss:authentication-provider>
  </ss:authentication-manager>

次の例は、定義されている ​authenticationManager​ を参照して、​requiredAuthorities​ 項目で ​ROLE_ADMIN​ ロールを持つユーザのみが操作にアクセスできるようにしています。

	<spring:security-manager>
		<spring:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" />
	</spring:security-manager>

	<flow name="protectedFlow">
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/" />
		<http:basic-security-filter doc:name="Basic security filter" realm="mule" />
		<spring:authorization-filter requiredAuthorities="ROLE_ADMIN" />

		<ee:transform doc:name="Transform Message">
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
				output application/json
				---
				{
					"status": "ok"
				}]]>
				</ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>

非同期システムでのセキュアコンポーネントの設定

複数のスレッドで認証を設定するためには、セキュリティプロバイダにセキュリティプロパティを追加する必要があるため、非同期システムでは Spring セキュリティが便利です。 次の例では、​MODE_GLOBAL​ が追加されたセキュリティプロパティです。

    <mule-ss:security-manager>
        <mule-ss:delegate-security-provider name="memory-dao" delegate-ref="authenticationManager">
            <mule-ss:security-property name="securityMode" value="MODE_GLOBAL"/>
        </mule-ss:delegate-security-provider>
    </mule-ss:security-manager>