クラス JaasAuthenticationProvider
- java.lang.Object
-
- org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider
-
- org.springframework.security.authentication.jaas.JaasAuthenticationProvider
- 実装されているすべてのインターフェース:
java.util.EventListener
、org.springframework.beans.factory.Aware
、org.springframework.beans.factory.InitializingBean
、org.springframework.context.ApplicationEventPublisherAware
、org.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 ログインモジュールを使用する場合は、時々 LoginContext は CallbackHandler 秒が必要になります。JaasAuthenticationProvider は内部 CallbackHandler を使用して、ApplicationContext で構成された
JaasAuthenticationCallbackHandler
をラップします。LoginContext が内部 CallbackHandler を呼び出すと、渡された各 Callback の各JaasAuthenticationCallbackHandler
に制御が渡されます。JaasAuthenticationCallbackHandler
はcallbackHandlers
プロパティを通じて 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)
メソッドをオーバーライドします。
フィールドのサマリー
フィールド 修飾子と型 フィールド 説明 protected static org.apache.commons.logging.Log
log
コンストラクターの概要
コンストラクター コンストラクター 説明 JaasAuthenticationProvider()
メソッドのサマリー
すべてのメソッド インスタンスメソッド 具象メソッド 修飾子と型 メソッド 説明 void
afterPropertiesSet()
必要なプロパティが設定されていることを検証します。protected void
configureJaas(org.springframework.core.io.Resource loginConfig)
Jaas を構成するためのフックメソッド。protected javax.security.auth.login.LoginContext
createLoginContext(javax.security.auth.callback.CallbackHandler handler)
認証に使用する LoginContext を作成します。org.springframework.core.io.Resource
getLoginConfig()
protected void
publishFailureEvent(UsernamePasswordAuthenticationToken token, AuthenticationException ase)
JaasAuthenticationFailedEvent
を公開します。void
setLoginConfig(org.springframework.core.io.Resource loginConfig)
JAAS ログイン構成ファイルを設定します。void
setRefreshConfigurationOnStartup(boolean refresh)
設定されている場合、Configuration#refresh()
への呼び出しは#configureJaas(Resource)
メソッドによって行われます。クラス org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider から継承されたメソッド
authenticate, getApplicationEventPublisher, handleLogout, onApplicationEvent, publishSuccessEvent, setApplicationEventPublisher, setAuthorityGranters, setCallbackHandlers, setLoginContextName, setLoginExceptionResolver, supports
メソッドの詳細
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
クラスからコピーされた説明:AbstractJaasAuthenticationProvider
必要なプロパティが設定されていることを検証します。さらに、AbstractJaasAuthenticationProvider.setCallbackHandlers(JaasAuthenticationCallbackHandler[])
が有効なハンドラーで呼び出されていない場合は、JaasNameCallbackHandler
およびJaasPasswordCallbackHandler
を使用するように初期化します。- 次で指定:
- インターフェース
org.springframework.beans.factory.InitializingBean
のafterPropertiesSet
- オーバーライド:
- クラス
AbstractJaasAuthenticationProvider
のafterPropertiesSet
- 例外:
java.lang.Exception
createLoginContext
protected javax.security.auth.login.LoginContext createLoginContext(javax.security.auth.callback.CallbackHandler handler) throws javax.security.auth.login.LoginException
クラスからコピーされた説明:AbstractJaasAuthenticationProvider
認証に使用する LoginContext を作成します。- 次で指定:
- クラス
AbstractJaasAuthenticationProvider
のcreateLoginContext
- パラメーター:
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
- 構成リソースの読み取りに問題がある場合。
publishFailureEvent
protected void publishFailureEvent(UsernamePasswordAuthenticationToken token, AuthenticationException ase)
JaasAuthenticationFailedEvent
を公開します。さまざまな機能のサブクラスによってオーバーライドできます- オーバーライド:
- クラス
AbstractJaasAuthenticationProvider
のpublishFailureEvent
- パラメーター:
token
- 処理中の認証トークンase
- 認証失敗の原因となった例外
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