diff --git a/java/mtsj/core/src/main/java/io/oasp/application/mtsj/general/security/TokenAuthenticationService.java b/java/mtsj/core/src/main/java/io/oasp/application/mtsj/general/security/TokenAuthenticationService.java index 9e7e59312..1504fe5cf 100644 --- a/java/mtsj/core/src/main/java/io/oasp/application/mtsj/general/security/TokenAuthenticationService.java +++ b/java/mtsj/core/src/main/java/io/oasp/application/mtsj/general/security/TokenAuthenticationService.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -54,6 +53,8 @@ public class TokenAuthenticationService { static final String CLAIM_SCOPE = "scope"; + static final String CLAIM_ROLES = "roles"; + /** * This method returns the token once the Authentication has been successful * @@ -110,7 +111,8 @@ static String generateToken(Authentication auth) { Map claims = new HashMap<>(); claims.put(CLAIM_ISSUER, ISSUER); claims.put(CLAIM_SUBJECT, auth.getName()); - claims.put(CLAIM_SCOPE, auth.getAuthorities()); + claims.put(CLAIM_SCOPE, scopes); + claims.put(CLAIM_ROLES, scopes); claims.put(CLAIM_CREATED, generateCreationDate() / 1000); claims.put(CLAIM_EXPIRATION, generateExpirationDate() / 1000); LOG.info(claims.toString()); @@ -162,15 +164,8 @@ public static UserDetailsClientTo getUserdetailsFromToken(String token) { static List getRolesFromToken(String token) { - List scopes = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token.replace(TOKEN_PREFIX, "")) - .getBody().get(CLAIM_SCOPE, List.class); - - List roles = new ArrayList<>(); - for (LinkedHashMap scope : scopes) { - roles.add(scope.get("authority").toString()); - } - - return roles; + return Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token.replace(TOKEN_PREFIX, "")).getBody() + .get(CLAIM_SCOPE, List.class); } }