Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions internal/service/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (auth *AuthService) SearchUser(username string) (*model.UserSearch, error)
return nil, ErrUserNotFound
}

func (auth *AuthService) CheckUserPassword(search model.UserSearch, password string) error {
func (auth *AuthService) CheckUserPassword(search model.UserSearch, password string) (err error) {
switch search.Type {
case model.UserLocal:
user := auth.GetLocalUser(search.Username)
Expand All @@ -203,14 +203,20 @@ func (auth *AuthService) CheckUserPassword(search model.UserSearch, password str
return bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password))
case model.UserLDAP:
if auth.ldap != nil {
err := auth.ldap.Bind(search.Username, password)
if err != nil {
return fmt.Errorf("failed to bind to ldap user: %w", err)
}
defer func() {
bindErr := auth.ldap.BindService(true)
if bindErr != nil {
if err != nil {
err = fmt.Errorf("failed to rebind to ldap service account: %w, original error: %w", bindErr, err)
return
}
err = fmt.Errorf("failed to rebind to ldap service account: %w", bindErr)
}
}()

err = auth.ldap.BindService(true)
err = auth.ldap.Bind(search.Username, password)
if err != nil {
return fmt.Errorf("failed to bind to ldap service account: %w", err)
return fmt.Errorf("failed to bind to ldap user: %w", err)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

return nil
Expand Down
Loading