Skip to content

Instantly share code, notes, and snippets.

@gregori
Created October 25, 2015 22:25
Show Gist options
  • Save gregori/632cba31c881684ca229 to your computer and use it in GitHub Desktop.
Save gregori/632cba31c881684ca229 to your computer and use it in GitHub Desktop.
Passo 3a
@Service
public class FakeUserDetailsService implements UserDetailsService {
@Autowired
private PessoaRepository personRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Pessoa person = personRepository.findByNome(username);
if (person == null) {
throw new UsernameNotFoundException("Username " + username + " não encontrado");
}
return new User(username, "password", getGrantedAuthorities(username));
}
private Collection<? extends GrantedAuthority> getGrantedAuthorities(String username) {
Collection<? extends GrantedAuthority> authorities;
if (username.equals("Rodrigo")) {
authorities = asList(() -> "ROLE_ADMIN", () -> "ROLE_BASIC");
} else {
authorities = asList(() -> "ROLE_BASIC");
}
return authorities;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment