diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/CallbackUrlBehavior.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/CallbackUrlBehavior.java index 8f2c50f0f..d08be7111 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/CallbackUrlBehavior.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/CallbackUrlBehavior.java @@ -49,6 +49,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -65,7 +66,10 @@ public class CallbackUrlBehavior { private LocalizationProvider localizationProvider; private PowerAuthServiceConfiguration configuration; - private final Map restClientCache = new HashMap<>(); + // Store REST clients in cache with their callback ID as a key + private final Map restClientCache = new ConcurrentHashMap<>(); + private final Object restClientCacheLock = new Object(); + private final CallbackAuthenticationPublicConverter authenticationPublicConverter = new CallbackAuthenticationPublicConverter(); // Prepare logger @@ -170,6 +174,8 @@ public UpdateCallbackUrlResponse updateCallbackUrl(UpdateCallbackUrlRequest requ } final CallbackUrlEntity entity = entityOptional.get(); + evictRestClientFromCache(entity); + entity.setName(request.getName()); entity.setCallbackUrl(request.getCallbackUrl()); entity.setAttributes(request.getAttributes()); @@ -244,7 +250,9 @@ public RemoveCallbackUrlResponse removeCallbackUrl(RemoveCallbackUrlRequest requ response.setId(request.getId()); final Optional callbackUrlEntityOptional = callbackUrlRepository.findById(request.getId()); if (callbackUrlEntityOptional.isPresent()) { - callbackUrlRepository.delete(callbackUrlEntityOptional.get()); + final CallbackUrlEntity callbackEntity = callbackUrlEntityOptional.get(); + evictRestClientFromCache(callbackEntity); + callbackUrlRepository.delete(callbackEntity); response.setRemoved(true); } else { response.setRemoved(false); @@ -415,15 +423,52 @@ private void notifyCallbackUrl(CallbackUrlEntity callbackUrlEntity, Map