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