UaaTokenUtils { public static Map<String, Object> getClaims(String jwtToken) { Jwt jwt; try { jwt = JwtHelper.decode(jwtToken); } catch (Exception ex) { throw new InvalidTokenException("Invalid token (could not decode): " + jwtToken, ex); } Map<String, Object> claims; try { claims = JsonUtils.readValue(jwt.getClaims(), new TypeReference<Map<String, Object>>() { }); } catch (JsonUtils.JsonUtilException ex) { throw new InvalidTokenException("Invalid token (cannot read token claims): " + jwtToken, ex); } return claims != null ? claims : new HashMap<>(); } private  UaaTokenUtils(); static String getRevocationHash(List<String> salts); static int murmurhash3x8632(byte[] data, int offset, int len, int seed); static Set<String> retainAutoApprovedScopes(Collection<String> requestedScopes, Set<String> autoApprovedScopes); static boolean isUserToken(Map<String, Object> claims); static String getRevocableTokenSignature(ClientDetails client, String clientSecret, UaaUser user); static String getRevocableTokenSignature(UaaUser user, String tokenSalt, String clientId, String clientSecret); static String constructToken(Map<String, Object> header, Map<String, Object> claims, Signer signer); static boolean isJwtToken(String token); static String constructTokenEndpointUrl(String issuer, IdentityZone identityZone); static boolean hasRequiredUserAuthorities(Collection<String> requiredGroups, Collection<? extends GrantedAuthority> userGroups); static boolean hasRequiredUserGroups(Collection<String> requiredGroups, Collection<String> userGroups); static Map<String, Object> getClaims(String jwtToken); static final Pattern jwtPattern; }
@Test public void getClaims() { Map<String, Object> headers = new HashMap<>(); headers.put("kid", "some-key"); headers.put("alg", "HS256"); Map<String, Object> content = new HashMap<>(); content.put("cid", "openidclient"); content.put("origin", "uaa"); String jwt = UaaTokenUtils.constructToken(headers, content, new MacSigner("foobar")); Map<String, Object> claims = UaaTokenUtils.getClaims(jwt); assertEquals(claims.get("cid"), "openidclient"); assertEquals(claims.get("origin"), "uaa"); }
@Test(expected = InvalidTokenException.class) public void getClaims_throwsExceptionWhenJwtIsMalformed() { UaaTokenUtils.getClaims("not.a.jwt"); }
@Test(expected = InvalidTokenException.class) public void getClaims_throwsExceptionWhenClaimsCannotBeRead() { Jwt encoded = JwtHelper.encode("great content", KeyInfoBuilder.build("foo", "bar", "https: UaaTokenUtils.getClaims(encoded.getEncoded()); }