[feat-1059]: задокументировано поведение getCurrentUser()#1075
Open
Textile86 wants to merge 4 commits intohexlet-volunteers:mainfrom
Open
[feat-1059]: задокументировано поведение getCurrentUser()#1075Textile86 wants to merge 4 commits intohexlet-volunteers:mainfrom
Textile86 wants to merge 4 commits intohexlet-volunteers:mainfrom
Conversation
ann-p-1320
reviewed
Apr 10, 2026
| var authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| if (authentication == null || !authentication.isAuthenticated()) { | ||
| return null; | ||
| throw new InsufficientAuthenticationException("User is not authenticated"); |
There was a problem hiding this comment.
Какие есть основания в пользу того, чтобы использовать именно InsufficientAuthenticationException? Что именно мы скажем клиенты этим exception'ом?
Author
There was a problem hiding this comment.
Выбрасывая InsufficientAuthenticationException мы говорим клиенту что его учетные данные отсутствуют и что ему нужно пройти аутентификацию
Это исключение лучше всего подходит потому что чутко указывает на отсутствие аутентификации, правильно обрабатывается Spring Security фильтрами, возвращает понятный статус 401 для клиента.
ann-p-1320
reviewed
Apr 10, 2026
| // на потом чтобы работать с залогиненым юзером | ||
| /** | ||
| * Метод возвращает текущего аутентифицированного пользователя. | ||
| * Метод извлекает email из Spring Security и загружает соответствующего пользователя |
ann-p-1320
reviewed
Apr 14, 2026
| var email = authentication.getName(); | ||
| return userRepository.findByEmail(email).get(); | ||
| return userRepository.findByEmail(email) | ||
| .orElseThrow(() -> new UserNotFoundException("User not found: " + email)); |
There was a problem hiding this comment.
Это должно быть исправлено в рамках другой ишью
|
аппрув |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1059