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
This commit is contained in:
parent
6e87a44034
commit
7ad31567cd
1 changed files with 7 additions and 10 deletions
|
@ -29,7 +29,13 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
|
||||||
// User not in LDAP, do nothing
|
// User not in LDAP, do nothing
|
||||||
return nil, user_model.ErrUserNotExist{Name: loginName}
|
return nil, user_model.ErrUserNotExist{Name: loginName}
|
||||||
}
|
}
|
||||||
|
// Fallback.
|
||||||
|
if len(sr.Username) == 0 {
|
||||||
|
sr.Username = userName
|
||||||
|
}
|
||||||
|
if len(sr.Mail) == 0 {
|
||||||
|
sr.Mail = fmt.Sprintf("%s@localhost.local", sr.Username)
|
||||||
|
}
|
||||||
isAttributeSSHPublicKeySet := len(strings.TrimSpace(source.AttributeSSHPublicKey)) > 0
|
isAttributeSSHPublicKeySet := len(strings.TrimSpace(source.AttributeSSHPublicKey)) > 0
|
||||||
|
|
||||||
// Update User admin flag if exist
|
// Update User admin flag if exist
|
||||||
|
@ -70,15 +76,6 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fallback.
|
|
||||||
if len(sr.Username) == 0 {
|
|
||||||
sr.Username = userName
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(sr.Mail) == 0 {
|
|
||||||
sr.Mail = fmt.Sprintf("%s@localhost.local", sr.Username)
|
|
||||||
}
|
|
||||||
|
|
||||||
user = &user_model.User{
|
user = &user_model.User{
|
||||||
LowerName: strings.ToLower(sr.Username),
|
LowerName: strings.ToLower(sr.Username),
|
||||||
Name: sr.Username,
|
Name: sr.Username,
|
||||||
|
|
Loading…
Reference in a new issue