content: package net.alex9849.cocktailpi.config.security;
  
  import net.alex9849.cocktailpi.model.user.User;
  import net.alex9849.cocktailpi.repository.UserRepository;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.security.core.userdetails.UserDetails;
  import org.springframework.security.core.userdetails.UserDetailsService;
  import org.springframework.security.core.userdetails.UsernameNotFoundException;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  
  @Service
  public class UserDetailsServiceImpl implements UserDetailsService {
      @Autowired
      UserRepository userRepository;
  
      @Transactional
      public User loadUserById(long id) throws UsernameNotFoundException {
          return userRepository.findById(id)
                  .orElseThrow(() -> new UsernameNotFoundException("User Not Found with id: " + id));
      }
  
      @Override
      public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
          return userRepository.findByUsernameIgnoringCase(username)
                  .orElseThrow(() -> new UsernameNotFoundException("User Not Found with username: " + username));
      }
  }
  