Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9CB1E11086 for ; Mon, 25 Aug 2014 15:36:02 +0000 (UTC) Received: (qmail 8675 invoked by uid 500); 25 Aug 2014 15:35:58 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 8582 invoked by uid 500); 25 Aug 2014 15:35:58 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 8133 invoked by uid 99); 25 Aug 2014 15:35:58 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Aug 2014 15:35:58 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B80BC9CDAFE; Mon, 25 Aug 2014 15:35:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhaisaab@apache.org To: commits@cloudstack.apache.org Date: Mon, 25 Aug 2014 15:36:10 -0000 Message-Id: In-Reply-To: <3bdbbdbdf5cb401da3ba74a23305a32c@git.apache.org> References: <3bdbbdbdf5cb401da3ba74a23305a32c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/52] git commit: updated refs/heads/saml2 to 1d809ff ApiServer: change loginUser method signature to return ResponseObject Signed-off-by: Rohit Yadav Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b32af9b2 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b32af9b2 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b32af9b2 Branch: refs/heads/saml2 Commit: b32af9b2d1731f53308dd63c92c26a6f109aee48 Parents: 66fff65 Author: Rohit Yadav Authored: Mon Aug 18 03:35:11 2014 +0200 Committer: Rohit Yadav Committed: Mon Aug 25 17:33:25 2014 +0200 ---------------------------------------------------------------------- server/src/com/cloud/api/ApiServer.java | 53 ++++++++++++++++++++- server/src/com/cloud/api/ApiServerService.java | 13 +++-- server/src/com/cloud/api/ApiServlet.java | 3 ++ 3 files changed, 60 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b32af9b2/server/src/com/cloud/api/ApiServer.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 5d6c925..fc55026 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -32,6 +32,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -54,6 +55,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.cloud.utils.HttpUtils; +import org.apache.cloudstack.api.response.LoginCmdResponse; import org.apache.commons.codec.binary.Base64; import org.apache.http.ConnectionClosedException; import org.apache.http.HttpException; @@ -932,8 +934,55 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer return null; } + private ResponseObject createLoginResponse(HttpSession session) { + LoginCmdResponse response = new LoginCmdResponse(); + response.setTimeout(session.getMaxInactiveInterval()); + + final String user_UUID = (String)session.getAttribute("user_UUID"); + session.removeAttribute("user_UUID"); + response.setUserId(user_UUID); + + final String domain_UUID = (String)session.getAttribute("domain_UUID"); + session.removeAttribute("domain_UUID"); + response.setDomainId(domain_UUID); + + final Enumeration attrNames = session.getAttributeNames(); + if (attrNames != null) { + while (attrNames.hasMoreElements()) { + final String attrName = (String) attrNames.nextElement(); + final Object attrObj = session.getAttribute(attrName); + if (ApiConstants.USERNAME.equalsIgnoreCase(attrName)) { + response.setUsername(attrObj.toString()); + } + if (ApiConstants.ACCOUNT.equalsIgnoreCase(attrName)) { + response.setAccount(attrObj.toString()); + } + if (ApiConstants.FIRSTNAME.equalsIgnoreCase(attrName)) { + response.setFirstName(attrObj.toString()); + } + if (ApiConstants.LASTNAME.equalsIgnoreCase(attrName)) { + response.setLastName(attrObj.toString()); + } + if (ApiConstants.TYPE.equalsIgnoreCase(attrName)) { + response.setType((attrObj.toString())); + } + if (ApiConstants.TIMEZONE.equalsIgnoreCase(attrName)) { + response.setTimeZone(attrObj.toString()); + } + if (ApiConstants.REGISTERED.equalsIgnoreCase(attrName)) { + response.setRegistered(attrObj.toString()); + } + if (ApiConstants.SESSIONKEY.equalsIgnoreCase(attrName)) { + response.setSessionKey(attrObj.toString()); + } + } + } + response.setResponseName("loginresponse"); + return response; + } + @Override - public void loginUser(final HttpSession session, final String username, final String password, Long domainId, final String domainPath, final String loginIpAddress, + public ResponseObject loginUser(final HttpSession session, final String username, final String password, Long domainId, final String domainPath, final String loginIpAddress, final 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 // we will default to ROOT @@ -1003,7 +1052,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer final String sessionKey = Base64.encodeBase64String(sessionKeyBytes); session.setAttribute("sessionkey", sessionKey); - return; + return createLoginResponse(session); } throw new CloudAuthenticationException("Failed to authenticate user " + username + " in domain " + domainId + "; please provide valid credentials"); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b32af9b2/server/src/com/cloud/api/ApiServerService.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiServerService.java b/server/src/com/cloud/api/ApiServerService.java index 5d078c3..aa3b8f7 100644 --- a/server/src/com/cloud/api/ApiServerService.java +++ b/server/src/com/cloud/api/ApiServerService.java @@ -16,21 +16,20 @@ // under the License. package com.cloud.api; -import java.util.Map; - -import javax.servlet.http.HttpSession; - +import com.cloud.exception.CloudAuthenticationException; +import org.apache.cloudstack.api.ResponseObject; import org.apache.cloudstack.api.ServerApiException; -import com.cloud.exception.CloudAuthenticationException; +import javax.servlet.http.HttpSession; +import java.util.Map; public interface ApiServerService { public boolean verifyRequest(Map requestParameters, Long userId) throws ServerApiException; public Long fetchDomainId(String domainUUID); - public void loginUser(HttpSession session, String username, String password, Long domainId, String domainPath, String loginIpAddress, - Map requestParameters) throws CloudAuthenticationException; + public ResponseObject loginUser(HttpSession session, String username, String password, Long domainId, String domainPath, String loginIpAddress, + Map requestParameters) throws CloudAuthenticationException; public void logoutUser(long userId); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b32af9b2/server/src/com/cloud/api/ApiServlet.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index 8dff6eb..5484b1e 100644 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -201,6 +201,9 @@ public class ApiServlet extends HttpServlet { } catch (final IllegalStateException ignored) { } } + } else { + auditTrailSb.insert(0, "(userId=" + session.getAttribute("userid") + " accountId=" + ((Account) session.getAttribute("accountobj")).getId() + + " sessionId=" + session.getId() + ")"); } HttpUtils.writeHttpResponse(resp, responseString, httpResponseCode, responseType); return;