settings.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package login
  2. import (
  3. "github.com/BurntSushi/toml"
  4. "github.com/grafana/grafana/pkg/log"
  5. m "github.com/grafana/grafana/pkg/models"
  6. "github.com/grafana/grafana/pkg/setting"
  7. )
  8. type LdapConfig struct {
  9. Servers []*LdapServerConf `toml:"servers"`
  10. VerboseLogging bool `toml:"verbose_logging"`
  11. }
  12. type LdapServerConf struct {
  13. Host string `toml:"host"`
  14. Port int `toml:"port"`
  15. UseSSL bool `toml:"use_ssl"`
  16. BindDN string `toml:"bind_dn"`
  17. BindPassword string `toml:"bind_password"`
  18. Attr LdapAttributeMap `toml:"attributes"`
  19. SearchFilter string `toml:"search_filter"`
  20. SearchBaseDNs []string `toml:"search_base_dns"`
  21. LdapGroups []*LdapGroupToOrgRole `toml:"group_mappings"`
  22. }
  23. type LdapAttributeMap struct {
  24. Username string `toml:"username"`
  25. Name string `toml:"name"`
  26. Surname string `toml:"surname"`
  27. Email string `toml:"email"`
  28. MemberOf string `toml:"member_of"`
  29. }
  30. type LdapGroupToOrgRole struct {
  31. GroupDN string `toml:"group_dn"`
  32. OrgId int64 `toml:"org_id"`
  33. OrgRole m.RoleType `toml:"org_role"`
  34. }
  35. var ldapCfg LdapConfig
  36. func loadLdapConfig() {
  37. if !setting.LdapEnabled {
  38. return
  39. }
  40. log.Info("Login: Ldap enabled, reading config file: %s", setting.LdapConfigFile)
  41. _, err := toml.DecodeFile(setting.LdapConfigFile, &ldapCfg)
  42. if err != nil {
  43. log.Fatal(3, "Failed to load ldap config file: %s", err)
  44. }
  45. // set default org id
  46. for _, server := range ldapCfg.Servers {
  47. for _, groupMap := range server.LdapGroups {
  48. if groupMap.OrgId == 0 {
  49. groupMap.OrgId = 1
  50. }
  51. }
  52. }
  53. }