Browse Source

auth/ldap: allow placeholder %s for BindDN (#2526)

pull/4722/merge
Unknwon 7 years ago
parent
commit
6f04ee879c
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 1
      conf/locale/locale_en-US.ini
  2. 2
      gogs.go
  3. 10
      pkg/auth/ldap/ldap.go
  4. 4
      pkg/bindata/bindata.go
  5. 2
      templates/.VERSION
  6. 1
      templates/admin/auth/edit.tmpl
  7. 1
      templates/admin/auth/new.tmpl

1
conf/locale/locale_en-US.ini

@ -1099,6 +1099,7 @@ auths.domain = Domain
auths.host = Host auths.host = Host
auths.port = Port auths.port = Port
auths.bind_dn = Bind DN auths.bind_dn = Bind DN
auths.bind_dn_helper = You can use '%s' as placeholder for username, e.g. DOM\%s
auths.bind_password = Bind Password auths.bind_password = Bind Password
auths.bind_password_helper = Warning: This password is stored in plain text. Do not use a high privileged account. auths.bind_password_helper = Warning: This password is stored in plain text. Do not use a high privileged account.
auths.user_base = User Search Base auths.user_base = User Search Base

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/setting"
) )
const APP_VER = "0.11.32.1115" const APP_VER = "0.11.33.1116"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

10
pkg/auth/ldap/ldap.go

@ -96,13 +96,15 @@ func (ls *Source) sanitizedGroupDN(groupDn string) (string, bool) {
func (ls *Source) findUserDN(l *ldap.Conn, name string) (string, bool) { func (ls *Source) findUserDN(l *ldap.Conn, name string) (string, bool) {
log.Trace("Search for LDAP user: %s", name) log.Trace("Search for LDAP user: %s", name)
if ls.BindDN != "" && ls.BindPassword != "" { if len(ls.BindDN) > 0 && len(ls.BindPassword) > 0 {
err := l.Bind(ls.BindDN, ls.BindPassword) // Replace placeholders with username
bindDN := strings.Replace(ls.BindDN, "%s", name, -1)
err := l.Bind(bindDN, ls.BindPassword)
if err != nil { if err != nil {
log.Trace("LDAP: Failed to bind as BindDN '%s': %v", ls.BindDN, err) log.Trace("LDAP: Failed to bind as BindDN '%s': %v", bindDN, err)
return "", false return "", false
} }
log.Trace("LDAP: Bound as BindDN: %s", ls.BindDN) log.Trace("LDAP: Bound as BindDN: %s", bindDN)
} else { } else {
log.Trace("LDAP: Proceeding with anonymous LDAP search") log.Trace("LDAP: Proceeding with anonymous LDAP search")
} }

4
pkg/bindata/bindata.go

File diff suppressed because one or more lines are too long

2
templates/.VERSION

@ -1 +1 @@
0.11.32.1115 0.11.33.1116

1
templates/admin/auth/edit.tmpl

@ -50,6 +50,7 @@
<div class="field"> <div class="field">
<label for="bind_dn">{{.i18n.Tr "admin.auths.bind_dn"}}</label> <label for="bind_dn">{{.i18n.Tr "admin.auths.bind_dn"}}</label>
<input id="bind_dn" name="bind_dn" value="{{$cfg.BindDN}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com"> <input id="bind_dn" name="bind_dn" value="{{$cfg.BindDN}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com">
<p class="help text red">{{.i18n.Tr "admin.auths.bind_dn_helper"}}</p>
</div> </div>
<input class="fake" type="password"> <input class="fake" type="password">
<div class="field"> <div class="field">

1
templates/admin/auth/new.tmpl

@ -56,6 +56,7 @@
<div class="ldap field {{if not (eq .type 2)}}hide{{end}}"> <div class="ldap field {{if not (eq .type 2)}}hide{{end}}">
<label for="bind_dn">{{.i18n.Tr "admin.auths.bind_dn"}}</label> <label for="bind_dn">{{.i18n.Tr "admin.auths.bind_dn"}}</label>
<input id="bind_dn" name="bind_dn" value="{{.bind_dn}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com"> <input id="bind_dn" name="bind_dn" value="{{.bind_dn}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com">
<p class="help text blue">{{.i18n.Tr "admin.auths.bind_dn_helper"}}</p>
</div> </div>
<div class="ldap field {{if not (eq .type 2)}}hide{{end}}"> <div class="ldap field {{if not (eq .type 2)}}hide{{end}}">
<label for="bind_password">{{.i18n.Tr "admin.auths.bind_password"}}</label> <label for="bind_password">{{.i18n.Tr "admin.auths.bind_password"}}</label>

Loading…
Cancel
Save