首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring LDAP不使用LDAP模板

Spring LDAP不使用LDAP模板
EN

Stack Overflow用户
提问于 2020-09-02 14:27:44
回答 1查看 2.7K关注 0票数 0

我正在尝试使用spring连接到LDAP服务器。

有关LDAP服务器的可用信息如下:

  1. host/ip
  2. port
  3. domain => ou=x,dc=y,dc=z

对于与用户名匹配的uid = {0}或cn = {0}等过滤方法,我没有任何信息。

这是我的密码

代码语言:javascript
复制
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;
    }
}

然后在另一个类中,这里是身份验证方法。

代码语言:javascript
复制
@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;
   }
}

我有以下错误:

LDAP处理过程中发生的[org.springframework.ldap.UncategorizedLdapException:未分类异常;嵌套异常为javax.naming.NamingException:[LDAP:错误代码1- 000004DC: LdapErr: DSID-0C090A7D,注释:为了执行此操作,必须在连接.、数据0、v3839上完成成功的绑定“。

我的问题是,这个错误的原因是什么?如果没有一个模式被称为uid={0}或它是标准的,我还能做什么?

此外,我还试图输入ContextSource初始化用户名和密码,尽管我认为它们是不可用的。

代码语言:javascript
复制
  contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z"); 
  contextSource.setPassword("password");

这给了我以下错误:

已解决的[org.springframework.ldap.AuthenticationException:[LDAP:错误代码49 - 80090308: LdapErr: DSID-0C090453,注释: AcceptSecurityContext错误,数据52e,v3839

在application.properties文件中,我将

代码语言:javascript
复制
spring.ldap.embedded.base-dn=dc=y,dc=z
spring.ldap.embedded.port=port
EN

回答 1

Stack Overflow用户

发布于 2020-09-09 17:11:14

将userDn设置为username@domainname.com。在我看来,contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z");,ou=x,看起来是额外的,下面的语句应该能让它工作。contextSource.setUserDn("uid=username,dc=y,dc=z");

问候阿比

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63707703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档