use of br.fatecsp.engsoft.entities.User in project Projeto_Detetive_ES3 by VitorAndrioli.
the class UserDetailsServiceImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Optional<User> userOp = Optional.ofNullable(UserRepository.findByUsername(username));
User user = userOp.orElseThrow(() -> new UsernameNotFoundException("Usuario não encontrado"));
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
user.getRoles().stream().forEach(role -> {
grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
});
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), grantedAuthorities);
}
Aggregations