fix: add sAMAccountName for AD search (#1869)

This commit is contained in:
Yaodong Yu 2023-05-19 21:16:59 +08:00 committed by GitHub
parent af79fdedf2
commit 1260354b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -211,7 +211,7 @@ func checkLdapUserPassword(user *User, password string, lang string) string {
}
searchReq := goldap.NewSearchRequest(ldapServer.BaseDn, goldap.ScopeWholeSubtree, goldap.NeverDerefAliases,
0, 0, false, ldapServer.buildFilterString(user), []string{}, nil)
0, 0, false, ldapServer.buildAuthFilterString(user), []string{}, nil)
searchResult, err := conn.Conn.Search(searchReq)
if err != nil {

View File

@ -367,7 +367,7 @@ func (ldapUser *LdapUser) GetLdapUuid() string {
return ldapUser.Cn
}
func (ldap *Ldap) buildFilterString(user *User) string {
func (ldap *Ldap) buildAuthFilterString(user *User) string {
if len(ldap.FilterFields) == 0 {
return fmt.Sprintf("(&%s(uid=%s))", ldap.Filter, user.Name)
}
@ -385,6 +385,8 @@ func (user *User) getFieldFromLdapAttribute(attribute string) string {
switch attribute {
case "uid":
return user.Name
case "sAMAccountName":
return user.Name
case "mail":
return user.Email
case "mobile":

View File

@ -185,6 +185,7 @@ class LdapEditPage extends React.Component {
{value: "uid", label: "uid"},
{value: "mail", label: "Email"},
{value: "mobile", label: "mobile"},
{value: "sAMAccountName", label: "sAMAccountName"},
].map((item) => Setting.getOption(item.label, item.value))} onChange={value => {
this.updateLdapField("filterFields", value);
}} />