Last active
May 1, 2018 20:32
-
-
Save lusabo/d9f2562532e7aa38dd5271864c6a4610 to your computer and use it in GitHub Desktop.
JwtUserFactory
This file contains hidden or 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
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