/** * Returns a {@link Attributes} instance based on the given {@link JsonObject}. * * @param claims a json object with the claims to extract * @return an {@link Attributes} instance with attributes from the given json object */ public static Attributes toAttributes(JsonObject claims) { return claims.entrySet().stream().reduce(new MapAttributes(), (mapAttributes, entry) -> { String claimName = entry.getKey(); JsonValue claimValue = entry.getValue(); if (JsonValue.ValueType.ARRAY.equals(claimValue.getValueType())) { JsonArray jsonArray = claims.getJsonArray(claimName); jsonArray.forEach(arrayValue -> mapAttributes.addLast(claimName, asString(arrayValue))); } else { mapAttributes.addLast(claimName, asString(claimValue)); } return mapAttributes; }, (mapAttributes, mapAttributes2) -> mapAttributes); }
private boolean hasValidAudience(JsonObject claims) throws RealmUnavailableException { if (this.audiences.isEmpty()) return true; JsonValue audience = claims.get("aud"); if (audience == null) { log.debug("Token does not contain an audience claim"); return false; } JsonArray audClaimArray; if (JsonValue.ValueType.STRING.equals(audience.getValueType())) { audClaimArray = Json.createArrayBuilder().add(audience).build(); } else { audClaimArray = (JsonArray) audience; } boolean valid = audClaimArray.stream() .map(jsonValue -> (JsonString) jsonValue) .anyMatch(audience1 -> audiences.contains(audience1.getString())); if (!valid) { log.debugf("Audience check failed. Provided [%s] but was expected [%s].", audClaimArray.toArray(), this.audiences); } return valid; }
private JsonObject getFirstJwk(final JsonObject jwks, final JsonArray keys) { if (keys.size() == 0) { throw new IllegalArgumentException("Invalid JWKS; 'keys' entry is empty.\n" + jwks.toString()); } final JsonValue value = keys.get(0); if (!JsonValue.ValueType.OBJECT.equals(value.getValueType())) { throw new IllegalArgumentException("Invalid JWKS; 'keys' array should contain jwk objects.\n" + jwks.toString()); } return value.asJsonObject(); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }
private Map<String, String> jsonToMap(JsonObject jsonOutput) { Map<String, String> resultMap = new HashMap<>(); for(String key:jsonOutput.keySet()) { JsonValue value = jsonOutput.get(key); if(value.getValueType() == ValueType.STRING) { resultMap.put(key, jsonOutput.getString(key)); } else if (!value.getValueType().equals(ValueType.OBJECT)&&!value.getValueType().equals(ValueType.ARRAY)) { resultMap.put(key, jsonOutput.getString(key).toString()); } } return resultMap; }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
/** * {@inheritDoc} */ @Override protected Boolean convert(JsonValue jsonValue) { if (jsonValue.getValueType().equals(ValueType.NUMBER)) { return ((JsonNumber) jsonValue).intValue() > 0; } return jsonValue.equals(JsonValue.TRUE); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
@Override public boolean equals(final Object obj) { return obj instanceof JsonValue && getValueType().equals(JsonValue.class.cast(obj).getValueType()); }
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }
/** * Compares the specified object with this {@link JsonValue} * object for equality. Returns {@code true} if and only if the * specified object is also a JsonValue, and their * {@link #getValueType()} objects are <i>equal</i>. * * @param obj the object to be compared for equality with this JsonValue * @return {@code true} if the specified object is equal to this * JsonValue */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof JsonValue) { return getValueType().equals(((JsonValue) obj).getValueType()); } return false; }
private static String asString(JsonValue value) { if (JsonValue.ValueType.STRING.equals(value.getValueType())) { return ((JsonString) value).getString(); } return value.toString(); } }