fix: use clearer message for ldap auth failure (#39392)

* fix #34942

log: `user does not exist ...: not in LDAP database or invalid password`
This commit is contained in:
wxiaoguang
2026-09-23 16:30:58 +08:00
committed by GitHub
parent 8164130349
commit 6146a4869e
2 changed files with 10 additions and 5 deletions
+8 -3
View File
@@ -31,8 +31,9 @@ func (err ErrUserAlreadyExist) Unwrap() error {
// ErrUserNotExist represents a "UserNotExist" kind of error. // ErrUserNotExist represents a "UserNotExist" kind of error.
type ErrUserNotExist struct { type ErrUserNotExist struct {
UID int64 UID int64
Name string Name string
ExtraMsg string
} }
// IsErrUserNotExist checks if an error is a ErrUserNotExist. // IsErrUserNotExist checks if an error is a ErrUserNotExist.
@@ -42,7 +43,11 @@ func IsErrUserNotExist(err error) bool {
} }
func (err ErrUserNotExist) Error() string { func (err ErrUserNotExist) Error() string {
return fmt.Sprintf("user does not exist [uid: %d, name: %s]", err.UID, err.Name) ret := fmt.Sprintf("user does not exist [uid: %d, name: %s]", err.UID, err.Name)
if err.ExtraMsg != "" {
ret += ": " + err.ExtraMsg
}
return ret
} }
// Unwrap unwraps this error as a ErrNotExist error // Unwrap unwraps this error as a ErrNotExist error
@@ -31,8 +31,8 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
} }
sr := source.SearchEntry(loginName, password, source.AuthSource.Type == auth.DLDAP) sr := source.SearchEntry(loginName, password, source.AuthSource.Type == auth.DLDAP)
if sr == nil { if sr == nil {
// User not in LDAP, do nothing // User is not in LDAP database, or password is invalid (direct bind)
return nil, user_model.ErrUserNotExist{Name: loginName} return nil, user_model.ErrUserNotExist{Name: loginName, ExtraMsg: "not in LDAP database or invalid password"}
} }
// Fallback. // Fallback.
// FIXME: this fallback would cause problems when the "Username" attribute is not set and a user inputs their email. // FIXME: this fallback would cause problems when the "Username" attribute is not set and a user inputs their email.