Inline buildCache() 01/101701/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Jul 2022 01:12:36 +0000 (03:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Jul 2022 01:28:45 +0000 (03:28 +0200)
This is an implementation detail, make sure we express it as such.

Change-Id: I405f1e2abef28a39a6ab93bc56c1a912d233ac06
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/KeystoneAuthRealm.java

index 461021d7b4678ef78e542b6de6f24db46477c786..a5e2127850851883d5834a4bd3aee0192d1fa280 100644 (file)
@@ -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<Boolean, SimpleHttpClient> clientCache;
-
     private final ICertificateManager certManager;
+    private final LoadingCache<Boolean, SimpleHttpClient> 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<Boolean, SimpleHttpClient> buildCache() {
-        return CacheBuilder.newBuilder()
-                .expireAfterAccess(CLIENT_EXPIRE_AFTER_ACCESS, TimeUnit.SECONDS)
-                .expireAfterWrite(CLIENT_EXPIRE_AFTER_WRITE, TimeUnit.SECONDS)
-                .build(new CacheLoader<Boolean, SimpleHttpClient>() {
-                    @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.