@Test public void testLoadSecretKeyFromHttpsJwks() throws Exception { JWTAuthContextInfo contextInfo = new JWTAuthContextInfo("https: contextInfo.setJwksRefreshInterval(10); KeyLocationResolver keyLocationResolver = new KeyLocationResolver(contextInfo) { protected HttpsJwks initializeHttpsJwks(String loc) { return mockedHttpsJwks; } }; OctetSequenceJsonWebKey jwk = new OctetSequenceJsonWebKey(secretKey); jwk.setKeyId("1"); when(mockedHttpsJwks.getJsonWebKeys()).thenReturn(Collections.singletonList(jwk)); keyLocationResolver = Mockito.spy(keyLocationResolver); when(signature.getHeaders()).thenReturn(headers); when(headers.getStringHeaderValue(JsonWebKey.KEY_ID_PARAMETER)).thenReturn("1"); assertEquals(secretKey, keyLocationResolver.resolveKey(signature, emptyList())); assertNull(keyLocationResolver.key); }
@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);  }