package net.devopssolutions.microservice.auth.security;

import net.devopssolutions.microservice.auth.model.User;
import net.devopssolutions.microservice.auth.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class AuthDetailsService implements UserDetailsService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public User loadUserByUsername(String username) throws UsernameNotFoundException {
        return userRepository.findByName(username);
    }
}

@@ -693,14 +693,19 @@
     
-return
+User user =
  use
@@ -738,16 +738,170 @@
 rname);%0A
+        if (user == null) %7B%0A            throw new UsernameNotFoundException(String.format(%22user %25s not found%22, username));%0A        %7D%0A        return user;%0A
     %7D%0A%7D%0A

throw exception when user is not found