Adding validation for LDAP settings to configuration (#3425)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8c2282f89e
Коммит
96bddf9016
@@ -2515,6 +2515,10 @@
|
|||||||
"id": "model.config.is_valid.ldap_sync_interval.app_error",
|
"id": "model.config.is_valid.ldap_sync_interval.app_error",
|
||||||
"translation": "Invalid sync interval time. Must be at least one minute."
|
"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",
|
"id": "model.config.is_valid.listen_address.app_error",
|
||||||
"translation": "Invalid listen address for service settings Must be set."
|
"translation": "Invalid listen address for service settings Must be set."
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ var flagRunCmds bool
|
|||||||
func doLoadConfig(filename string) (err string) {
|
func doLoadConfig(filename string) (err string) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
err = fmt.Sprintf("Error loding config, err=%v", r)
|
err = fmt.Sprintf("%v", r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
utils.LoadConfig(filename)
|
utils.LoadConfig(filename)
|
||||||
@@ -83,7 +83,7 @@ func main() {
|
|||||||
parseCmds()
|
parseCmds()
|
||||||
|
|
||||||
if errstr := doLoadConfig(flagConfigFile); errstr != "" {
|
if errstr := doLoadConfig(flagConfigFile); errstr != "" {
|
||||||
l4g.Exit("Unable to load mattermost configuration file:", errstr)
|
l4g.Exit("Unable to load mattermost configuration file: ", errstr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -486,6 +486,11 @@ func (o *Config) SetDefaults() {
|
|||||||
*o.LdapSettings.EmailAttribute = ""
|
*o.LdapSettings.EmailAttribute = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.LdapSettings.UsernameAttribute == nil {
|
||||||
|
o.LdapSettings.UsernameAttribute = new(string)
|
||||||
|
*o.LdapSettings.UsernameAttribute = ""
|
||||||
|
}
|
||||||
|
|
||||||
if o.LdapSettings.NicknameAttribute == nil {
|
if o.LdapSettings.NicknameAttribute == nil {
|
||||||
o.LdapSettings.NicknameAttribute = new(string)
|
o.LdapSettings.NicknameAttribute = new(string)
|
||||||
*o.LdapSettings.NicknameAttribute = ""
|
*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, "")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,13 +168,11 @@ func LoadConfig(fileName string) {
|
|||||||
config.SetDefaults()
|
config.SetDefaults()
|
||||||
|
|
||||||
if err := config.IsValid(); err != nil {
|
if err := config.IsValid(); err != nil {
|
||||||
panic(T("utils.config.load_config.validating.panic",
|
panic(err.Error())
|
||||||
map[string]interface{}{"Filename": fileName, "Error": err.Message}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ValidateLdapFilter(&config); err != nil {
|
if err := ValidateLdapFilter(&config); err != nil {
|
||||||
panic(T("utils.config.load_config.validating.panic",
|
panic(err.Error())
|
||||||
map[string]interface{}{"Filename": fileName, "Error": err.Message}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configureLog(&config.LogSettings)
|
configureLog(&config.LogSettings)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user