クラス LdapAuthenticationProvider
- 実装されているすべてのインターフェース:
org.springframework.beans.factory.Aware、org.springframework.context.MessageSourceAware、AuthenticationProvider
AuthenticationProvider 実装。LDAP ディレクトリを構成して、このクラスがその責任のほとんどを 2 つの別個の戦略インターフェース LdapAuthenticator と LdapAuthoritiesPopulator に委譲するように構成する方法はたくさんあります。
LdapAuthenticator
このインターフェースは、ユーザー認証を実行し、ディレクトリからユーザーの情報を取得するロールを果たします。実装例としては、ユーザーを「バインド」することでユーザーを認証するBindAuthenticator と、LDAP の「比較」操作を使用して提供されたパスワードをディレクトリに格納されている値と比較する PasswordComparisonAuthenticator があります。属性の権限は使用されている認証の型に依存する可能性があるため、ユーザー属性を取得するタスクはオーセンティケーターに委譲されます。たとえば、ユーザーとしてバインドする場合は、ユーザー自身の権限で読み取る必要がある場合があります(バインド操作に使用されるのと同じコンテキストを使用)。
LdapAuthoritiesPopulator
ユーザーが認証されると、このインターフェースが呼び出されて、ユーザーに付与された権限のセットが取得されます。DefaultLdapAuthoritiesPopulator は、ユーザーの属性からユーザーのロール情報を取得したり、ユーザーがメンバーである「グループ」の検索を実行したり、これらをロールにマップしたりするように構成できます。カスタム実装では、データベースなど、まったく異なるソースからロールを取得できます。
構成
簡単な構成は次のようになります。
<bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldap://monkeymachine:389/dc=springframework,dc=org"/>
<property name="userDn" value="cn=manager,dc=springframework,dc=org"/>
<property name="password" value="password"/>
</bean>
<bean id="ldapAuthProvider"
class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<constructor-arg>
<bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
<constructor-arg ref="contextSource"/>
<property name="userDnPatterns"><list><value>uid={0},ou=people</value></list></property>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource"/>
<constructor-arg value="ou=groups"/>
<property name="groupRoleAttribute" value="ou"/>
</bean>
</constructor-arg>
</bean>
これにより、URL ldap://monkeymachine:389/dc=springframework、dc = org で LDAP サーバーにアクセスするようにプロバイダーが設定されます。認証は、DN uid =< user-login-name>、ou = people、dc = springframework、dc = org とのバインドを試みることによって実行されます。認証が成功すると、デフォルトのフィルター(member =< user's-DN>)を使用して DN ou = groups、dc = springframework、dc = org で検索することにより、ロールがユーザーに割り当てられます)。ロール名は、各試合の "ou" 属性から取得されます。
authenticate メソッドは、空のパスワードを完全に拒否します。LDAP サーバーは、DN が指定されている場合でも、空のパスワードを使用した匿名バインド操作を許可する場合があります。実際には、これは、LDAP ディレクトリが認証されていないアクセスを許可するように構成されている場合、空のパスワードを入力するだけで任意のユーザーとして認証できる可能性があることを意味します。認証されていないアクセスの誤用の詳細については、draft-ietf-ldapbis-authmeth-19.txt を参照してください。
フィールドのサマリー
クラス org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider から継承されたフィールド
logger, messages, userDetailsContextMapperコンストラクターの概要
コンストラクターコンストラクター説明LdapAuthenticationProvider(LdapAuthenticator authenticator) 指定されたオーセンティケーターと null 権限ポピュレーターを使用してインスタンスを作成します。LdapAuthenticationProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) 提供されたオーセンティケーターとオーソリティポピュレーターの実装でインスタンスを作成します。メソッドのサマリー
修飾子と型メソッド説明protected org.springframework.ldap.core.DirContextOperationsdoAuthentication(UsernamePasswordAuthenticationToken authentication) protected LdapAuthoritiesPopulatorprotected CollectionSE<? extends GrantedAuthority>loadUserAuthorities(org.springframework.ldap.core.DirContextOperations userData, StringSE username, StringSE password) voidsetHideUserNotFoundExceptions(boolean hideUserNotFoundExceptions) クラス org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider から継承されたメソッド
authenticate, createSuccessfulAuthentication, getUserDetailsContextMapper, setAuthoritiesMapper, setMessageSource, setUseAuthenticationRequestCredentials, setUserDetailsContextMapper, supports
コンストラクターの詳細
LdapAuthenticationProvider
public LdapAuthenticationProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) 提供されたオーセンティケーターとオーソリティポピュレーターの実装でインスタンスを作成します。- パラメーター:
authenticator- このプロバイダーがユーザーを認証するために使用する認証戦略(バインド、パスワード比較など)。authoritiesPopulator- 認証された後、特定のユーザーの権限を取得するための戦略。
LdapAuthenticationProvider
指定されたオーセンティケーターと null 権限ポピュレーターを使用してインスタンスを作成します。この場合、権限はユーザーコンテキストからマップする必要があります。- パラメーター:
authenticator- オーセンティケーター戦略。
メソッドの詳細
getAuthoritiesPopulator
setHideUserNotFoundExceptions
public void setHideUserNotFoundExceptions(boolean hideUserNotFoundExceptions) doAuthentication
protected org.springframework.ldap.core.DirContextOperations doAuthentication(UsernamePasswordAuthenticationToken authentication) - 次で指定:
- クラス
AbstractLdapAuthenticationProviderのdoAuthentication
loadUserAuthorities
protected CollectionSE<? extends GrantedAuthority> loadUserAuthorities(org.springframework.ldap.core.DirContextOperations userData, StringSE username, StringSE password)