/** * Use {@link #parse(String)} instead. * * @param s The JSON object string to parse. Must not be {@code null}. * * @return The JSON object. * * @throws ParseException If the string cannot be parsed to a valid JSON * object. */ @Deprecated public static JSONObject parseJSONObject(final String s) throws ParseException { return parse(s); }
/** * Gets a JSON object member of a JSON object. * * @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 JSONObject getJSONObject(final JSONObject o, final String key) throws ParseException { return getGeneric(o, key, JSONObject.class); }
/** * 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))); } else if("jku".equals(name)) { header = header.jwkURL(JSONObjectUtils.getURI(jsonObject, name)); } else if("jwk".equals(name)) { header = header.jwk(JWK.parse(JSONObjectUtils.getJSONObject(jsonObject, name))); } else if("x5u".equals(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));
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.audience(JSONObjectUtils.getStringList(json, AUDIENCE_CLAIM)); } else if (audValue == null) { builder.audience((String)null); builder.expirationTime(new Date(JSONObjectUtils.getLong(json, EXPIRATION_TIME_CLAIM) * 1000)); builder.notBeforeTime(new Date(JSONObjectUtils.getLong(json, NOT_BEFORE_CLAIM) * 1000)); builder.issueTime(new Date(JSONObjectUtils.getLong(json, ISSUED_AT_CLAIM) * 1000)); builder.jwtID(JSONObjectUtils.getString(json, JWT_ID_CLAIM));
private Map<String, Object> getIdTokenClaims(AuthenticationContext context, String idToken) { context.setProperty(OIDCAuthenticatorConstants.ID_TOKEN, idToken); String base64Body = idToken.split("\\.")[1]; byte[] decoded = Base64.decodeBase64(base64Body.getBytes()); Set<Map.Entry<String, Object>> jwtAttributeSet = new HashSet<>(); try { jwtAttributeSet = JSONObjectUtils.parseJSONObject(new String(decoded)).entrySet(); } catch (ParseException e) { log.error("Error occurred while parsing JWT provided by federated IDP: ", e); } Map<String, Object> jwtAttributeMap = new HashMap(); for(Map.Entry<String, Object> entry : jwtAttributeSet) { jwtAttributeMap.put(entry.getKey(), entry.getValue()); } return jwtAttributeMap; }
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))); } else { header = header.customParam(name, jsonObject.get(name));
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")); if (jsonObject.containsKey("oth")) { JSONArray arr = JSONObjectUtils.getJSONArray(jsonObject, "oth"); oth = new ArrayList<>(arr.size()); Base64URL r = new Base64URL(JSONObjectUtils.getString(otherJson, "r")); Base64URL odq = new Base64URL(JSONObjectUtils.getString(otherJson, "dq")); Base64URL t = new Base64URL(JSONObjectUtils.getString(otherJson, "t"));
/** * Gets a string array member of a JSON object. * * @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 String[] getStringArray(final JSONObject o, final String key) throws ParseException { JSONArray jsonArray = getJSONArray(o, key); if (jsonArray == null) { return null; } try { return jsonArray.toArray(new String[0]); } catch (ArrayStoreException e) { throw new ParseException("JSON object member with key \"" + key + "\" is not an array of strings", 0); } }
/** * Gets a string list member of a JSON object * * @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 List<String> getStringList(final JSONObject o, final String key) throws ParseException { String[] array = getStringArray(o, key); if (array == null) { return null; } return Arrays.asList(array); }
/** * Parses the optional key operations. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The key operations, {@code null} if not specified. * * @throws ParseException If parsing failed. */ static Set<KeyOperation> parseKeyOperations(final JSONObject o) throws ParseException { if(o.containsKey("key_ops")) { return KeyOperation.parse(JSONObjectUtils.getStringList(o, "key_ops")); } 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))); } else if("jku".equals(name)) { header = header.jwkURL(JSONObjectUtils.getURI(jsonObject, name)); } else if("jwk".equals(name)) { header = header.jwk(JWK.parse(JSONObjectUtils.getJSONObject(jsonObject, name))); } else if("x5u".equals(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)));
final JSONObject internal = JSONObjectUtils.parseJSONObject(String.valueOf(claims.getClaim(Claims.TAG_INTERNAL.getName())));
/** * Parses the optional X.509 certificate chain. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The X.509 certificate chain (containing at least one * certificate) as a unmodifiable list, {@code null} if not * specified. * * @throws ParseException If parsing failed. */ static List<Base64> parseX509CertChain(final JSONObject o) throws ParseException { if (o.containsKey("x5c")) { List<Base64> chain = X509CertChainUtils.toBase64List(JSONObjectUtils.getJSONArray(o, "x5c")); if (chain.isEmpty()) { throw new ParseException("The X.509 certificate chain \"x5c\" must not be empty", 0); } return chain; } else { return null; } } }
/** * Parses the specified string representing a JSON Web Key (JWK) set. * * @param s The string to parse. Must not be {@code null}. * * @return The JWK set. * * @throws ParseException If the string couldn't be parsed to a valid * JSON Web Key (JWK) set. */ public static JWKSet parse(final String s) throws ParseException { return parse(JSONObjectUtils.parse(s)); }
/** * 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")); }
final ReadOnlyJWTClaimsSet previousCS = signedPreviousRT.getJWTClaimsSet(); final String tagInternalPayload = String.valueOf(previousCS.getClaim(Claims.TAG_INTERNAL.getName())); final JSONObject tagInternal = JSONObjectUtils.parseJSONObject(tagInternalPayload);
/** * Gets a string member of a JSON object. * * @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 String getString(final JSONObject o, final String key) throws ParseException { return getGeneric(o, key, String.class); }
throws ParseException { JSONArray keyArray = JSONObjectUtils.getJSONArray(json, "keys");
/** * Parses a JWE header from the specified JSON object string. * * @param jsonString The JSON object string to parse. Must not be {@code null}. * * @return The JWE header. * * @throws ParseException If the specified JSON object string doesn't * represent a valid JWE header. */ public static JWEHeader parse(final String jsonString) throws ParseException { return parse(JSONObjectUtils.parse(jsonString), null); }