Created
October 25, 2015 22:25
-
-
Save gregori/632cba31c881684ca229 to your computer and use it in GitHub Desktop.
Passo 3a
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
@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