From efc05ea1dec5a60c95763fc5158d60b45ef46d8f Mon Sep 17 00:00:00 2001 From: juju2013 Date: Tue, 22 Apr 2014 18:55:27 +0200 Subject: initial support for LDAP authentication/MSAD --- modules/base/conf.go | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'modules/base') diff --git a/modules/base/conf.go b/modules/base/conf.go index abb67f6d..57245045 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -10,6 +10,7 @@ import ( "os/exec" "path" "path/filepath" + "regexp" "strings" "github.com/Unknwon/com" @@ -19,6 +20,7 @@ import ( "github.com/gogits/cache" "github.com/gogits/session" + "github.com/gogits/gogs/modules/auth/ldap" "github.com/gogits/gogs/modules/log" ) @@ -51,6 +53,7 @@ var ( Domain string SecretKey string RunUser string + LdapAuth bool RepoRootPath string ScriptType string @@ -83,13 +86,13 @@ var ( ) var Service struct { - RegisterEmailConfirm bool - DisableRegistration bool - RequireSignInView bool - EnableCacheAvatar bool - NotifyMail bool - ActiveCodeLives int - ResetPwdCodeLives int + RegisterEmailConfirm bool + DisableRegistration bool + RequireSignInView bool + EnableCacheAvatar bool + NotifyMail bool + ActiveCodeLives int + ResetPwdCodeLives int } func ExecDir() (string, error) { @@ -310,6 +313,33 @@ func NewConfigContext() { CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME") CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME") + // load LDAP authentication configuration if present + LdapAuth = Cfg.MustBool("security", "LDAP_AUTH", false) + if LdapAuth { + log.Debug("LDAP AUTHENTICATION activated") + nbsrc := 0 + for _, v := range Cfg.GetSectionList() { + if matched, _ := regexp.MatchString("(?i)^LDAPSOURCE.*", v); matched { + ldapname := Cfg.MustValue(v, "name", v) + ldaphost := Cfg.MustValue(v, "host") + ldapport := Cfg.MustInt(v, "port", 389) + ldapbasedn := Cfg.MustValue(v, "basedn", "dc=*,dc=*") + ldapattribute := Cfg.MustValue(v, "attribute", "mail") + ldapfilter := Cfg.MustValue(v, "filter", "(*)") + ldapmsadsaformat := Cfg.MustValue(v, "MSADSAFORMAT", "%s") + ldap.AddSource(ldapname, ldaphost, ldapport, ldapbasedn, ldapattribute, ldapfilter, ldapmsadsaformat) + nbsrc += 1 + log.Debug("%s added as LDAP source", ldapname) + } + } + if nbsrc == 0 { + log.Debug("No valide LDAP found, LDAP AUTHENTICATION NOT activated") + LdapAuth = false + } + } else { + log.Debug("LDAP AUTHENTICATION NOT activated") + } + PictureService = Cfg.MustValue("picture", "SERVICE") // Determine and create root git reposiroty path. -- cgit v1.2.3