35 lines
758 B
Go
35 lines
758 B
Go
|
package initalize
|
||
|
|
||
|
import (
|
||
|
"github.com/go-ldap/ldap/v3"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
func InitLdap(host, bindDN, password string) *ldap.Conn {
|
||
|
// LDAP服务器配置
|
||
|
/*certFile := "/path/to/certificate.crt"
|
||
|
keyFile := "/path/to/certificate.crt"
|
||
|
// 加载证书文件
|
||
|
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
// 配置TLS
|
||
|
tlsConfig := &tls.Config{
|
||
|
InsecureSkipVerify: true, // 忽略证书验证(请谨慎使用)
|
||
|
Certificates: []tls.Certificate{cert},
|
||
|
}*/
|
||
|
// 连接到LDAP服务器
|
||
|
l, err := ldap.DialURL(host /*, ldap.DialWithTLSConfig(tlsConfig)*/)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
// 进行身份认证
|
||
|
err = l.Bind(bindDN, password)
|
||
|
if err != nil {
|
||
|
l.Close()
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
return l
|
||
|
}
|