@Override public PublicKey getPublicKey(String kid, KeycloakDeployment deployment) { int minTimeBetweenRequests = deployment.getMinTimeBetweenJwksRequests(); int publicKeyCacheTtl = deployment.getPublicKeyCacheTtl(); int currentTime = Time.currentTime(); // Check if key is in cache. PublicKey publicKey = lookupCachedKey(publicKeyCacheTtl, currentTime, kid); if (publicKey != null) { return publicKey; } // Check if we are allowed to send request synchronized (this) { currentTime = Time.currentTime(); if (currentTime > lastRequestTime + minTimeBetweenRequests) { sendRequest(deployment); lastRequestTime = currentTime; } else { log.debug("Won't send request to realm jwks url. Last request time was " + lastRequestTime); } return lookupCachedKey(publicKeyCacheTtl, currentTime, kid); } }
@Override public void reset(KeycloakDeployment deployment) { synchronized (this) { sendRequest(deployment); lastRequestTime = Time.currentTime(); } }
JWKPublicKeyLocator pkLocator = new JWKPublicKeyLocator(); deployment.setPublicKeyLocator(pkLocator);