fix(ldap): exiting by peer
exception occurred during the TLS connection(#5977)
This commit is contained in:
parent
c82866975e
commit
9bd3c87bcc
@ -50,31 +50,13 @@ func loginLdap(c *gin.Context, req *LoginReq) {
|
|||||||
ldapUserSearchBase := setting.GetStr(conf.LdapUserSearchBase)
|
ldapUserSearchBase := setting.GetStr(conf.LdapUserSearchBase)
|
||||||
ldapUserSearchFilter := setting.GetStr(conf.LdapUserSearchFilter) // (uid=%s)
|
ldapUserSearchFilter := setting.GetStr(conf.LdapUserSearchFilter) // (uid=%s)
|
||||||
|
|
||||||
var tlsEnabled bool = false
|
// Connect to LdapServer
|
||||||
if strings.HasPrefix(ldapServer, "ldaps://") {
|
l, err := dial(ldapServer)
|
||||||
tlsEnabled = true
|
|
||||||
ldapServer = strings.TrimPrefix(ldapServer, "ldaps://")
|
|
||||||
} else if strings.HasPrefix(ldapServer, "ldap://") {
|
|
||||||
ldapServer = strings.TrimPrefix(ldapServer, "ldap://")
|
|
||||||
}
|
|
||||||
|
|
||||||
l, err := ldap.Dial("tcp", ldapServer)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log.Errorf("failed to connect to LDAP: %v", err)
|
utils.Log.Errorf("failed to connect to LDAP: %v", err)
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer l.Close()
|
|
||||||
|
|
||||||
if tlsEnabled {
|
|
||||||
// Reconnect with TLS
|
|
||||||
err = l.StartTLS(&tls.Config{InsecureSkipVerify: true})
|
|
||||||
if err != nil {
|
|
||||||
utils.Log.Errorf("failed to start tls: %v", err)
|
|
||||||
common.ErrorResp(c, err, 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// First bind with a read only user
|
// First bind with a read only user
|
||||||
if ldapManagerDN != "" && ldapManagerPassword != "" {
|
if ldapManagerDN != "" && ldapManagerPassword != "" {
|
||||||
@ -157,3 +139,19 @@ func ladpRegister(username string) (*model.User, error) {
|
|||||||
}
|
}
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dial(ldapServer string) (*ldap.Conn, error) {
|
||||||
|
var tlsEnabled bool = false
|
||||||
|
if strings.HasPrefix(ldapServer, "ldaps://") {
|
||||||
|
tlsEnabled = true
|
||||||
|
ldapServer = strings.TrimPrefix(ldapServer, "ldaps://")
|
||||||
|
} else if strings.HasPrefix(ldapServer, "ldap://") {
|
||||||
|
ldapServer = strings.TrimPrefix(ldapServer, "ldap://")
|
||||||
|
}
|
||||||
|
|
||||||
|
if tlsEnabled {
|
||||||
|
return ldap.DialTLS("tcp", ldapServer, &tls.Config{InsecureSkipVerify: true})
|
||||||
|
} else {
|
||||||
|
return ldap.Dial("tcp", ldapServer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user