content: package com.amran.dynamic.multitenant.security;
  
  import com.amran.dynamic.multitenant.tenant.repository.UserRepository;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.security.core.authority.SimpleGrantedAuthority;
  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 java.util.Arrays;
  import java.util.List;
  
  /**
   * @author Md. Amran Hossain
   */
  @Service
  public class JwtUserDetailsService implements UserDetailsService {
  
      @Autowired
      UserRepository userRepository;
  
      @Override
      public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
          com.amran.dynamic.multitenant.tenant.entity.User user = userRepository.findByUserName(userName);
          if(null == user){
              throw new UsernameNotFoundException("Invalid user name or password.");
          }
          return new org.springframework.security.core.userdetails.User(user.getUserName(), user.getPassword(), getAuthority());
      }
  
      private List<SimpleGrantedAuthority> getAuthority() {
          return Arrays.asList(new SimpleGrantedAuthority("ROLE_ADMIN"));
      }
  }
  