Spring boot Spring安全性-在Spring引导中根据LDAP使用Active Directory对用户进行身份验证

Spring boot Spring安全性-在Spring引导中根据LDAP使用Active Directory对用户进行身份验证,spring-boot,active-directory,ldap,spring-security-ldap,Spring Boot,Active Directory,Ldap,Spring Security Ldap,配置LDAP身份验证时,我发现LDAP身份验证错误。我的属性文件配置如下: ldap.urls=ldap://***.***.local:8389 ldap.base.dn=dc=test,dc=com ldap.user.dn.pattern=(&(objectClass=user)(userPrincipalName={0})(memberof=CN=Group Name,OU=***,OU=****,DC=test,DC=com)) 通过传递有效用户名和密码访问

配置LDAP身份验证时,我发现LDAP身份验证错误。我的属性文件配置如下:

 ldap.urls=ldap://***.***.local:8389
    ldap.base.dn=dc=test,dc=com
    ldap.user.dn.pattern=(&(objectClass=user)(userPrincipalName={0})(memberof=CN=Group Name,OU=***,OU=****,DC=test,DC=com))
通过传递有效用户名和密码访问wsdl时出现以下错误:

在访问wsdl时,它询问用户名和密码。如果我们提供的是“ActiveDirectoryLdapAuthenticationProvider-Active Directory身份验证失败:提供的密码无效

启动应用程序时,我可以在控制台上看到以下内容:

`org.springframework.ldap.core.support.AbstractContextSource - Property 'userDn' not set - anonymous context will be used for read-write operation`
对于SOAP调用,正如我在SOAPWebServiceConfig.java中提供的,甚至不起作用

//XwsSecurityInterceptor
    @Bean
    public XwsSecurityInterceptor securityInterceptor(){
        XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
        //Callback Handler -> SimplePasswordValidationCallbackHandler
        securityInterceptor.setCallbackHandler(callbackHandler());
        //Security Policy -> securityPolicy.xml
        securityInterceptor.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
        return securityInterceptor;
    }

    @Bean
    public SimplePasswordValidationCallbackHandler callbackHandler() {
        SimplePasswordValidationCallbackHandler handler = new SimplePasswordValidationCallbackHandler();
        handler.setUsersMap(Collections.singletonMap("user", "password"));
        return handler;
    }

    //Interceptors.add -> XwsSecurityInterceptor
    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {
        interceptors.add(securityInterceptor());
    }
//XwsSecurityInterceptor
@豆子
public XwsSecurityInterceptor securityInterceptor(){
XwsSecurityInterceptor securityInterceptor=新的XwsSecurityInterceptor();
//回调处理程序->SimplePasswordValidationCallbackHandler
setCallbackHandler(callbackHandler());
//安全策略->securityPolicy.xml
setPolicyConfiguration(新类路径资源(“securityPolicy.xml”);
返回安全拦截器;
}
@豆子
公共SimplePasswordValidationCallbackHandler callbackHandler(){
SimplePasswordValidationCallbackHandler=新SimplePasswordValidationCallbackHandler();
setUsersMap(Collections.singletonMap(“用户”、“密码”));
返回处理程序;
}
//Interceptors.add->XwsSecurityInterceptor
@凌驾
公共void附加侦听器(列表侦听器){
add(securityInterceptor());
}

我不明白这里的问题是什么。有人能就此提出建议吗。

Active Directory有LDAP兼容协议,但与其他LDAP目录相比使用了一些特殊约定。 要使这些配置正确(例如,将域附加到用户名),请使用ActiveDirectoryLdapAuthenticationProvider,而不是通过属性使用自动配置时将使用的LdapAuthenticationProvider。然后从application.yml中删除或重命名“ldap.url”和其他属性

package com.test;

import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider;

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        ActiveDirectoryLdapAuthenticationProvider adProvider = new ActiveDirectoryLdapAuthenticationProvider("domain.org",
                "ldap://activedirectory-url:389");
        adProvider.setConvertSubErrorCodesToExceptions(true);
        adProvider.setUseAuthenticationRequestCredentials(true);
        auth.authenticationProvider(adProvider);
    }

}

但它不适用于SOAP调用。请在这方面帮助我。@tomb尝试省去“(memberof=CN=Group Name,OU=***,OU=***,DC=test,DC=com)”部分,看看是否有帮助。