@Test(expected = UnresolvableKeyException.class) public void testLoadHttpsJwksNonMathchingKidAndRefreshDeclined() throws Exception { JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(); contextInfo.setDecryptionKeyLocation("https: contextInfo.setJwksRefreshInterval(10); contextInfo.setForcedJwksRefreshInterval(10); DecryptionKeyLocationResolver keyLocationResolver = new DecryptionKeyLocationResolver(contextInfo) { protected HttpsJwks initializeHttpsJwks(String loc) { return mockedHttpsJwks; } }; when(encryption.getHeaders()).thenReturn(headers); when(headers.getStringHeaderValue(JsonWebKey.KEY_ID_PARAMETER)).thenReturn("1"); RsaJsonWebKey jwk = RsaJwkGenerator.generateJwk(2048); jwk.setKeyId("2"); when(mockedHttpsJwks.getJsonWebKeys()).thenReturn(Collections.singletonList(jwk)); doAnswer((i) -> { jwk.setKeyId("1"); return null; }).when(mockedHttpsJwks).refresh(); keyLocationResolver = Mockito.spy(keyLocationResolver); assertEquals(jwk.getPrivateKey(), keyLocationResolver.resolveKey(encryption, emptyList())); assertNull(keyLocationResolver.key); jwk.setKeyId("2"); keyLocationResolver.resolveKey(encryption, emptyList()); }
@Override public Key resolveKey(JsonWebEncryption jwe, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jwe, authContextInfo.getTokenDecryptionKeyId()); if (key != null) { return key; } Key theKey = tryAsDecryptionJwk(jwe); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getDecryptionKeyContent(), authContextInfo.getDecryptionKeyLocation()); } return theKey; }
DecryptionKeyLocationResolver extends AbstractKeyLocationResolver implements DecryptionKeyResolver { @Override public Key resolveKey(JsonWebEncryption jwe, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jwe, authContextInfo.getTokenDecryptionKeyId()); if (key != null) { return key; } Key theKey = tryAsDecryptionJwk(jwe); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getDecryptionKeyContent(), authContextInfo.getDecryptionKeyLocation()); } return theKey; } }
DecryptionKeyLocationResolver extends AbstractKeyLocationResolver implements DecryptionKeyResolver { @Override public Key resolveKey(JsonWebEncryption jwe, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jwe, authContextInfo.getTokenDecryptionKeyId()); if (key != null) { return key; } Key theKey = tryAsDecryptionJwk(jwe); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getDecryptionKeyContent(), authContextInfo.getDecryptionKeyLocation()); } return theKey; } DecryptionKeyLocationResolver(JWTAuthContextInfo authContextInfo); }
DecryptionKeyLocationResolver extends AbstractKeyLocationResolver implements DecryptionKeyResolver { @Override public Key resolveKey(JsonWebEncryption jwe, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jwe, authContextInfo.getTokenDecryptionKeyId()); if (key != null) { return key; } Key theKey = tryAsDecryptionJwk(jwe); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getDecryptionKeyContent(), authContextInfo.getDecryptionKeyLocation()); } return theKey; } DecryptionKeyLocationResolver(JWTAuthContextInfo authContextInfo); @Override Key resolveKey(JsonWebEncryption jwe, List<JsonWebStructure> nestingContext); }
DecryptionKeyLocationResolver extends AbstractKeyLocationResolver implements DecryptionKeyResolver { @Override public Key resolveKey(JsonWebEncryption jwe, List<JsonWebStructure> nestingContext) throws UnresolvableKeyException { verifyKid(jwe, authContextInfo.getTokenDecryptionKeyId()); if (key != null) { return key; } Key theKey = tryAsDecryptionJwk(jwe); if (theKey == null) { reportUnresolvableKeyException(authContextInfo.getDecryptionKeyContent(), authContextInfo.getDecryptionKeyLocation()); } return theKey; } DecryptionKeyLocationResolver(JWTAuthContextInfo authContextInfo); @Override Key resolveKey(JsonWebEncryption jwe, List<JsonWebStructure> nestingContext);  }