Skip to content

Commit 9ab26db

Browse files
author
Daman Arora
committed
fix domain path issue
1 parent 8e48938 commit 9ab26db

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import java.util.Map;
2222

2323
import com.cloud.api.response.ApiResponseSerializer;
24+
import com.cloud.domain.DomainVO;
25+
import com.cloud.domain.dao.DomainDao;
2426
import com.cloud.user.Account;
27+
import com.cloud.utils.component.ComponentContext;
2528
import org.apache.cloudstack.acl.RoleType;
2629
import org.apache.cloudstack.api.APICommand;
2730
import org.apache.cloudstack.api.ApiConstants;
@@ -61,6 +64,10 @@ public class VerifyOAuthCodeAndGetUserCmd extends BaseListCmd implements APIAuth
6164
description = "Domain ID for domain-specific OAuth provider lookup")
6265
private Long domainId;
6366

67+
@Parameter(name = ApiConstants.DOMAIN, type = CommandType.STRING,
68+
description = "Domain path for domain-specific OAuth provider lookup")
69+
private String domainPath;
70+
6471
/////////////////////////////////////////////////////
6572
/////////////////// Accessors ///////////////////////
6673
/////////////////////////////////////////////////////
@@ -83,6 +90,8 @@ public Long getDomainId() {
8390

8491
protected OAuth2AuthManager _oauth2mgr;
8592

93+
DomainDao _domainDao;
94+
8695
@Override
8796
public long getEntityOwnerId() {
8897
return Account.Type.NORMAL.ordinal();
@@ -108,6 +117,19 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
108117
if (ArrayUtils.isNotEmpty(domainIdArray)) {
109118
domainId = Long.parseLong(domainIdArray[0]);
110119
}
120+
final String[] domainArray = (String[])params.get(ApiConstants.DOMAIN);
121+
if (ArrayUtils.isNotEmpty(domainArray) && domainId == null) {
122+
String path = domainArray[0];
123+
if (path != null && !"/".equals(path)) {
124+
// Look up domain by path - ensure path starts with /
125+
String fullPath = path.startsWith("/") ? path : "/" + path;
126+
if (!fullPath.endsWith("/")) fullPath = fullPath + "/";
127+
DomainVO domain = _domainDao.findDomainByPath(fullPath);
128+
if (domain != null) {
129+
domainId = domain.getId();
130+
}
131+
}
132+
}
111133

112134
String email = _oauth2mgr.verifyCodeAndFetchEmail(secretCode, provider, domainId);
113135
if (email != null) {
@@ -137,5 +159,9 @@ public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
137159
if (_oauth2mgr == null) {
138160
logger.error("No suitable Pluggable Authentication Manager found for listing OAuth providers");
139161
}
162+
_domainDao = (DomainDao) ComponentContext.getComponent(DomainDao.class);
163+
if (_domainDao == null) {
164+
logger.error("Could not get DomainDao component");
165+
}
140166
}
141167
}

0 commit comments

Comments
 (0)