当前位置: 首页 > 知识库问答 >
问题:

SpringLDAP不使用LDAP模板

柴文林
2023-03-14

我正在尝试使用spring连接到LDAP服务器
有关LDAP服务器的可用信息如下:

  1. 主机/ip
  2. 端口
  3. 域名

这是我的密码

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;
   }
}
      

我有以下错误:

m. m. a. ExceptionHandlerExceptionResolver:已解决的[org.springframework.ldap.未分类的LdapExctive:在LDAP处理过程中发生了未分类的异常;嵌套的异常javax.naming.命名异常:[LDAP:错误代码1-000004DC: LdapErr: DSID-0C090A7D,注释:为了执行此操作,必须在连接上完成成功的绑定。, data 0, v3839

我的问题是这个错误的原因是什么,如果没有被称为uid={0}的模式,或者它是标准的,我该怎么办呢?
此外,我尝试输入ContextSource初始化用户名和密码,尽管我认为它们不可用

  contextSource.setUserDn("uid=username,ou=x,dc=y,dc=z"); 
  contextSource.setPassword("password");

这给了我以下错误:

[nio-8005-exec-5]. m. m. a. ExceptionHandlerExceptionResolver:已解决[org.springframework.ldap.身份验证异常:[LDAP:错误代码49 - 80090308: LdapErr: DSID-0C090453,注释: AcceptSecurityContext错误,数据52e, v3839

在应用程序中。属性文件,我把

spring.ldap.embedded.base-dn=dc=y,dc=z
spring.ldap.embedded.port=port

共有1个答案

西门凯康
2023-03-14

将userDn设置为username@domainname.com.contextSource。setUserDn(“uid=username,ou=x,dc=y,dc=z”) 这里对我来说,ou=x,看起来是额外的,下面的语句应该可以让它工作<代码>上下文源代码。setUserDn(“uid=username,dc=y,dc=z”)

问候阿比

 类似资料:
  • 我有教育问题: 存在具有windows server 2003(AD)的虚拟机,其中包含用户及其密码。已建立与机器的连接(ip:192.168.56.101:389)。 Web应用程序的目的是使用户能够在AD中更改他的密码。 问题:无法配置到windws server 2003的连接。 我从这个教程开始https://spring.io/guides/gs/authenticating-ldap/

  • 我坚持使用spring ldaptemplate身份验证方法返回零计数,同时使用group字符串,下面的字符串。 cn=jirra-acdolite-dg,ou=jira安全组,ou=apps安全组,ou=Security组,ou=global,ou=bt,dc=barcadero,dc=com 如下所示的错误消息。 2018年2月15日12:32:52上午org.springframework.

  • 启用LDAP:true ldap主机名:我的ldap服务器的主机名 LDAP端口:389 LDAP方法:plain ldap基础:我的ldap服务器的基础 LDAP uid:userPrincipalName LDAP绑定DN:Nothing LDAP密码:nothing LDAP筛选器:(&(userprincipalname=%{username})(memberof=cn=[所需组的名称],

  • LDAP 基本概念 https://segmentfault.com/a/1190000002607140 http://www.itdadao.com/articles/c15a1348510p0.html http://blog.csdn.net/reblue520/article/details/51804162 LDAP 服务器端安装 环境:CentOS 7.3 x64(为了方便,已经禁用

  • 我有问题。这是我使用ldap进行身份验证的代码 在Spring,但它有一个错误,告诉我AcceptSecurityContext。 javax.naming.身份验证异常:[LDAP:错误代码49 - 80090308:LdapErr:DSD-0C090400,注释:AcceptSecurityContext错误,数据52e,v1db1] 请帮帮我