簡體   English   中英

Spring 安全 Active Directory 身份驗證 - 無限登錄彈出窗口

[英]Spring Security Active Directory Authentication - infinite login pop-up

我正在使用 Spring 引導(2.7.2)安全。 我的安全配置是:

public class WebSecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().fullyAuthenticated().and().httpBasic();
        return http.build();
    }

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

}

現在,當我點擊我的 URI 時,我不斷收到登錄彈出窗口。

在此處輸入圖像描述

我提供的用戶名和密碼是正確的。 控制台上沒有任何錯誤。

我在這里做錯了什么或錯過了什么?

雖然我仍在等待正確的答案,但我從這里得到了這個想法並且它有效。

所以這就是我最終的結果:

public class WebSecurityConfig extends GlobalAuthenticationConfigurerAdapter {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated()
                // .fullyAuthenticated()
                .and().httpBasic();
        return http.build();
    }

    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
                "ldap://ldap-company.com:389/dc=company,dc=com");
        contextSource.setUserDn("CN=MYBindUser,OU=Ldap,dc=COMPANY,dc=com");
        contextSource.setPassword("ComplexP@ssw0rd");
        contextSource.setReferral("follow");
        contextSource.afterPropertiesSet();

        LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer = auth
                .ldapAuthentication();

        ldapAuthenticationProviderConfigurer
        .userSearchFilter("(&(cn={0}))")
        // .userSearchFilter("(sAMAccountName=%s)")
        .userSearchBase("")
        // .groupSearchBase("(&(objectCategory=group)(cn={0}))")
        .contextSource(contextSource);
    }
    
}

現在我的使用 ActiveDirectory LDAP 的 HTTPBasic 身份驗證工作得很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM