feat: Casdoor's LDAP client supports LDAP server's self-signed certificates now (#3709)

This commit is contained in:
DacongDA
2025-04-07 02:02:32 +08:00
committed by GitHub
parent 952538916d
commit f04a431d85
3 changed files with 28 additions and 13 deletions

View File

@ -16,6 +16,7 @@ package object
import (
"crypto/md5"
"crypto/tls"
"encoding/base64"
"errors"
"fmt"
@ -64,8 +65,11 @@ type LdapUser struct {
func (ldap *Ldap) GetLdapConn() (c *LdapConn, err error) {
var conn *goldap.Conn
tlsConfig := tls.Config{
InsecureSkipVerify: ldap.AllowSelfSignedCert,
}
if ldap.EnableSsl {
conn, err = goldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldap.Host, ldap.Port), nil)
conn, err = goldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldap.Host, ldap.Port), &tlsConfig)
} else {
conn, err = goldap.Dial("tcp", fmt.Sprintf("%s:%d", ldap.Host, ldap.Port))
}