Skip to content

Commit 974aadc

Browse files
committed
Add domain path handling to OAuth provider commands and improve descriptions
1 parent 1e99cce commit 974aadc

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2AuthManagerImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public OauthProviderVO registerOauthProvider(RegisterOAuthProviderCmd cmd) {
147147
String clientId = StringUtils.trim(cmd.getClientId());
148148
String redirectUri = StringUtils.trim(cmd.getRedirectUri());
149149
String secretKey = StringUtils.trim(cmd.getSecretKey());
150-
Long domainId = cmd.getDomainId();
150+
Long domainId = resolveDomainIdFromIdOrPath(cmd.getDomainId(), cmd.getDomainPath());
151151

152152
if (!isOAuthPluginEnabled(domainId)) {
153153
throw new CloudRuntimeException("OAuth is not enabled, please enable to register");
@@ -265,6 +265,20 @@ public Long resolveDomainId(Map<String, Object[]> params) {
265265
return null;
266266
}
267267

268+
protected Long resolveDomainIdFromIdOrPath(Long domainId, String domainPath) {
269+
if (domainId != null) {
270+
return domainId;
271+
}
272+
String path = normalizeDomainPath(domainPath);
273+
if (StringUtils.isNotEmpty(path)) {
274+
Domain domain = _domainService.findDomainByIdOrPath(null, path);
275+
if (Objects.nonNull(domain)) {
276+
return domain.getId();
277+
}
278+
}
279+
return null;
280+
}
281+
268282
protected String normalizeDomainPath(String path) {
269283
if (StringUtils.isEmpty(path)) {
270284
return null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class ListOAuthProvidersCmd extends BaseListCmd implements APIAuthenticat
6868
private Long domainId;
6969

7070
@Parameter(name = ApiConstants.DOMAIN, type = CommandType.STRING,
71-
description = "Domain path for domain-specific OAuth provider lookup", since = "4.23.0")
71+
description = "Domain path for domain-specific OAuth provider lookup. Ignored when Domain ID is passed.", since = "4.23.0")
7272
private String domainPath;
7373

7474
/////////////////////////////////////////////////////

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public class RegisterOAuthProviderCmd extends BaseCmd {
6363
description = "Domain ID for domain-specific OAuth provider. If not provided, registers as global provider", since = "4.23.0")
6464
private Long domainId;
6565

66+
@Parameter(name = ApiConstants.DOMAIN, type = CommandType.STRING,
67+
description = "Domain path for domain-specific OAuth provider. Ignored when Domain ID is passed.", since = "4.23.0")
68+
private String domainPath;
69+
6670
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP,
6771
description = "Any OAuth provider details in key/value pairs using format details[i].keyname=keyvalue. Example: details[0].clientsecret=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")
6872
protected Map details;
@@ -96,6 +100,10 @@ public Long getDomainId() {
96100
return domainId;
97101
}
98102

103+
public String getDomainPath() {
104+
return domainPath;
105+
}
106+
99107
public Map getDetails() {
100108
if (MapUtils.isEmpty(details)) {
101109
return null;

0 commit comments

Comments
 (0)