FrankYang0529 commented on code in PR #24093:
URL: https://github.com/apache/kafka/pull/24093#discussion_r4502343435


##########
clients/src/main/java/org/apache/kafka/common/security/authenticator/CredentialCache.java:
##########
@@ -16,53 +16,50 @@
  */
 package org.apache.kafka.common.security.authenticator;
 
+import org.apache.kafka.common.security.scram.ScramCredential;
+import org.apache.kafka.common.security.scram.internals.ScramMechanism;
+
+import java.util.Collection;
 import java.util.concurrent.ConcurrentHashMap;
 
 public class CredentialCache {
 
-    private final ConcurrentHashMap<String, Cache<?>> cacheMap = new 
ConcurrentHashMap<>();
+    private final ConcurrentHashMap<String, Cache> cacheMap = new 
ConcurrentHashMap<>();
 
-    public <C> Cache<C> createCache(String mechanism, Class<C> 
credentialClass) {
-        Cache<C> cache = new Cache<>(credentialClass);
-        @SuppressWarnings("unchecked")
-        Cache<C> oldCache = (Cache<C>) cacheMap.putIfAbsent(mechanism, cache);
-        return oldCache == null ? cache : oldCache;
+    public CredentialCache() {
     }
 
-    @SuppressWarnings("unchecked")
-    public <C> Cache<C> cache(String mechanism, Class<C> credentialClass) {
-        Cache<?> cache = cacheMap.get(mechanism);
-        if (cache != null) {
-            if (cache.credentialClass() != credentialClass)
-                throw new IllegalArgumentException("Invalid credential class " 
+ credentialClass + ", expected " + cache.credentialClass());
-            return (Cache<C>) cache;
-        } else
-            return null;
+    /**
+     * Creates a cache for each SCRAM mechanism in {@code mechanisms}. Other 
mechanisms are ignored.
+     */
+    public CredentialCache(Collection<String> mechanisms) {
+        for (String mechanism : ScramMechanism.mechanismNames()) {
+            if (mechanisms.contains(mechanism))
+                cacheMap.put(mechanism, new Cache());
+        }
     }
 
-    public static class Cache<C> {
-        private final Class<C> credentialClass;
-        private final ConcurrentHashMap<String, C> credentials;
+    public Cache createCache(String mechanism) {

Review Comment:
   Thanks for the review. Removed `CredentialCache()` and `createCache()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to