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
This commit is contained in:
prachi 2012-03-20 15:57:05 -07:00
parent 1a39682cd5
commit 280d533a6f
2 changed files with 17 additions and 1 deletions

View File

@ -116,6 +116,7 @@ import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.encoding.Base64;
import com.cloud.utils.exception.CSExceptionErrorCode;
import com.cloud.uuididentity.dao.IdentityDao;
public class ApiServer implements HttpRequestHandler {
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
@ -766,6 +767,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<String, Object[]> requestParameters) throws CloudAuthenticationException {
// We will always use domainId first. If that does not exist, we will use domain name. If THAT doesn't exist

View File

@ -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");