DaanHoogland commented on code in PR #12702:
URL: https://github.com/apache/cloudstack/pull/12702#discussion_r3440701472


##########
plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java:
##########
@@ -98,7 +113,26 @@ public String authenticate(String command, Map<String, 
Object[]> params, HttpSes
             provider = providerArray[0];
         }
 
-        List<OauthProviderVO> resultList = 
_oauth2mgr.listOauthProviders(provider, id);
+        boolean domainRequested = 
ArrayUtils.isNotEmpty((String[])params.get(ApiConstants.DOMAIN_ID))
+                || 
ArrayUtils.isNotEmpty((String[])params.get(ApiConstants.DOMAIN));
+        domainId = _oauth2mgr.resolveDomainId(params);
+
+        if (domainRequested && domainId == null) {
+            ListResponse<OauthProviderResponse> response = new 
ListResponse<>();
+            response.setResponses(new ArrayList<>(), 0);
+            response.setResponseName(getCommandName());
+            setResponseObject(response);
+            return ApiResponseSerializer.toSerializedString(response, 
responseType);
+        }
+
+        List<OauthProviderVO> resultList = 
_oauth2mgr.listOauthProviders(provider, id, domainId);
+        boolean isAuthenticated = session != null && 
session.getAttribute(ApiConstants.USER_ID) != null;
+        if (domainRequested && domainId != null && domainId > 0) {
+            resultList.removeIf(p -> p.getDomainId() == null);
+        } else if (!domainRequested && !isAuthenticated) {
+            resultList.removeIf(p -> p.getDomainId() != null);
+        }

Review Comment:
   add a `domainRequested()` method? or maybe split this sequence in several 
methods to factor out?



##########
plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java:
##########
@@ -118,8 +154,20 @@ public String authenticate(String command, Map<String, 
Object[]> params, HttpSes
             responses.add(r);
         }
 
+        int totalEnabledCount = responses.size();
+        if (!domainRequested && !isAuthenticated) {
+            List<OauthProviderVO> allProviders = 
_oauth2mgr.listOauthProviders(null, null, null);
+            for (OauthProviderVO domainProvider : allProviders) {
+                if (domainProvider.getDomainId() != null && 
domainProvider.isEnabled()
+                        && 
OAuth2AuthManager.isPluginEnabledForDomain(domainProvider.getDomainId())
+                        && 
authenticatorPluginNames.contains(domainProvider.getProvider())) {
+                    totalEnabledCount++;
+                }
+            }
+        }

Review Comment:
   `calculateTotalEnabledCount()` method?



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