Skip to content

Instantly share code, notes, and snippets.

@lusabo
Last active May 1, 2018 20:32
Show Gist options
  • Save lusabo/d9f2562532e7aa38dd5271864c6a4610 to your computer and use it in GitHub Desktop.
Save lusabo/d9f2562532e7aa38dd5271864c6a4610 to your computer and use it in GitHub Desktop.
JwtUserFactory
package com.eco.security;
// Imports
public class JwtUserFactory {
private JwtUserFactory() {
}
/*
* Converte e gera um JwtUser com base nos dados de um usuário.
*/
public static JwtUser create(User user) {
return new JwtUser(user.getId(), user.getUsername(), user.getPassword(),
mapToGrantedAuthorities(user.getProfile()));
}
/*
* Converte o perfil do usuário para o formato utilizado pelo Spring Security.
*/
private static List<GrantedAuthority> mapToGrantedAuthorities(Profile profile) {
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority(profile.toString()));
return authorities;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment