fix
This commit is contained in:
37
initalize/ldap.go
Normal file
37
initalize/ldap.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package initalize
|
||||
|
||||
import (
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
"log"
|
||||
)
|
||||
|
||||
func InitLdap(host, bindDN, password string) *ldap.Conn {
|
||||
// LDAP服务器配置
|
||||
/*host := "ldap://192.168.1.13:389"
|
||||
bindDN := "cn=root,dc=fusen,dc=com"
|
||||
password := "fusen!@#"*/
|
||||
/*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
|
||||
}
|
||||
Reference in New Issue
Block a user