[英]Spring LDAP not working with LDAP template
我正在嘗試使用 spring 連接到 LDAP 服務器
有關 LDAP 服務器的可用信息如下:
這是我的代碼
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
import org.springframework.ldap.core.support.LdapContextSource;
@Configuration
public class LdapConfiguration {
@Bean
public LdapContextSource contextSource() {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://ip:port");
contextSource.setBase("dc=y,dc=z");
return contextSource;
}
@Bean
public LdapTemplate ldapTemplate() {
LdapTemplate template = new LdapTemplate(contextSource());
return template;
}
}
然后在另一個類中是身份驗證方法
@Service
public class LdapUserServiceImpl implements LdapUserService, BaseLdapNameAware {
@Autowired
protected LdapTemplate ldapTemplate;
@Autowired
protected ContextSource contextSource;
@Override
public Boolean authenticate(String userDn, String credentials) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("uid", userDn));
boolean authenticated = ldapTemplate.authenticate(LdapUtils.emptyLdapName(), filter.toString(), credentials);
return authenticated;
}
}
我有以下錯誤:
mmaExceptionHandlerExceptionResolver : 已解決 [org.springframework.ldap.UncategorizedLdapException: LDAP 處理期間發生未分類的異常; 嵌套異常是 javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C090A7D, comment: 為了執行此操作,必須在連接上完成成功的綁定。, data 0, v3839
我的問題是這個錯誤的原因是什么,如果沒有模式被稱為 uid={0} 或者它是標准的,我該怎么辦
另外,我嘗試輸入 ContextSource 初始化用戶名和密碼,盡管我認為它們不可用
contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z");
contextSource.setPassword("password");
這給了我以下錯誤:
[nio-8005-exec-5] .mmaExceptionHandlerExceptionResolver:已解決 [org.springframework.ldap.AuthenticationException:[LDAP:錯誤代碼 49 - 80090308:LdapErr:DSID-0C090453,評論:AcceptSecurityContext 錯誤,數據 52e,v3839
在 application.properties 文件中,我把
spring.ldap.embedded.base-dn=dc=y,dc=z
spring.ldap.embedded.port=port
將 userDn 設置為 username@domainname.com。 contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z");
對我來說,ou=x 看起來是多余的,下面的語句應該使它起作用。 contextSource.setUserDn("uid=username,dc=y,dc=z");
問候阿比
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.