使用gopkg.in/ldap.v2的LDAP身份验证错误:无法读取LDAP响应数据包:意外的EOF

I am new to golang, i been trying to implement ldap authentication using gopkg.in/ldap.v2.

below is the code i using . example from the document : https://godoc.org/gopkg.in/go-ldap/ldap.v2

// The username and password we want to check
username := "someuser"
password := "userpassword"

bindusername := "readonly"
bindpassword := "password"

l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", "ldap.example.com", 389))
if err != nil {
    log.Fatal(err)
}
defer l.Close()

// Reconnect with TLS
err = l.StartTLS(&tls.Config{InsecureSkipVerify: true})
if err != nil {
    log.Fatal(err)
}

// First bind with a read only user
err = l.Bind(bindusername, bindpassword)
if err != nil {
    log.Fatal(err)
}

// Search for the given username
searchRequest := ldap.NewSearchRequest(
    "dc=example,dc=com",
    ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
    fmt.Sprintf("(&(objectClass=organizationalPerson)&(uid=%s))", username),
    []string{"dn"},
    nil,
)

sr, err := l.Search(searchRequest)
if err != nil {
    log.Fatal(err)
}

if len(sr.Entries) != 1 {
    log.Fatal("User does not exist or too many entries returned")
}

userdn := sr.Entries[0].DN

// Bind as the user to verify their password
err = l.Bind(userdn, password)
if err != nil {
    log.Fatal(err)
}

// Rebind as the read only user for any futher queries
err = l.Bind(bindusername, bindpassword)
if err != nil {
    log.Fatal(err)
}

here is the error i am getting at First Bind step: unable to read LDAP response packet: unexpected EOF

I am stuck here. can any one help me here . Thanks

doujiu8145
doujiu8145 您是否找到了解决方案?
大约 3 年之前 回复
doudou5421
doudou5421 可能的话,除非基本通信解决,否则请不要使用TLS。当服务器出于某种原因拒绝TLS连接时,通常会返回此类消息。
接近 4 年之前 回复
duanjia7912
duanjia7912 我将检查日志
接近 4 年之前 回复
dqmq0654
dqmq0654 服务器关闭了连接,而不是响应。您可以检查服务器日志以了解原因吗?
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问