@Test public void testLoadJWKOnClassPath() throws Exception { JWTAuthContextInfo contextInfo = new JWTAuthContextInfo("publicKey.jwk", "issuer"); contextInfo.setTokenKeyId("key1"); KeyLocationResolver keyLocationResolver = new KeyLocationResolver(contextInfo); when(signature.getHeaders()).thenReturn(headers); when(headers.getStringHeaderValue(JsonWebKey.KEY_ID_PARAMETER)).thenReturn("key1"); assertNotNull(keyLocationResolver.key); assertEquals(keyLocationResolver.key, keyLocationResolver.resolveKey(signature, emptyList())); assertEquals(keyLocationResolver.key, keyLocationResolver.getJsonWebKey("key1", null).getKey()); }
@Override public Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jws, authContextInfo.getTokenKeyId()); if (key != null) { return key; } Key theKey = tryAsVerificationJwk(jws); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getPublicKeyContent(), authContextInfo.getPublicKeyLocation()); } return theKey; }
KeyLocationResolver extends AbstractKeyLocationResolver implements VerificationKeyResolver { @Override public Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jws, authContextInfo.getTokenKeyId()); if (key != null) { return key; } Key theKey = tryAsVerificationJwk(jws); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getPublicKeyContent(), authContextInfo.getPublicKeyLocation()); } return theKey; } }
KeyLocationResolver extends AbstractKeyLocationResolver implements VerificationKeyResolver { @Override public Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jws, authContextInfo.getTokenKeyId()); if (key != null) { return key; } Key theKey = tryAsVerificationJwk(jws); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getPublicKeyContent(), authContextInfo.getPublicKeyLocation()); } return theKey; } KeyLocationResolver(JWTAuthContextInfo authContextInfo); }
KeyLocationResolver extends AbstractKeyLocationResolver implements VerificationKeyResolver { @Override public Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jws, authContextInfo.getTokenKeyId()); if (key != null) { return key; } Key theKey = tryAsVerificationJwk(jws); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getPublicKeyContent(), authContextInfo.getPublicKeyLocation()); } return theKey; } KeyLocationResolver(JWTAuthContextInfo authContextInfo); @Override Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContext); }
KeyLocationResolver extends AbstractKeyLocationResolver implements VerificationKeyResolver { @Override public Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jws, authContextInfo.getTokenKeyId()); if (key != null) { return key; } Key theKey = tryAsVerificationJwk(jws); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getPublicKeyContent(), authContextInfo.getPublicKeyLocation()); } return theKey; } KeyLocationResolver(JWTAuthContextInfo authContextInfo); @Override Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContext);  }