第7章 認証
次の例では、セキュリティドメインでアプリケーションポリシーを使用できる方法を説明します。
明確にするために、例では認証ポリシーだけが宣言されています。ただし、同じ <application-policy> に <authorization> と <mapping> 要素を含めることができます。<authentication> 要素に関する詳細は 「<authentication>」 を参照してください。
例7.1 シングルログインスタックの認証ポリシー
この例では、シングルログインモジュール
UsersRolesLoginModule
( 「UsersRolesLoginModule」 を参照) を使用する jmx-console
という名前のシンプルなセキュリティドメイン設定について説明します。
ログインモジュールは
jboss-as/server/$PROFILE/conf/props
ディレクトリのファイルからのユーザーとロールのプロパティにより提供されます。
この例では、<login-module> は成功する必要があります。そうでない場合は、認証は失敗します。
<application-policy xmlns="urn:jboss:security-beans:1.0 name="jmx-console"> <authentication> <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required"> <module-option name="usersProperties">props/jmx-console-users.properties</module-option> <module-option name="rolesProperties">props/jmx-console-roles.properties</module-option> </login-module> </authentication> </application-policy>
例7.2 複数のログインスタックの認証ポリシー
この例では、認証ログインモジュールスタックで 2 つのログインモジュールを使用する
web-console
という名前のセキュリティドメイン設定について説明します。
ある <login-module> は
LdapLoginModule
(「LdapLoginModule」 を参照) を使用してログイン資格情報を取得します。一方で、別の <login-module> は BaseCertLoginModule
(「BaseCertLoginModule」 を参照) を使用して認証資格情報を取得します。
この例では、両方のモジュールとも sufficient であるとマークされているため、認証が成功するためにはどちらか一方のみ成功する必要があります。
<application-policy xmlns="urn:jboss:security-beans:1.0 name="web-console"> <authentication> <!-- LDAP configuration --> <login-module code="org.jboss.security.auth.spi.LdapLoginModule" flag="sufficient" /> <!-- database configuration --> <login-module code="org.jboss.security.auth.spi.BaseCertLoginModule" flag="sufficient" /> </authentication> </application-policy>
7.1. カスタムコールバックハンドラ
認証手順にコールバックハンドラを実装することにより、ログインモジュールがクライアントアプリケーションの認証メソッドに依存することなくユーザーを認証できます。
次のメソッドを使用してコールバックハンドラを実装できます。
conf/jboss-service.xml
JaasSecurityManagerService MBean 定義で CallbackHandlerClassName 属性を指定します。deploy/security/security-jboss-beans.xml
JNDISecurityManagement Bean にコールバックハンドラのインスタンスをインジェクトします。
手順7.1 属性を使用したコールバックハンドラの設定
これは
jboss-service.xml
設定ファイルでコールバックハンドラを指定する手順を示しています。
設定ファイルを開きます
$JBOSS_HOME/server/$PROFILE/conf/
に移動します。jboss-service.xml
ファイルを開きます。デフォルトでjboss-service.xml
ファイルには 例7.3「jboss-service デフォルト設定」 の設定が含まれています。例7.3 jboss-service デフォルト設定
<?xml version="1.0" encoding="UTF-8"?> ... <!-- ==================================================================== --> <!-- Security --> <!-- ==================================================================== --> <!-- JAAS security manager and realm mapping --> <mbean code="org.jboss.security.plugins.JaasSecurityManagerService" name="jboss.security:service=JaasSecurityManager"> <!-- A flag which indicates whether the SecurityAssociation server mode is set on service creation. This is true by default since the SecurityAssociation should be thread local for multi-threaded server operation.--> <attribute name="ServerMode">true</attribute> <attribute name="SecurityManagerClassName">org.jboss.security.plugins.JaasSecurityManager</attribute> <attribute name="DefaultUnauthenticatedPrincipal">anonymous</attribute> <!-- DefaultCacheTimeout: Specifies the default timed cache policy timeout in seconds. If you want to disable caching of security credentials, set this to 0 to force authentication to occur every time. This has no affect if the AuthenticationCacheJndiName has been changed from the default value.--> <attribute name="DefaultCacheTimeout">1800</attribute> <!-- DefaultCacheResolution: Specifies the default timed cache policy resolution in seconds. This controls the interval at which the cache current timestamp is updated and should be less than the DefaultCacheTimeout in order for the timeout to be meaningful. This has no affect if the AuthenticationCacheJndiName has been changed from the default value.--> <attribute name="DefaultCacheResolution">60</attribute> <!-- DeepCopySubjectMode: This set the copy mode of subjects done by the security managers to be deep copies that makes copies of the subject principals and credentials if they are cloneable. It should be set to true if subject include mutable content that can be corrupted when multiple threads have the same identity and cache flushes/logout clearing the subject in one thread results in subject references affecting other threads.--> <attribute name="DeepCopySubjectMode">false</attribute> </mbean> ...
属性を追加します
カスタムコールバックハンドラを設定するには、<attribute> 要素を <mbean> 要素の子として追加し、コールバックハンドラの完全修飾名を指定します。コールバックハンドラが指定された例の <attribute> 要素については、例7.4「コールバックハンドラを追加した jboss-service」 を参照してください。例7.4 コールバックハンドラを追加した jboss-service
<?xml version="1.0" encoding="UTF-8"?> ... <!-- ==================================================================== --> <!-- Security --> <!-- ==================================================================== --> <!-- JAAS security manager and realm mapping --> <mbean code="org.jboss.security.plugins.JaasSecurityManagerService" name="jboss.security:service=JaasSecurityManager"> <!-- A flag which indicates whether the SecurityAssociation server mode is set on service creation. This is true by default since the SecurityAssociation should be thread local for multi-threaded server operation.--> <attribute name="ServerMode">true</attribute> <attribute name="SecurityManagerClassName">org.jboss.security.plugins.JaasSecurityManager</attribute> <attribute name="DefaultUnauthenticatedPrincipal">anonymous</attribute> <!-- DefaultCacheTimeout: Specifies the default timed cache policy timeout in seconds. If you want to disable caching of security credentials, set this to 0 to force authentication to occur every time. This has no affect if the AuthenticationCacheJndiName has been changed from the default value.--> <attribute name="DefaultCacheTimeout">1800</attribute> <!-- DefaultCacheResolution: Specifies the default timed cache policy resolution in seconds. This controls the interval at which the cache current timestamp is updated and should be less than the DefaultCacheTimeout in order for the timeout to be meaningful. This has no affect if the AuthenticationCacheJndiName has been changed from the default value.--> <attribute name="DefaultCacheResolution">60</attribute> <!-- DeepCopySubjectMode: This set the copy mode of subjects done by the security managers to be deep copies that makes copies of the subject principals and credentials if they are cloneable. It should be set to true if subject include mutable content that can be corrupted when multiple threads have the same identity and cache flushes/logout clearing the subject in one thread results in subject references affecting other threads.--> <attribute name="DeepCopySubjectMode">false</attribute> <attribute name="CallbackHandlerClassName">org.jboss.security.plugins.[Custom_Callback_Handler_Name]</attribute> </mbean> ...
サーバーを再起動します
これでjboss-service.xml
ファイルを設定し、カスタムコールバックハンドラを使用できるようになりました。サーバーを再起動して、新しいセキュリティポリシーが有効であることを確認してください。
手順7.2 インジェクションを使用したセキュリティコールバックハンドラの設定
これは JNDISecurityManagement Bean にセキュリティコールバックハンドラのインスタンスをインジェクトする方法を示した手順です。
カスタムコールバックのインスタンスを作成します
カスタムコールバックハンドラのインスタンスを作成し、登録する必要があります。設定ファイルを開きます
$JBOSS_HOME/server/$PROFILE/deploy/security/
に移動します。security-jboss-beans.xml
ファイルを開きます。デフォルトでsecurity-jboss-beans.xml
ファイルには 例7.5「security-jboss-beans デフォルト設定」 の JNDIBasedSecurityManagement Bean 設定が含まれています。例7.5 security-jboss-beans デフォルト設定
<!-- JNDI Based Security Management --> <bean name="JBossSecuritySubjectFactory" class="org.jboss.security.integration.JBossSecuritySubjectFactory" />
インジェクションのプロパティを追加します
コールバックハンドラをインジェクトするには、<property> 要素を JNDIBasedSecurityManagement <mbean> 要素の子として追加します。例7.4「コールバックハンドラを追加した jboss-service」 に説明された <property> と <inject> 要素を使用してコールバックハンドラを指定します。例7.6 security-jboss-beans コールバックハンドラ
<bean name="JBossSecuritySubjectFactory" class="org.jboss.security.integration.JBossSecuritySubjectFactory"> <property name="securityManagement"> <inject bean="JNDIBasedSecurityManagement" /> </property> </bean>
サーバーを再起動します
これでsecurity-jboss-beans.xml
ファイルを設定し、カスタムコールバックハンドラをインジェクトできるようになりました。サーバーを再起動して、新しいセキュリティポリシーが有効であることを確認してください。