Skip to content

Commit 280d533

Browse files
author
prachi
committed
Bug 14047 - login API fails when UUID is used for domain_id
Changes: - API should accept UUID for domain and convert to id when needed
1 parent 1a39682 commit 280d533

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎server/src/com/cloud/api/ApiServer.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import com.cloud.utils.db.Transaction;
117117
import com.cloud.utils.encoding.Base64;
118118
import com.cloud.utils.exception.CSExceptionErrorCode;
119+
import com.cloud.uuididentity.dao.IdentityDao;
119120

120121
public class ApiServer implements HttpRequestHandler {
121122
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
@@ -766,6 +767,17 @@ else if ("signatureversion".equalsIgnoreCase(paramName)) {
766767
}
767768
return false;
768769
}
770+
771+
public Long fetchDomainId(String domainUUID){
772+
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
773+
IdentityDao identityDao = locator.getDao(IdentityDao.class);
774+
try{
775+
Long domainId = identityDao.getIdentityId("domain", domainUUID);
776+
return domainId;
777+
}catch(InvalidParameterValueException ex){
778+
return null;
779+
}
780+
}
769781

770782
public void loginUser(HttpSession session, String username, String password, Long domainId, String domainPath, Map<String, Object[]> requestParameters) throws CloudAuthenticationException {
771783
// We will always use domainId first. If that does not exist, we will use domain name. If THAT doesn't exist

‎server/src/com/cloud/api/ApiServlet.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ private void processRequest(HttpServletRequest req, HttpServletResponse resp) {
177177
Long domainId = null;
178178
if ((domainIdArr != null) && (domainIdArr.length > 0)) {
179179
try {
180-
domainId = new Long(Long.parseLong(domainIdArr[0]));
180+
//check if UUID is passed in for domain
181+
domainId = _apiServer.fetchDomainId(domainIdArr[0]);
182+
if(domainId == null){
183+
domainId = new Long(Long.parseLong(domainIdArr[0]));
184+
}
181185
auditTrailSb.append(" domainid=" + domainId);// building the params for POST call
182186
} catch (NumberFormatException e) {
183187
s_logger.warn("Invalid domain id entered by user");

0 commit comments

Comments
 (0)