From 71476ab1db7d1d7dc57643bdf98ec4d8cfce147e Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Sun, 4 Oct 2020 14:10:44 +0300 Subject: [PATCH] Properly handle events when user is not found Signed-off-by: Pekka Helenius --- .../bookstore/service/session/UserDetailServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/service/session/UserDetailServiceImpl.java b/bookstore/src/main/java/com/fjordtek/bookstore/service/session/UserDetailServiceImpl.java index 7213455..b5b4df4 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/service/session/UserDetailServiceImpl.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/service/session/UserDetailServiceImpl.java @@ -67,6 +67,10 @@ public class UserDetailServiceImpl implements UserDetailsService { User currentUser = userRepository.findByUsername(userName); + if (currentUser == null) { + throw new UsernameNotFoundException(""); + } + UserDetails userDetails = new org.springframework.security.core.userdetails.User( userName, currentUser.getPassword(), getUserGrantedAuthorities(userName) );