From 12847f90d10df93529b3999f4deb1e740a20bedc Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Fri, 24 Mar 2017 18:00:21 +0800 Subject: [PATCH] if password is not provided read it from config when calling ping ldap API --- src/ui/api/ldap.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ui/api/ldap.go b/src/ui/api/ldap.go index 6fa8bd4ec..f1af1b14e 100644 --- a/src/ui/api/ldap.go +++ b/src/ui/api/ldap.go @@ -16,6 +16,7 @@ package api import ( + "encoding/json" "fmt" "net/http" "strings" @@ -65,6 +66,22 @@ func (l *LdapAPI) Ping() { } } else { l.DecodeJSONReqAndValidate(&ldapConfs) + v := map[string]interface{}{} + if err := json.Unmarshal(l.Ctx.Input.RequestBody, + &v); err != nil { + log.Errorf("failed to unmarshal LDAP server settings: %v", err) + l.RenderError(http.StatusInternalServerError, "") + return + } + if _, ok := v["ldap_search_password"]; !ok { + settings, err := ldapUtils.GetSystemLdapConf() + if err != nil { + log.Errorf("Can't load system configuration, error: %v", err) + l.RenderError(http.StatusInternalServerError, fmt.Sprintf("can't load system configuration: %v", err)) + return + } + ldapConfs.LdapSearchPassword = settings.LdapSearchPassword + } } ldapConfs, err = ldapUtils.ValidateLdapConf(ldapConfs)