Created
January 16, 2022 15:12
-
-
Save iamprafful/f2fbd32d76a59c040025225299492e1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.api.service; | |
import com.example.api.repository.UserRepository; | |
import org.springframework.security.core.GrantedAuthority; | |
import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
import org.springframework.security.core.userdetails.User; | |
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.ArrayList; | |
import java.util.List; | |
@Service | |
public class JwtUserDetailsService implements UserDetailsService { | |
final UserRepository userRepository; | |
public JwtUserDetailsService(UserRepository userRepository) { | |
this.userRepository = userRepository; | |
} | |
@Override | |
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | |
com.example.api.model.User user = userRepository.findUserByUsername(username); | |
List<GrantedAuthority> authorityList = new ArrayList<>(); | |
authorityList.add(new SimpleGrantedAuthority("USER_ROLE")); | |
return new User(user.getUserName(), user.getPassword(), authorityList); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment