クラス JaasAuthenticationProvider

  • 実装されたすべてのインターフェース:
    java.util.EventListenerorg.springframework.beans.factory.Awareorg.springframework.beans.factory.InitializingBeanorg.springframework.context.ApplicationEventPublisherAwareorg.springframework.context.ApplicationListener<SessionDestroyedEvent>AuthenticationProvider

    public class JaasAuthenticationProvider
    extends AbstractJaasAuthenticationProvider
    JAAS ログイン構成からユーザーの詳細を取得する AuthenticationProvider 実装。

    この AuthenticationProvider は、正しいユーザー名とパスワードを含む UsernamePasswordAuthenticationToken リクエストを検証できます。

    この実装は JAAS 構成によってサポートされています。loginConfig プロパティは、特定の JAAS 構成ファイルに設定する必要があります。この setter は、Spring Resource インスタンスを受け入れます。これは、loginContextName プロパティに一致するインデックスを含む JAAS 構成ファイルを指す必要があります。

    次に例を示します: この JaasAuthenticationProvider が Spring WebApplicationContext で構成されている場合、loginConfiguration を設定するための xml は次のようになります...

     <property name="loginConfig">
       <value>/WEB-INF/login.conf</value>
     </property>
     

    loginContextName は、指定された loginConfig の特定のインデックスと一致する必要があります。JUnit テストで使用される loginConfig ファイルは次のようになります...

     JAASTest {
       org.springframework.security.authentication.jaas.TestLoginModule required;
     };
     
    上記のログイン構成の例を使用すると、loginContextName プロパティは JAASTest として設定されます...
      <property name="loginContextName"> <value>JAASTest</value> </property>
     

    認証ソースとして JAAS ログインモジュールを使用する場合は、時々 LoginContextCallbackHandler 秒が必要になります。JaasAuthenticationProvider は内部 CallbackHandler を使用して、ApplicationContext で構成された JaasAuthenticationCallbackHandler をラップします。LoginContext が内部 CallbackHandler を呼び出すと、渡された各 Callback の各 JaasAuthenticationCallbackHandler に制御が渡されます。

    JaasAuthenticationCallbackHandlercallbackHandlers プロパティを通じて JaasAuthenticationProvider に渡されます。

     <property name="callbackHandlers">
       <list>
         <bean class="org.springframework.security.authentication.jaas.TestCallbackHandler"/>
         <bean class="org.springframework.security.authentication.jaas.JaasNameCallbackHandler"/>
         <bean class="org.springframework.security.authentication.jaas.JaasPasswordCallbackHandler"/>
      </list>
     </property>
     

    LoginContext.login() を呼び出した後、JaasAuthenticationProvider はサブジェクト(LoginContext.getSubject()。getPrincipals)から返されたプリンシパルを取得します。返された各プリンシパルは、構成された AuthorityGranter に渡されます。AuthorityGranter は、返されたプリンシパルとロール名の間のマッピングです。AuthorityGranter が Authorization にロールを付与したい場合は、AuthorityGranter.grant(java.security.Principal) メソッドからそのロール名を返します。返されたロールは、GrantedAuthority として Authorization オブジェクトに適用されます。

    AuthorityGranters は次のように Spring XML で構成されています...

     <property name="authorityGranters">
       <list>
         <bean class="org.springframework.security.authentication.jaas.TestAuthorityGranter"/>
       </list>
      </property>
     
    構成メモ: JaasAuthenticationProvider は、セキュリティプロパティ "login.config.url.X" を使用して jaas を構成します。Jaas の構成方法をカスタマイズする場合は、このサブクラスを作成し、configureJaas(Resource) メソッドをオーバーライドします。
    • フィールドの詳細

      • log

        protected static final org.apache.commons.logging.Log log
    • コンストラクターの詳細

      • JaasAuthenticationProvider

        public JaasAuthenticationProvider()
    • メソッドの詳細

      • createLoginContext

        protected javax.security.auth.login.LoginContext createLoginContext​(javax.security.auth.callback.CallbackHandler handler)
                                                                     throws javax.security.auth.login.LoginException
        クラスからコピーされた説明: AbstractJaasAuthenticationProvider
        認証に使用する LoginContext を作成します。
        次で指定:
        クラス AbstractJaasAuthenticationProvidercreateLoginContext 
        パラメーター:
        handler - LoginContext に使用する必要がある CallbackHandler(非 null)。
        戻り値:
        認証に使用する LoginContext
        例外:
        javax.security.auth.login.LoginException
      • configureJaas

        protected void configureJaas​(org.springframework.core.io.Resource loginConfig)
                              throws java.io.IOException
        Jaas を構成するためのフックメソッド。
        パラメーター:
        loginConfig - Jaas ログイン構成の URL
        例外:
        java.io.IOException - 構成リソースの読み取りに問題がある場合。
      • getLoginConfig

        public org.springframework.core.io.Resource getLoginConfig()
      • setLoginConfig

        public void setLoginConfig​(org.springframework.core.io.Resource loginConfig)
        JAAS ログイン構成ファイルを設定します。
        パラメーター:
        loginConfig -
        関連事項:
        JAAS リファレンス
      • setRefreshConfigurationOnStartup

        public void setRefreshConfigurationOnStartup​(boolean refresh)
        設定されている場合、Configuration#refresh() への呼び出しは #configureJaas(Resource)  メソッドによって行われます。デフォルトは true です。
        パラメーター:
        refresh - false に設定すると、構成の再読み込みが無効になります。一部の環境で役立つ場合があります。
        関連事項:
        SEC-1320