From 990bfe7e47fc14f437b0cbc95b4ff9b3e3ddad55 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 3 Jul 2022 03:12:36 +0200 Subject: [PATCH] Inline buildCache() This is an implementation detail, make sure we express it as such. Change-Id: I405f1e2abef28a39a6ab93bc56c1a912d233ac06 Signed-off-by: Robert Varga --- .../aaa/shiro/realm/KeystoneAuthRealm.java | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/KeystoneAuthRealm.java b/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/KeystoneAuthRealm.java index 461021d7b..a5e212785 100644 --- a/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/KeystoneAuthRealm.java +++ b/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/KeystoneAuthRealm.java @@ -14,7 +14,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.UncheckedExecutionException; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -72,14 +71,19 @@ public class KeystoneAuthRealm extends AuthorizingRealm { private volatile boolean sslVerification = true; private volatile String defaultDomain = DEFAULT_KEYSTONE_DOMAIN; - private final LoadingCache clientCache; - private final ICertificateManager certManager; + private final LoadingCache clientCache = CacheBuilder.newBuilder() + .expireAfterAccess(CLIENT_EXPIRE_AFTER_ACCESS, TimeUnit.SECONDS) + .expireAfterWrite(CLIENT_EXPIRE_AFTER_WRITE, TimeUnit.SECONDS) + .build(new CacheLoader<>() { + @Override + public SimpleHttpClient load(final Boolean withSslVerification) { + return buildClient(withSslVerification, certManager, SimpleHttpClient.clientBuilder()); + } + }); - @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Legacy class layout") public KeystoneAuthRealm() { certManager = requireNonNull(ThreadLocals.CERT_MANAGER_TL.get()); - clientCache = buildCache(); LOG.info("KeystoneAuthRealm created"); } @@ -167,25 +171,6 @@ public class KeystoneAuthRealm extends AuthorizingRealm { return new SimpleAuthenticationInfo(odlPrincipal, password.toCharArray(), getName()); } - /** - * Used to build a cache of {@link SimpleHttpClient}. In practice, only one - * client instance is used at a time but SSL verification flag is used as - * key for convenience. - * - * @return the cache. - */ - protected LoadingCache buildCache() { - return CacheBuilder.newBuilder() - .expireAfterAccess(CLIENT_EXPIRE_AFTER_ACCESS, TimeUnit.SECONDS) - .expireAfterWrite(CLIENT_EXPIRE_AFTER_WRITE, TimeUnit.SECONDS) - .build(new CacheLoader() { - @Override - public SimpleHttpClient load(final Boolean withSslVerification) throws Exception { - return buildClient(withSslVerification, certManager, SimpleHttpClient.clientBuilder()); - } - }); - } - /** * Used to obtain a {@link SimpleHttpClient} that optionally performs SSL * verification. -- 2.36.6