Skip to content

Commit

Permalink
Handle both JWK and JWKS
Browse files Browse the repository at this point in the history
Handle classpath: prefix for resource paths
  • Loading branch information
starksm64 committed May 3, 2018
1 parent 5ef1c7b commit 587b657
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ public static PublicKey decodePublicKey(String pemEncoded) throws Exception {
}

/**
* Decode a JWKS encoded public key string to an RSA PublicKey
* Decode a JWK(S) encoded public key string to an RSA PublicKey
* @param jwksValue - JWKS string value
* @return PublicKey from RSAPublicKeySpec
*/
public static PublicKey decodeJWKSPublicKey(String jwksValue) throws Exception {
JsonObject jwks = Json.createReader(new StringReader(jwksValue)).readObject();
JsonArray keys = jwks.getJsonArray("keys");
JsonObject jwk = keys.getJsonObject(0);
JsonObject jwk;
if(keys != null) {
jwk = keys.getJsonObject(0);
}
else {
jwk = jwks;
}
String e = jwk.getString("e");
String n = jwk.getString("n");

Expand Down Expand Up @@ -97,6 +103,10 @@ private static String removeBeginEnd(String pem) {
* @throws IOException - on failure
*/
public static String readResource(String resName) throws IOException {
// Strip any classpath: prefix
if(resName.startsWith("classpath:")) {
resName = resName.substring(10);
}
InputStream is = SimpleTokenUtils.class.getResourceAsStream(resName);
StringWriter sw = new StringWriter();
try(BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
Expand Down

0 comments on commit 587b657

Please sign in to comment.