protected Map<String, Object> decode(String token) { try { Jwt jwt = JwtHelper.decodeAndVerify(token, verifier); String claimsStr = jwt.getClaims(); Map<String, Object> claims = objectMapper.parseMap(claimsStr); if (claims.containsKey(EXP) && claims.get(EXP) instanceof Integer) { Integer intValue = (Integer) claims.get(EXP); claims.put(EXP, new Long(intValue)); } this.getJwtClaimsSetVerifier().verify(claims); return claims; } catch (Exception e) { throw new InvalidTokenException("Cannot convert access token to JSON", e); } }
private Map<String, Object> decodeJwtMap(final String token, final OAuthPublicKey keyExchangePublicKey) { final RsaVerifier rsaVerifier = new RsaVerifier(keyExchangePublicKey.getPublicKey()); final Jwt jwt = JwtHelper.decodeAndVerify(token, rsaVerifier); final String content = jwt.getClaims(); final Map<String, Object> map = objectMapper.parseMap(content); if (map.containsKey(EXP) && map.get(EXP) instanceof Integer) { final Integer intValue = (Integer) map.get(EXP); map.put(EXP, Long.valueOf(intValue)); } return map; } }
public Map<String, Object> decodeAndVerify (String token) { File file = new File(PUBLIC_KEY_LOCATION); try (FileInputStream inputStream = new FileInputStream(file)) { CertificateFactory certificateFactory = CertificateFactory.getInstance(X509_CERTFICATE); Certificate certificate = certificateFactory.generateCertificate(inputStream); RSAPublicKeyImpl publicKey = (RSAPublicKeyImpl) certificate.getPublicKey(); RsaVerifier verifier = new RsaVerifier(publicKey); Jwt jwt = JwtHelper.decodeAndVerify(token, verifier); String content = jwt.getClaims(); Map<String, Object> map = objectMapper.parseMap(content); if (map.containsKey(EXP) && map.get(EXP) instanceof Integer) { Integer intValue = (Integer) map.get(EXP); map.put(EXP, new Long(intValue)); } return map; } catch (Exception e) { throw new InvalidTokenException("Cannot convert access token to JSON", e); } } }
protected Map<String, Object> decode(String token) { try { Jwt jwt = JwtHelper.decodeAndVerify(token, verifier); String claimsStr = jwt.getClaims(); Map<String, Object> claims = objectMapper.parseMap(claimsStr); if (claims.containsKey(EXP) && claims.get(EXP) instanceof Integer) { Integer intValue = (Integer) claims.get(EXP); claims.put(EXP, new Long(intValue)); } this.getJwtClaimsSetVerifier().verify(claims); return claims; } catch (Exception e) { throw new InvalidTokenException("Cannot convert access token to JSON", e); } }
private void decodeAndVerify(String tokenString) { try { JwtHelper.decodeAndVerify(tokenString, getSignatureVerifier(getCachedTokenKey())); } catch (InvalidSignatureException e) { throw new InvalidTokenException(e.getMessage(), e); } }
@Test public void tokenWhenUsingClientCredentialsThenIsValid() throws Exception { MvcResult result = this.mvc .perform(post("/oauth/token").with(CLIENT_CREDENTIALS) .param("grant_type", "client_credentials").param("scope", "any")) .andExpect(status().isOk()).andReturn(); String accessToken = extract(result, "access_token"); JwtHelper.decodeAndVerify(accessToken, new RsaVerifier(privateKeyValue)); }