cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [3/5] git commit: updated refs/heads/saml2 to 66129c3
Date Mon, 18 Aug 2014 01:46:55 GMT
ApiServer: change loginUser method signature to return ResponseObject

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/61316eed
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/61316eed
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/61316eed

Branch: refs/heads/saml2
Commit: 61316eed75f6084490a9dac2fcbca2beaf811acc
Parents: 49a64cd
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Mon Aug 18 03:35:11 2014 +0200
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Mon Aug 18 03:35:11 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/61316eed/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<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
         // 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/61316eed/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<String, Object[]> 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<String, Object[]> requestParameters) throws CloudAuthenticationException;
+    public ResponseObject loginUser(HttpSession session, String username, String password,
Long domainId, String domainPath, String loginIpAddress,
+                                    Map<String, Object[]> requestParameters) throws
CloudAuthenticationException;
 
     public void logoutUser(long userId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/61316eed/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;


Mime
View raw message