Skip to content

Commit 24ca473

Browse files
committed
Handle login page provider visibility
1 parent 1a45270 commit 24ca473

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
127127
}
128128

129129
List<OauthProviderVO> resultList = _oauth2mgr.listOauthProviders(provider, id, domainId);
130+
boolean isAuthenticated = session != null && session.getAttribute(ApiConstants.USER_ID) != null;
130131
if (domainRequested && domainId != null && domainId > 0) {
131132
resultList.removeIf(p -> p.getDomainId() == null);
132-
} else if (!domainRequested) {
133+
} else if (!domainRequested && !isAuthenticated) {
133134
resultList.removeIf(p -> p.getDomainId() != null);
134135
}
135136

@@ -153,8 +154,20 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
153154
responses.add(r);
154155
}
155156

157+
int totalEnabledCount = responses.size();
158+
if (!domainRequested && !isAuthenticated) {
159+
List<OauthProviderVO> allProviders = _oauth2mgr.listOauthProviders(null, null, null);
160+
for (OauthProviderVO domainProvider : allProviders) {
161+
if (domainProvider.getDomainId() != null && domainProvider.isEnabled()
162+
&& Boolean.TRUE.equals(OAuth2AuthManager.OAuth2IsPluginEnabled.valueInScope(ConfigKey.Scope.Domain, domainProvider.getDomainId(), true))
163+
&& authenticatorPluginNames.contains(domainProvider.getProvider())) {
164+
totalEnabledCount++;
165+
}
166+
}
167+
}
168+
156169
ListResponse<OauthProviderResponse> response = new ListResponse<>();
157-
response.setResponses(responses, resultList.size());
170+
response.setResponses(responses, totalEnabledCount);
158171
response.setResponseName(getCommandName());
159172
setResponseObject(response);
160173

ui/src/views/auth/Login.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
</div>
204204
<div v-else style="text-align: center; color: #999; padding: 20px 0;">
205205
<span v-if="form.oauthDomain">No OAuth providers configured for this domain</span>
206+
<span v-else>Enter your domain to see available providers</span>
206207
</div>
207208
</a-tab-pane>
208209
</a-tabs>
@@ -380,7 +381,8 @@ export default {
380381
this.githubredirecturi = item.redirecturi
381382
}
382383
})
383-
this.socialLogin = oauthproviders.some(item => item.enabled)
384+
const totalCount = response.listoauthproviderresponse.count || 0
385+
this.socialLogin = totalCount > 0
384386
this.oauthGithubProvider = this.githubprovider
385387
this.oauthGoogleProvider = this.googleprovider
386388
this.oauthGithubClientId = this.githubclientid

0 commit comments

Comments
 (0)