Added allow_sign_up setting to auth.ldap to be able to disable automatic user creation for LDAP logins (#6191)

This commit is contained in:
Eric Perrino
2016-10-07 01:49:58 -05:00
committed by Torkel Ödegaard
parent 7e6595acaf
commit d3b0905899
4 changed files with 10 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
type ldapAuther struct {
@@ -132,8 +133,10 @@ func (a *ldapAuther) getGrafanaUserFor(ldapUser *ldapUserInfo) (*m.User, error)
// get user from grafana db
userQuery := m.GetUserByLoginQuery{LoginOrEmail: ldapUser.Username}
if err := bus.Dispatch(&userQuery); err != nil {
if err == m.ErrUserNotFound {
if err == m.ErrUserNotFound && setting.LdapAllowSignup {
return a.createGrafanaUser(ldapUser)
} else if err == m.ErrUserNotFound {
return nil, ErrInvalidCredentials
} else {
return nil, err
}

View File

@@ -134,8 +134,9 @@ var (
GoogleTagManagerId string
// LDAP
LdapEnabled bool
LdapConfigFile string
LdapEnabled bool
LdapConfigFile string
LdapAllowSignup bool = true
// SMTP email settings
Smtp SmtpSettings
@@ -551,6 +552,7 @@ func NewConfigContext(args *CommandLineArgs) error {
ldapSec := Cfg.Section("auth.ldap")
LdapEnabled = ldapSec.Key("enabled").MustBool(false)
LdapConfigFile = ldapSec.Key("config_file").String()
LdapAllowSignup = ldapSec.Key("allow_sign_up").MustBool(true)
alerting := Cfg.Section("alerting")
AlertingEnabled = alerting.Key("enabled").MustBool(false)