2017-11-17 32 views
0

私の会社にはActive Directoryが設定されています。私はログインシステムをそのADにリンクする必要があるアプリケーションを作っているので、Spring LDAP認証を実装するように設定しました。LDAP検索でエントリが見つかりません

しかし、私はアプリケーションにログインしようとすると、私は

Failed to locate directory entry for authenticated user: my.name 

javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100213, problem 2001 (NO_OBJECT), data 0, best match of: 
'DC=dev,DC=company,DC=corp' 

私の春のセキュリティコードを取得するには、次のようになります。

@Configuration 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 


    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .authorizeRequests() 
       .anyRequest().fullyAuthenticated() 
       .and() 
       .formLogin(); 
    } 


    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception{ 
     auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailsService()); 
    } 

    @Bean 
    public AuthenticationManager authenticationManager() { 
     return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider())); 
    } 

    @Bean 
    public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() { 
     ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("company.hr", "ldap://10.23.1.1:389/dc=dev,dc=company,dc=corp"); 
     provider.setConvertSubErrorCodesToExceptions(true); 
     provider.setUseAuthenticationRequestCredentials(true); 

     return provider; 
    } 
} 

問題の一つは、私たちのAD構造が実際にあるということですこれらの組織単位のそれぞれはさらに細分しています:

AD tree structure

LDAPで読み上げると、共通の親フォルダへのパスのみをツリーを介して再帰的に検索し、一致するユーザーを検索する必要がありました。OUが何であっても、実際にはdsqueryコマンドからどこにいるかに関係なく、照会されたユーザーを返すかどうかを確認するプロンプトが表示されます。しかし、それは春には起こりません。私は話題を見つけ出し、何時間もデバッグしたことをすべて読んだことがありますが、パラメータが正しく設定されているようですが、まだ例外がスローされます。

私の質問は、(特定のユーザーに数十もの異なるOUがあるため)その特定のユーザーの完全なURLを指定せずに、ユーザーが実際にActive Directoryにいることを確認する方法です。

+0

パラメータを正しく取得するには、JXplorer内で検索を実行します。使用している検索のパラメータと値は指定しないでください。 my.nameを探しているようです。 dsquery user -samid my.nameを試してみてください – jwilleke

答えて

0

解決策が見つかりました。場合によっては、X回目のドキュメンテーションを読み返すことが実際に役立ちます。

私はconstrcutorで三番目のパラメータは、実際には「ROOTDN」であるので、それがどこにあるべき場所です。この

ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("company.hr", "ldap://10.23.1.1:389", "dc=dev,dc=company,dc=corp"); 

にこの

@Bean 
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() { 
    ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("company.hr", "ldap://10.23.1.1:389/dc=dev,dc=company,dc=corp"); 
    provider.setConvertSubErrorCodesToExceptions(true); 
    provider.setUseAuthenticationRequestCredentials(true); 

    return provider; 
} 

からActiveDirectoryLdapAuthenticationProviderのコンストラクタ呼び出しを変更URLの拡張子ではなく、渡されます。

関連する問題