ldap login support anonymous search mode
This commit is contained in:
parent
7c86e8f58e
commit
a5be668359
|
@ -45,16 +45,17 @@ func ldapReq(user, pass string) (*ldap.SearchResult, error) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
if !lc.TLS && lc.StartTLS {
|
if !lc.TLS && lc.StartTLS {
|
||||||
err = conn.StartTLS(&tls.Config{InsecureSkipVerify: true})
|
if err := conn.StartTLS(&tls.Config{InsecureSkipVerify: true}); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("ldap.conn startTLS fail: %v", err)
|
return nil, fmt.Errorf("ldap.conn startTLS fail: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//if bindUser is empty, anonymousSearch mode
|
||||||
err = conn.Bind(lc.BindUser, lc.BindPass)
|
if lc.BindUser != "" {
|
||||||
if err != nil {
|
//BindSearch mode
|
||||||
|
if err := conn.Bind(lc.BindUser, lc.BindPass); err != nil {
|
||||||
return nil, fmt.Errorf("bind ldap fail: %v, use %s", err, lc.BindUser)
|
return nil, fmt.Errorf("bind ldap fail: %v, use %s", err, lc.BindUser)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
searchRequest := ldap.NewSearchRequest(
|
searchRequest := ldap.NewSearchRequest(
|
||||||
lc.BaseDn, // The base dn to search
|
lc.BaseDn, // The base dn to search
|
||||||
|
|
Loading…
Reference in New Issue