fix(api): allow logout with user anonymousUser (#2764)
This commit is contained in:
@@ -52,7 +52,7 @@ public class LogoutService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private BookLoreUserEntity resolveUser(Authentication auth, String refreshToken) {
|
private BookLoreUserEntity resolveUser(Authentication auth, String refreshToken) {
|
||||||
if (auth != null && auth.isAuthenticated() && !"anonymousUser".equals(auth.getPrincipal())) {
|
if (auth != null && auth.isAuthenticated()) {
|
||||||
var bookLoreUser = authenticationService.getAuthenticatedUser();
|
var bookLoreUser = authenticationService.getAuthenticatedUser();
|
||||||
return userRepository.findByUsername(bookLoreUser.getUsername())
|
return userRepository.findByUsername(bookLoreUser.getUsername())
|
||||||
.orElseThrow(() -> ApiError.GENERIC_UNAUTHORIZED.createException("User not found"));
|
.orElseThrow(() -> ApiError.GENERIC_UNAUTHORIZED.createException("User not found"));
|
||||||
|
|||||||
@@ -274,7 +274,6 @@ class LogoutServiceTest {
|
|||||||
private Authentication mockAuth() {
|
private Authentication mockAuth() {
|
||||||
var auth = mock(Authentication.class);
|
var auth = mock(Authentication.class);
|
||||||
when(auth.isAuthenticated()).thenReturn(true);
|
when(auth.isAuthenticated()).thenReturn(true);
|
||||||
when(auth.getPrincipal()).thenReturn("not-anonymous");
|
|
||||||
return auth;
|
return auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user