From aef7dc9aa0d462bb50dafed2133f94a003127a81 Mon Sep 17 00:00:00 2001 From: prachi Date: Tue, 20 Mar 2012 17:03:19 -0700 Subject: [PATCH] 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 Conflicts: server/src/com/cloud/api/ApiServer.java --- server/src/com/cloud/api/ApiServer.java | 12 ++++++++++++ server/src/com/cloud/api/ApiServlet.java | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index b078934017d..dd1eb2e4f46 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -114,6 +114,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; import com.cloud.utils.encoding.Base64; +import com.cloud.uuididentity.dao.IdentityDao; public class ApiServer implements HttpRequestHandler { private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName()); @@ -737,6 +738,17 @@ public class ApiServer implements HttpRequestHandler { } return false; } + + public Long fetchDomainId(String domainUUID){ + ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); + IdentityDao identityDao = locator.getDao(IdentityDao.class); + try{ + Long domainId = identityDao.getIdentityId("domain", domainUUID); + return domainId; + }catch(InvalidParameterValueException ex){ + return null; + } + } public void loginUser(HttpSession session, String username, String password, Long domainId, String domainPath, Map requestParameters) throws CloudAuthenticationException { // We will always use domainId first. If that does not exist, we will use domain name. If THAT doesn't exist diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index 4e1fe904584..66cf7fd69fa 100755 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -177,7 +177,11 @@ public class ApiServlet extends HttpServlet { Long domainId = null; if ((domainIdArr != null) && (domainIdArr.length > 0)) { try { - domainId = new Long(Long.parseLong(domainIdArr[0])); + //check if UUID is passed in for domain + domainId = _apiServer.fetchDomainId(domainIdArr[0]); + if(domainId == null){ + domainId = new Long(Long.parseLong(domainIdArr[0])); + } auditTrailSb.append(" domainid=" + domainId);// building the params for POST call } catch (NumberFormatException e) { s_logger.warn("Invalid domain id entered by user");