yifan-c commented on code in PR #308:
URL: https://github.com/apache/cassandra-sidecar/pull/308#discussion_r2709390127


##########
server/src/main/java/org/apache/cassandra/sidecar/acl/authentication/CassandraIdentityExtractor.java:
##########
@@ -44,22 +45,46 @@ public CassandraIdentityExtractor(AdminIdentityResolver 
adminIdentityResolver,
     }
 
     @Override
-    public List<String> validIdentities(CertificateCredentials 
certificateCredentials) throws CredentialValidationException
+    public Future<List<String>> validIdentities(CertificateCredentials 
certificateCredentials)
     {
-        List<String> identities = 
super.validIdentities(certificateCredentials);
-        List<String> allowedIdentities = new ArrayList<>();
-        for (String identity : identities)
-        {
-            // Sidecar recognizes identities in identity_to_role table as 
authenticated
-            if (adminIdentityResolver.isAdmin(identity) || 
identityToRoleCache.containsKey(identity))
-            {
-                allowedIdentities.add(identity);
-            }
-        }
-        if (allowedIdentities.isEmpty())
-        {
-            throw new CredentialValidationException("Could not extract valid 
identities from certificate");
-        }
-        return allowedIdentities;
+        return super.validIdentities(certificateCredentials)
+                    .compose(identities -> {
+                        List<Future<Boolean>> validityCheckFutures = new 
ArrayList<>();
+                        for (String identity : identities)
+                        {
+                            Future<Boolean> isAdminFuture
+                            = 
adminIdentityResolver.isAdmin(identity).compose(adminValue -> adminValue
+                                                                               
             ? Future.succeededFuture()
+                                                                               
             : Future.failedFuture("not admin"));
+                            // Sidecar recognizes identities in 
identity_to_role table as authenticated
+                            Future<Boolean> inCacheFuture
+                            = 
identityToRoleCache.containsKey(identity).compose(hasRole -> hasRole
+                                                                               
            ? Future.succeededFuture()
+                                                                               
            : Future.failedFuture("no role mapped"));;
+
+                            Future<Boolean> isValidFuture
+                            = Future.any(isAdminFuture, inCacheFuture)
+                                    .compose(success -> 
Future.succeededFuture(true),
+                                             failure -> 
Future.succeededFuture(false));

Review Comment:
   Both `isAdmin` and `containsKey` triggers the loading function in the 
`IdentityToRoleCache`. 
   The two concurrent futures could lead to the function being evaluated twice, 
according to the `AuthCache.get` behavior. 
   Should we eval `isAdmin` first, then `identityToRoleCache.containsKey`? The 
second does not need to trigger the loading function again, since `isAdmin` 
call already either populate the cache or not.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to