Skip to content

Commit 0b7bf57

Browse files
authored
Merge pull request #231 from hudeng-go/master
feat: Add account pattern support at ldap settings
2 parents 5b2e00a + 7bdf6cb commit 0b7bf57

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/services/auth_login_ldap.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
78
"github.com/go-ldap/ldap/v3"
89
)
910

@@ -15,6 +16,7 @@ type AuthLoginConfig struct {
1516
BaseDn string `json:"basedn"`
1617
BindUsername string `json:"bind_username"`
1718
BindPassword string `json:"bind_password"`
19+
AccountPattern string `json:"account_pattern"`
1820
GivenNameKey string `json:"given_name_key"`
1921
EmailKey string `json:"email_key"`
2022
MobileKey string `json:"mobile_key"`
@@ -80,14 +82,18 @@ func (al *AuthLoginLdapService) AuthLogin(username string, password string) (*Au
8082
}
8183

8284
// 搜索下用户信息
85+
accountPattern := "(&(objectClass=User)(userPrincipalName=%s))"
86+
if al.config.AccountPattern != "" {
87+
accountPattern = al.config.AccountPattern
88+
}
8389
searchRequest := ldap.NewSearchRequest(
8490
al.config.BaseDn,
8591
ldap.ScopeWholeSubtree,
8692
ldap.NeverDerefAliases,
8793
0,
8894
0,
8995
false,
90-
fmt.Sprintf("(&(objectClass=User)(userPrincipalName=%s))", username),
96+
fmt.Sprintf(accountPattern, username),
9197
al.GetAttributes(),
9298
nil,
9399
)

views/system/auth/doc.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ <h4><i class="fa fa-address-card-o"></i> 登录认证方式配置文档</h4>
3333
"basedn": "dc=umich,dc=edu", // ldap base dn; 用于搜索的节点;必填不能为空
3434
"bind_username": "readonly", // ldap bind dn; 用来获取查询权限的 bind 用户;非必填可以为空
3535
"bind_password": "password", // ldap bind dn password; bind 用户密码;非必填可以为空
36+
"account_pattern": "(&(objectClass=User)(userPrincipalName=%s))" // ldap search pattern; 非必填可以为空,默认值为(&(objectClass=User)(userPrincipalName=%s))
3637
"given_name_key": "displayName", // ldap 查询用户名对应的 key,必填
3738
"email_key": "mail", // ldap 查询邮箱对应的 key, 没有可为空
3839
"mobile_key": "mobile", // ldap 查询手机号对应的 key,没有可为空

0 commit comments

Comments
 (0)