use of org.jose4j.jwk.JsonWebKeySet in project cas by apereo.
the class OidcServiceJsonWebKeystoreCacheLoader method load.
@Override
public Optional<RsaJsonWebKey> load(final OidcRegisteredService svc) throws Exception {
final Optional<JsonWebKeySet> jwks = buildJsonWebKeySet(svc);
if (!jwks.isPresent() || jwks.get().getJsonWebKeys().isEmpty()) {
return Optional.empty();
}
final RsaJsonWebKey key = getJsonSigningWebKeyFromJwks(jwks.get());
if (key == null) {
return Optional.empty();
}
return Optional.of(key);
}
use of org.jose4j.jwk.JsonWebKeySet in project cas by apereo.
the class OidcDefaultJsonWebKeystoreCacheLoader method buildJsonWebKeySet.
private static JsonWebKeySet buildJsonWebKeySet(final String json) throws Exception {
final JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(json);
final RsaJsonWebKey webKey = getJsonSigningWebKeyFromJwks(jsonWebKeySet);
if (webKey == null || webKey.getPrivateKey() == null) {
LOGGER.warn("JSON web key retrieved [{}] is not found or has no associated private key", webKey);
return null;
}
return jsonWebKeySet;
}
use of org.jose4j.jwk.JsonWebKeySet in project cas by apereo.
the class OidcServiceJsonWebKeystoreCacheLoader method buildJsonWebKeySet.
private static JsonWebKeySet buildJsonWebKeySet(final String json) throws Exception {
final JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(json);
final RsaJsonWebKey webKey = getJsonSigningWebKeyFromJwks(jsonWebKeySet);
if (webKey == null || webKey.getPublicKey() == null) {
LOGGER.warn("JSON web key retrieved [{}] is not found or has no associated public key", webKey);
return null;
}
return jsonWebKeySet;
}
use of org.jose4j.jwk.JsonWebKeySet in project kafka by apache.
the class JwksFileVerificationKeyResolver method init.
@Override
public void init() throws IOException {
log.debug("Starting creation of new VerificationKeyResolver from {}", jwksFile);
String json = Utils.readFileAsString(jwksFile.toFile().getPath());
JsonWebKeySet jwks;
try {
jwks = new JsonWebKeySet(json);
} catch (JoseException e) {
throw new IOException(e);
}
delegate = new JwksVerificationKeyResolver(jwks.getJsonWebKeys());
}
use of org.jose4j.jwk.JsonWebKeySet in project tomee by apache.
the class PublicKeyResolver method parseJwks.
private Map<String, Key> parseJwks(final String publicKey) {
final JsonObject jwks;
try {
jwks = Json.createReader(new StringReader(publicKey)).readObject();
} catch (final JsonParsingException e) {
return Collections.emptyMap();
}
try {
final JsonArray keys = jwks.getJsonArray(JWK_SET_MEMBER_NAME);
for (final JsonValue key : keys) {
validateJwk(key.asJsonObject());
}
} catch (final Exception e) {
throw new DeploymentException("MicroProfile Public Key JWKS invalid format.");
}
try {
final JsonWebKeySet keySet = new JsonWebKeySet(publicKey);
final Map<String, Key> keys = keySet.getJsonWebKeys().stream().collect(Collectors.toMap(JsonWebKey::getKeyId, JsonWebKey::getKey));
return Collections.unmodifiableMap(keys);
} catch (final JoseException e) {
throw new DeploymentException(JWTAuthConfigurationProperties.PUBLIC_KEY_ERROR + " JWK.", e);
}
}
Aggregations