Skip to content

Commit 7ad3156

Browse files
authored
Fix ldap admin privileges update bug (#27051)
When the user does not set a username lookup condition, LDAP will get an empty string `""` for the user, hence the following code ``` if isExist, err := user_model.IsUserExist(db.DefaultContext, 0, sr.Username) ``` The user presence determination will always be nonexistent, so updates to user information will never be performed. Fix #27049
1 parent 6e87a44 commit 7ad3156

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

services/auth/source/ldap/source_authenticate.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
2929
// User not in LDAP, do nothing
3030
return nil, user_model.ErrUserNotExist{Name: loginName}
3131
}
32-
32+
// Fallback.
33+
if len(sr.Username) == 0 {
34+
sr.Username = userName
35+
}
36+
if len(sr.Mail) == 0 {
37+
sr.Mail = fmt.Sprintf("%[email protected]", sr.Username)
38+
}
3339
isAttributeSSHPublicKeySet := len(strings.TrimSpace(source.AttributeSSHPublicKey)) > 0
3440

3541
// Update User admin flag if exist
@@ -70,15 +76,6 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
7076
}
7177
}
7278
} else {
73-
// Fallback.
74-
if len(sr.Username) == 0 {
75-
sr.Username = userName
76-
}
77-
78-
if len(sr.Mail) == 0 {
79-
sr.Mail = fmt.Sprintf("%[email protected]", sr.Username)
80-
}
81-
8279
user = &user_model.User{
8380
LowerName: strings.ToLower(sr.Username),
8481
Name: sr.Username,

0 commit comments

Comments
 (0)