content: package com.adamzareba.spring.security.oauth2.service;
  
  import com.adamzareba.spring.security.oauth2.model.security.User;
  import com.adamzareba.spring.security.oauth2.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
      private UserRepository userRepository;
  
      @Override
      @Transactional(readOnly = true)
      public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
          User user = userRepository.findByUsername(username);
  
          if (user != null) {
              return user;
          }
  
          throw new UsernameNotFoundException(username);
      }
  }
  