@Test public void retrieveTokenKeysForNewKeyId() throws OAuth2ServiceException, InvalidKeySpecException, NoSuchAlgorithmException { cut.getPublicKey(JwtSignatureAlgorithm.RS256, "key-id-0", TOKEN_KEYS_URI); cut.getPublicKey(JwtSignatureAlgorithm.RS256, "not-seen-yet", TOKEN_KEYS_URI); verify(tokenKeyServiceMock, times(2)).retrieveTokenKeys(any()); }
@Nullable public PublicKey getPublicKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI keyUri) throws OAuth2ServiceException, InvalidKeySpecException, NoSuchAlgorithmException { assertNotNull(keyAlgorithm, "keyAlgorithm must not be null."); assertHasText(keyId, "keyId must not be null."); assertNotNull(keyUri, "keyUrl must not be null."); String cacheKey = getUniqueCacheKey(keyAlgorithm, keyId, keyUri); PublicKey publicKey = getCache().getIfPresent(cacheKey); if (publicKey == null) { retrieveTokenKeysAndFillCache(keyUri); } return getCache().getIfPresent(cacheKey); }
OAuth2TokenKeyServiceWithCache implements Cacheable { @Nullable public PublicKey getPublicKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI keyUri) throws OAuth2ServiceException, InvalidKeySpecException, NoSuchAlgorithmException { assertNotNull(keyAlgorithm, "keyAlgorithm must not be null."); assertHasText(keyId, "keyId must not be null."); assertNotNull(keyUri, "keyUrl must not be null."); String cacheKey = getUniqueCacheKey(keyAlgorithm, keyId, keyUri); PublicKey publicKey = getCache().getIfPresent(cacheKey); if (publicKey == null) { retrieveTokenKeysAndFillCache(keyUri); } return getCache().getIfPresent(cacheKey); } }
OAuth2TokenKeyServiceWithCache implements Cacheable { @Nullable public PublicKey getPublicKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI keyUri) throws OAuth2ServiceException, InvalidKeySpecException, NoSuchAlgorithmException { assertNotNull(keyAlgorithm, "keyAlgorithm must not be null."); assertHasText(keyId, "keyId must not be null."); assertNotNull(keyUri, "keyUrl must not be null."); String cacheKey = getUniqueCacheKey(keyAlgorithm, keyId, keyUri); PublicKey publicKey = getCache().getIfPresent(cacheKey); if (publicKey == null) { retrieveTokenKeysAndFillCache(keyUri); } return getCache().getIfPresent(cacheKey); } private  OAuth2TokenKeyServiceWithCache(); }
OAuth2TokenKeyServiceWithCache implements Cacheable { @Nullable public PublicKey getPublicKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI keyUri) throws OAuth2ServiceException, InvalidKeySpecException, NoSuchAlgorithmException { assertNotNull(keyAlgorithm, "keyAlgorithm must not be null."); assertHasText(keyId, "keyId must not be null."); assertNotNull(keyUri, "keyUrl must not be null."); String cacheKey = getUniqueCacheKey(keyAlgorithm, keyId, keyUri); PublicKey publicKey = getCache().getIfPresent(cacheKey); if (publicKey == null) { retrieveTokenKeysAndFillCache(keyUri); } return getCache().getIfPresent(cacheKey); } private  OAuth2TokenKeyServiceWithCache(); static OAuth2TokenKeyServiceWithCache getInstance(); @Deprecated OAuth2TokenKeyServiceWithCache withCacheTime(int timeInSeconds); @Deprecated OAuth2TokenKeyServiceWithCache withCacheSize(int size); OAuth2TokenKeyServiceWithCache withCacheConfiguration(CacheConfiguration cacheConfiguration); OAuth2TokenKeyServiceWithCache withTokenKeyService(OAuth2TokenKeyService tokenKeyService); @Nullable PublicKey getPublicKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI keyUri); @Nonnull @Override CacheConfiguration getCacheConfiguration(); @Override void clearCache(); @Override Object getCacheStatistics(); static String getUniqueCacheKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI jwksUri); }
OAuth2TokenKeyServiceWithCache implements Cacheable { @Nullable public PublicKey getPublicKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI keyUri) throws OAuth2ServiceException, InvalidKeySpecException, NoSuchAlgorithmException { assertNotNull(keyAlgorithm, "keyAlgorithm must not be null."); assertHasText(keyId, "keyId must not be null."); assertNotNull(keyUri, "keyUrl must not be null."); String cacheKey = getUniqueCacheKey(keyAlgorithm, keyId, keyUri); PublicKey publicKey = getCache().getIfPresent(cacheKey); if (publicKey == null) { retrieveTokenKeysAndFillCache(keyUri); } return getCache().getIfPresent(cacheKey); } private  OAuth2TokenKeyServiceWithCache(); static OAuth2TokenKeyServiceWithCache getInstance(); @Deprecated OAuth2TokenKeyServiceWithCache withCacheTime(int timeInSeconds); @Deprecated OAuth2TokenKeyServiceWithCache withCacheSize(int size); OAuth2TokenKeyServiceWithCache withCacheConfiguration(CacheConfiguration cacheConfiguration); OAuth2TokenKeyServiceWithCache withTokenKeyService(OAuth2TokenKeyService tokenKeyService); @Nullable PublicKey getPublicKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI keyUri); @Nonnull @Override CacheConfiguration getCacheConfiguration(); @Override void clearCache(); @Override Object getCacheStatistics(); static String getUniqueCacheKey(JwtSignatureAlgorithm keyAlgorithm, String keyId, URI jwksUri);  }