/** * Gets a string member of a JSON object as {@code java.net.URI}. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value, may be {@code null}. * * @throws ParseException If the value is not of the expected type. */ public static URI getURI(final JSONObject o, final String key) throws ParseException { String value = getString(o, key); if (value == null) { return null; } try { return new URI(value); } catch (URISyntaxException e) { throw new ParseException(e.getMessage(), 0); } }
header = header.type(new JOSEObjectType(JSONObjectUtils.getString(jsonObject, name))); } else if("cty".equals(name)) { header = header.contentType(JSONObjectUtils.getString(jsonObject, name)); } else if("crit".equals(name)) { header = header.criticalParams(new HashSet<>(JSONObjectUtils.getStringList(jsonObject, name)));
builder.issuer(JSONObjectUtils.getString(json, ISSUER_CLAIM)); builder.subject(JSONObjectUtils.getString(json, SUBJECT_CLAIM)); singleAud.add(JSONObjectUtils.getString(json, AUDIENCE_CLAIM)); builder.audience(singleAud); } else if (audValue instanceof List) { builder.jwtID(JSONObjectUtils.getString(json, JWT_ID_CLAIM));
/** * Parses the JWK type. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The key type. * * @throws ParseException If parsing failed. */ static KeyType parseKeyType(final JSONObject o) throws ParseException { return KeyType.parse(JSONObjectUtils.getString(o, "kty")); }
header = header.type(new JOSEObjectType(JSONObjectUtils.getString(jsonObject, name))); } else if("cty".equals(name)) { header = header.contentType(JSONObjectUtils.getString(jsonObject, name)); } else if("crit".equals(name)) { header = header.criticalParams(new HashSet<>(JSONObjectUtils.getStringList(jsonObject, name))); header = header.x509CertURL(JSONObjectUtils.getURI(jsonObject, name)); } else if("x5t".equals(name)) { header = header.x509CertThumbprint(new Base64URL(JSONObjectUtils.getString(jsonObject, name))); } else if("x5t#S256".equals(name)) { header = header.x509CertSHA256Thumbprint(new Base64URL(JSONObjectUtils.getString(jsonObject, name))); } else if("x5c".equals(name)) { header = header.x509CertChain(X509CertChainUtils.toBase64List(JSONObjectUtils.getJSONArray(jsonObject, name))); } else if("kid".equals(name)) { header = header.keyID(JSONObjectUtils.getString(jsonObject, name)); } else { header = header.customParam(name, jsonObject.get(name));
/** * Parses the optional key ID. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The key ID, {@code null} if not specified. * * @throws ParseException If parsing failed. */ static String parseKeyID(final JSONObject o) throws ParseException { if (o.containsKey("kid")) { return JSONObjectUtils.getString(o, "kid"); } else { return null; } }
header = header.type(new JOSEObjectType(JSONObjectUtils.getString(jsonObject, name))); } else if("cty".equals(name)) { header = header.contentType(JSONObjectUtils.getString(jsonObject, name)); } else if("crit".equals(name)) { header = header.criticalParams(new HashSet<>(JSONObjectUtils.getStringList(jsonObject, name))); header = header.x509CertURL(JSONObjectUtils.getURI(jsonObject, name)); } else if("x5t".equals(name)) { header = header.x509CertThumbprint(new Base64URL(JSONObjectUtils.getString(jsonObject, name))); } else if("x5t#S256".equals(name)) { header = header.x509CertSHA256Thumbprint(new Base64URL(JSONObjectUtils.getString(jsonObject, name))); } else if("x5c".equals(name)) { header = header.x509CertChain(X509CertChainUtils.toBase64List(JSONObjectUtils.getJSONArray(jsonObject, name))); } else if("kid".equals(name)) { header = header.keyID(JSONObjectUtils.getString(jsonObject, name)); } else if("epk".equals(name)) { header = header.ephemeralPublicKey(JWK.parse(JSONObjectUtils.getJSONObject(jsonObject, name))); } else if("zip".equals(name)) { header = header.compressionAlgorithm(new CompressionAlgorithm(JSONObjectUtils.getString(jsonObject, name))); } else if("apu".equals(name)) { header = header.agreementPartyUInfo(new Base64URL(JSONObjectUtils.getString(jsonObject, name))); } else if("apv".equals(name)) { header = header.agreementPartyVInfo(new Base64URL(JSONObjectUtils.getString(jsonObject, name))); } else if("p2s".equals(name)) { header = header.pbes2Salt(new Base64URL(JSONObjectUtils.getString(jsonObject, name))); } else if("p2c".equals(name)) { header = header.pbes2Count(JSONObjectUtils.getInt(jsonObject, name)); } else if("iv".equals(name)) { header = header.iv(new Base64URL(JSONObjectUtils.getString(jsonObject, name)));
/** * Parses an encryption method ({@code enc}) parameter from the * specified JWE header JSON object. * * @param json The JSON object to parse. Must not be {@code null}. * * @return The encryption method. * * @throws ParseException If the {@code enc} parameter couldn't be * parsed. */ private static EncryptionMethod parseEncryptionMethod(final JSONObject json) throws ParseException { return EncryptionMethod.parse(JSONObjectUtils.getString(json, "enc")); }
/** * Parses the optional algorithm. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The intended JOSE algorithm, {@code null} if not specified. * * @throws ParseException If parsing failed. */ static Algorithm parseAlgorithm(final JSONObject o) throws ParseException { if (o.containsKey("alg")) { return new Algorithm(JSONObjectUtils.getString(o, "alg")); } else { return null; } }
/** * Parses the optional X.509 certificate thumbprint. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The X.509 certificate thumbprint, {@code null} if not * specified. * * @throws ParseException If parsing failed. */ static Base64URL parseX509CertThumbprint(final JSONObject o) throws ParseException { if (o.containsKey("x5t")) { return new Base64URL(JSONObjectUtils.getString(o, "x5t")); } else { return null; } }
/** * Parses the optional X.509 certificate SHA-256 thumbprint. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The X.509 certificate SHA-256 thumbprint, {@code null} if * not specified. * * @throws ParseException If parsing failed. */ static Base64URL parseX509CertSHA256Thumbprint(final JSONObject o) throws ParseException { if (o.containsKey("x5t#S256")) { return new Base64URL(JSONObjectUtils.getString(o, "x5t#S256")); } else { return null; } }
/** * Parses the optional public key use. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The key use, {@code null} if not specified or if the key is * intended for signing as well as encryption. * * @throws ParseException If parsing failed. */ static KeyUse parseKeyUse(final JSONObject o) throws ParseException { if (o.containsKey("use")) { return KeyUse.parse(JSONObjectUtils.getString(o, "use")); } else { return null; } }
throws ParseException { String algName = JSONObjectUtils.getString(json, "alg");
Base64URL n = new Base64URL(JSONObjectUtils.getString(jsonObject, "n")); Base64URL e = new Base64URL(JSONObjectUtils.getString(jsonObject, "e")); KeyType kty = KeyType.parse(JSONObjectUtils.getString(jsonObject, "kty")); if (kty != KeyType.RSA) { throw new ParseException("The key type \"kty\" must be RSA", 0); d = new Base64URL(JSONObjectUtils.getString(jsonObject, "d")); p = new Base64URL(JSONObjectUtils.getString(jsonObject, "p")); q = new Base64URL(JSONObjectUtils.getString(jsonObject, "q")); dp = new Base64URL(JSONObjectUtils.getString(jsonObject, "dp")); dq = new Base64URL(JSONObjectUtils.getString(jsonObject, "dq")); qi = new Base64URL(JSONObjectUtils.getString(jsonObject, "qi")); JSONObject otherJson = (JSONObject)o; Base64URL r = new Base64URL(JSONObjectUtils.getString(otherJson, "r")); Base64URL odq = new Base64URL(JSONObjectUtils.getString(otherJson, "dq")); Base64URL t = new Base64URL(JSONObjectUtils.getString(otherJson, "t"));
throws ParseException { KeyType kty = KeyType.parse(JSONObjectUtils.getString(jsonObject, "kty"));
Base64URL k = new Base64URL(JSONObjectUtils.getString(jsonObject, "k"));