public class LdapAuthenticationProvider extends AbstractLdapAuthenticationProvider
AuthenticationProvider 実装。LDAP ディレクトリを構成して、このクラスがその責任のほとんどを 2 つの別個の戦略インターフェース LdapAuthenticator と LdapAuthoritiesPopulator に委譲するように構成する方法はたくさんあります。
BindAuthenticator と、LDAP の「比較」操作を使用して提供されたパスワードをディレクトリに格納されている値と比較する PasswordComparisonAuthenticator があります。属性の権限は使用されている認証の型に依存する可能性があるため、ユーザー属性を取得するタスクはオーセンティケーターに委譲されます。たとえば、ユーザーとしてバインドする場合は、ユーザー自身の権限で読み取る必要がある場合があります(バインド操作に使用されるのと同じコンテキストを使用)。
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 を参照してください。
logger, messages, userDetailsContextMapper| コンストラクターと説明 |
|---|
LdapAuthenticationProvider(LdapAuthenticator authenticator) 指定されたオーセンティケーターと null 権限ポピュレーターを使用してインスタンスを作成します。 |
LdapAuthenticationProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator) 提供されたオーセンティケーターとオーソリティポピュレーターの実装でインスタンスを作成します。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected org.springframework.ldap.core.DirContextOperations | doAuthentication(UsernamePasswordAuthenticationToken authentication) |
protected LdapAuthoritiesPopulator | getAuthoritiesPopulator() |
protected java.util.Collection<? extends GrantedAuthority> | loadUserAuthorities(org.springframework.ldap.core.DirContextOperations userData, java.lang.String username, java.lang.String password) |
void | setHideUserNotFoundExceptions(boolean hideUserNotFoundExceptions) |
authenticate, createSuccessfulAuthentication, getUserDetailsContextMapper, setAuthoritiesMapper, setMessageSource, setUseAuthenticationRequestCredentials, setUserDetailsContextMapper, supportspublic LdapAuthenticationProvider(LdapAuthenticator authenticator, LdapAuthoritiesPopulator authoritiesPopulator)
authenticator - このプロバイダーがユーザーを認証するために使用する認証戦略(バインド、パスワード比較など)。authoritiesPopulator - 認証された後、特定のユーザーの権限を取得するための戦略。public LdapAuthenticationProvider(LdapAuthenticator authenticator)
authenticator - オーセンティケーター戦略。protected LdapAuthoritiesPopulator getAuthoritiesPopulator()
public void setHideUserNotFoundExceptions(boolean hideUserNotFoundExceptions)
protected org.springframework.ldap.core.DirContextOperations doAuthentication(UsernamePasswordAuthenticationToken authentication)
AbstractLdapAuthenticationProvider の doAuthentication protected java.util.Collection<? extends GrantedAuthority> loadUserAuthorities(org.springframework.ldap.core.DirContextOperations userData, java.lang.String username, java.lang.String password)