mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Adding validation for LDAP settings to configuration (#3425)
This commit is contained in:
committed by
GitHub
parent
8c2282f89e
commit
96bddf9016
@@ -2515,6 +2515,10 @@
|
||||
"id": "model.config.is_valid.ldap_sync_interval.app_error",
|
||||
"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."
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user