/** @see UserDetailsService#loadUserByUsername(String) */ @Override @Transactional(readOnly = true) public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Professor professor = professorRepository.findByUsername(username); if (professor == null) { throw new UsernameNotFoundException("Nombre de usuario o contraseña no válidos"); } return buildUserForAuthentication( professor, new SimpleGrantedAuthority(professor.getRole().toString())); }
/** * Builds a new {@link User} based on the given professor and authority. * * @param professor the professor used as base to the user. * @param authority {@link GrantedAuthority} the professor has * @return {@link User} based on the professor. */ private User buildUserForAuthentication(Professor professor, GrantedAuthority authority) { List<GrantedAuthority> authorities = new ArrayList<>(); authorities.add(authority); return new User(professor.getUsername(), professor.getPasswordHash(), authorities); }