1

こんにちは私はLdapで簡単なログインを作成する際に問題があります。私はspring.ioのWebサイトからプロジェクトを始めてダウンロードしました:linkこれはldifファイルと完全に連携していますが、ldapサーバーを実行しているものと置き換えたいと思います。私は何の進歩もなくそれを試しました。私は私が形式で良いユーザ名とパスワードでログインしようとした場合、「ユーザー名」(プロジェクトを開始したばかりのWebSecurityConfigに置き換え)コードのこの作品春のブートldapセキュリティ

@Configuration 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

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

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

    @Bean 
    public AuthenticationManager authenticationManager() { 
     return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider())); 
    } 
    @Bean 
    public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() { 
     ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(null, "ldap://ip:port/", "ou=GROUP,dc=domain,dc=com"); 
     provider.setConvertSubErrorCodesToExceptions(true); 
     provider.setUseAuthenticationRequestCredentials(true); 

     return provider; 
    } 
} 

で最高の結果を得る「パスワード」コンソール出力:ActiveDirectoryLdapAuthenticationProvider:Active Directoryの認証に失敗しました:提供されたパスワードが無効です

"[email protected]"と良いパスワードを使用すると、ページはコンソールに出力されずにリロードされます。

私は、ランダムなユーザ名とパスワードのコンソールを使用する場合:指定されたパスワードは

無効でした誰かが助けることができます:Active Directory認証に失敗しましたか?

+0

あなたがActiveDirectoryLdapAuthenticationProviderのコンストラクタでドメインの「ヌル」を使用するように、あなたが を認証するために「のuserPrincipalName」([email protected])を使用する必要がありますが、これは動作しない理由を見つけるためにログをオンにしたり、 LDAPSまたはStartTLS拡張操作を使用しない場合、ネットワークトレースはLDAP BIND要求が成功したかどうかを確認します –

答えて

0

コメントに示唆されているとおり、私はロギングを有効にしていて、問題は "[email protected]"でも同じであることがわかりました。

問題はaciveDirectoryLdapAuthenticationProvider()に3つありました。

  1. 私はROOTDNからOUのグループを削除し、我々だけでログインするためのユーザー名を使用することができますので、ドメインを追加した。

    ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("domain.com", "ldap://ip:port/", "dc=domain,dc=com"); 
    
  2. provider.setSearchFilter("(&(objectClass=user)(sAMAccountName={0}))"); 
    
  3. 、最終的に私のプロバイダのsearchfilterを変更しました"[email protected]"と "username"のsAMAccountName isteadが一致していたため、ActiveDirectoryLdapAuthProvider searchForUserメソッドを変更する必要がありました。この:

    これで置き換え
    return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context, 
           searchControls, searchRoot, searchFilter, 
           new Object[] { bindPrincipal });  
    

    return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context, 
          searchControls, searchRoot, searchFilter, 
          new Object[] { username }); 
    

コンプリートaciveDirectoryLdapAuthenticationProvider():

@Bean 
    public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() { 
     ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("domain.com", "ldap://ip:port/", "dc=domain,dc=com"); 
     provider.setSearchFilter("(&(objectClass=user)(sAMAccountName={0}))"); 
     provider.setConvertSubErrorCodesToExceptions(true); 
     provider.setUseAuthenticationRequestCredentials(true); 
     return provider; 
    } 

誰かが第三/第二の問題のためのよりよい解決策を提供することはできますか?たぶん、より良い検索フィルタですか?私はActiveDirectoryLdapAuthProviderを使っているbindPrincipalの "[email protected]"フォーマットと一致するldapのフィールドを持っていません。

+0

こんにちは@ user3551808、どうやってログ記録を有効にしましたか教えてください。私は似たようなエラーがあり、より多くのログを見たいと思っていますが、起こっていないようです。私はlogback.xmlを使用していて、logback.xmlの始めにこのエントリを作成しました: 'debug = "true"助けてくれていないようだった。 –

関連する問題