summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-06-28 14:53:44 -0400
committerGitHub <noreply@github.com>2016-06-28 14:53:44 -0400
commit96bddf90169a0d9c39bdb0ae425ff15dfd03f62b (patch)
tree66aa05158f7ed8f36a6f0c1d88f24b3419fb58f9
parent8c2282f89e6c439044afe98eb61f806d5a3215b5 (diff)
downloadchat-96bddf90169a0d9c39bdb0ae425ff15dfd03f62b.tar.gz
chat-96bddf90169a0d9c39bdb0ae425ff15dfd03f62b.tar.bz2
chat-96bddf90169a0d9c39bdb0ae425ff15dfd03f62b.zip
Adding validation for LDAP settings to configuration (#3425)
-rw-r--r--i18n/en.json4
-rw-r--r--mattermost.go4
-rw-r--r--model/config.go19
-rw-r--r--utils/config.go6
4 files changed, 27 insertions, 6 deletions
diff --git a/i18n/en.json b/i18n/en.json
index b6c9e91cc..e428dc781 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -2516,6 +2516,10 @@
"translation": "Invalid sync interval time. Must be at least one minute."
},
{
+ "id": "model.config.is_valid.ldap_required.app_error",
+ "translation": "Required LDAP field missing."
+ },
+ {
"id": "model.config.is_valid.listen_address.app_error",
"translation": "Invalid listen address for service settings Must be set."
},
diff --git a/mattermost.go b/mattermost.go
index 963978ecf..bdfa55d9a 100644
--- a/mattermost.go
+++ b/mattermost.go
@@ -71,7 +71,7 @@ var flagRunCmds bool
func doLoadConfig(filename string) (err string) {
defer func() {
if r := recover(); r != nil {
- err = fmt.Sprintf("Error loding config, err=%v", r)
+ err = fmt.Sprintf("%v", r)
}
}()
utils.LoadConfig(filename)
@@ -83,7 +83,7 @@ func main() {
parseCmds()
if errstr := doLoadConfig(flagConfigFile); errstr != "" {
- l4g.Exit("Unable to load mattermost configuration file:", errstr)
+ l4g.Exit("Unable to load mattermost configuration file: ", errstr)
return
}
diff --git a/model/config.go b/model/config.go
index cbb254768..51a3b252e 100644
--- a/model/config.go
+++ b/model/config.go
@@ -486,6 +486,11 @@ func (o *Config) SetDefaults() {
*o.LdapSettings.EmailAttribute = ""
}
+ if o.LdapSettings.UsernameAttribute == nil {
+ o.LdapSettings.UsernameAttribute = new(string)
+ *o.LdapSettings.UsernameAttribute = ""
+ }
+
if o.LdapSettings.NicknameAttribute == nil {
o.LdapSettings.NicknameAttribute = new(string)
*o.LdapSettings.NicknameAttribute = ""
@@ -709,6 +714,20 @@ func (o *Config) IsValid() *AppError {
return NewLocAppError("Config.IsValid", "model.config.is_valid.ldap_sync_interval.app_error", nil, "")
}
+ if *o.LdapSettings.Enable {
+ if *o.LdapSettings.LdapServer == "" ||
+ *o.LdapSettings.BaseDN == "" ||
+ *o.LdapSettings.BindUsername == "" ||
+ *o.LdapSettings.BindPassword == "" ||
+ *o.LdapSettings.FirstNameAttribute == "" ||
+ *o.LdapSettings.LastNameAttribute == "" ||
+ *o.LdapSettings.EmailAttribute == "" ||
+ *o.LdapSettings.UsernameAttribute == "" ||
+ *o.LdapSettings.IdAttribute == "" {
+ return NewLocAppError("Config.IsValid", "Required LDAP field missing", nil, "")
+ }
+ }
+
return nil
}
diff --git a/utils/config.go b/utils/config.go
index 5b8ba0906..79d1d8e4b 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -168,13 +168,11 @@ func LoadConfig(fileName string) {
config.SetDefaults()
if err := config.IsValid(); err != nil {
- panic(T("utils.config.load_config.validating.panic",
- map[string]interface{}{"Filename": fileName, "Error": err.Message}))
+ panic(err.Error())
}
if err := ValidateLdapFilter(&config); err != nil {
- panic(T("utils.config.load_config.validating.panic",
- map[string]interface{}{"Filename": fileName, "Error": err.Message}))
+ panic(err.Error())
}
configureLog(&config.LogSettings)