1
0
Fork 0
forked from forgejo/forgejo

initial support for LDAP authentication/MSAD

This commit is contained in:
juju2013 2014-04-22 18:55:27 +02:00 committed by juju2013
parent dbdaf934e1
commit efc05ea1de
7 changed files with 216 additions and 8 deletions

View file

@ -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.