|
25 | 25 | import org.apache.cloudstack.api.ApiErrorCode; |
26 | 26 | import org.apache.cloudstack.api.BaseCmd; |
27 | 27 | import org.apache.cloudstack.api.Parameter; |
28 | | -import org.apache.cloudstack.api.ResponseObject; |
29 | 28 | import org.apache.cloudstack.api.ServerApiException; |
30 | 29 | import org.apache.cloudstack.api.response.LoginCmdResponse; |
31 | 30 | import org.apache.log4j.Logger; |
32 | 31 |
|
33 | 32 | import javax.inject.Inject; |
34 | 33 | import javax.servlet.http.HttpServletResponse; |
35 | 34 | import javax.servlet.http.HttpSession; |
36 | | -import java.util.Enumeration; |
37 | 35 | import java.util.Map; |
38 | 36 |
|
39 | 37 | @APICommand(name = "login", description = "Logs a user into the CloudStack. A successful login attempt will generate a JSESSIONID cookie value that can be passed in subsequent Query command calls until the \"logout\" command has been issued or the session has expired.", requestHasSensitiveInfo = true, responseObject = LoginCmdResponse.class, entityType = {}) |
@@ -100,54 +98,6 @@ public void execute() throws ServerApiException { |
100 | 98 | throw new ServerApiException(ApiErrorCode.METHOD_NOT_ALLOWED, "This is an authentication api, cannot be used directly"); |
101 | 99 | } |
102 | 100 |
|
103 | | - private String createLoginResponse(HttpSession session, String responseType) { |
104 | | - LoginCmdResponse response = new LoginCmdResponse(); |
105 | | - response.setTimeout(session.getMaxInactiveInterval()); |
106 | | - |
107 | | - final String user_UUID = (String)session.getAttribute("user_UUID"); |
108 | | - session.removeAttribute("user_UUID"); |
109 | | - response.setUserId(user_UUID); |
110 | | - |
111 | | - final String domain_UUID = (String)session.getAttribute("domain_UUID"); |
112 | | - session.removeAttribute("domain_UUID"); |
113 | | - response.setDomainId(domain_UUID); |
114 | | - |
115 | | - // FIXME: the while loop mess |
116 | | - final Enumeration attrNames = session.getAttributeNames(); |
117 | | - if (attrNames != null) { |
118 | | - while (attrNames.hasMoreElements()) { |
119 | | - final String attrName = (String) attrNames.nextElement(); |
120 | | - final Object attrObj = session.getAttribute(attrName); |
121 | | - if (ApiConstants.USERNAME.equalsIgnoreCase(attrName)) { |
122 | | - response.setUsername(attrObj.toString()); |
123 | | - } |
124 | | - if (ApiConstants.ACCOUNT.equalsIgnoreCase(attrName)) { |
125 | | - response.setAccount(attrObj.toString()); |
126 | | - } |
127 | | - if (ApiConstants.FIRSTNAME.equalsIgnoreCase(attrName)) { |
128 | | - response.setFirstName(attrObj.toString()); |
129 | | - } |
130 | | - if (ApiConstants.LASTNAME.equalsIgnoreCase(attrName)) { |
131 | | - response.setLastName(attrObj.toString()); |
132 | | - } |
133 | | - if (ApiConstants.TYPE.equalsIgnoreCase(attrName)) { |
134 | | - response.setType((attrObj.toString())); |
135 | | - } |
136 | | - if (ApiConstants.TIMEZONE.equalsIgnoreCase(attrName)) { |
137 | | - response.setTimeZone(attrObj.toString()); |
138 | | - } |
139 | | - if (ApiConstants.REGISTERED.equalsIgnoreCase(attrName)) { |
140 | | - response.setRegistered(attrObj.toString()); |
141 | | - } |
142 | | - if (ApiConstants.SESSIONKEY.equalsIgnoreCase(attrName)) { |
143 | | - response.setSessionKey(attrObj.toString()); |
144 | | - } |
145 | | - } |
146 | | - } |
147 | | - response.setResponseName(getCommandName()); |
148 | | - return ApiResponseSerializer.toSerializedString((ResponseObject) response, responseType); |
149 | | - } |
150 | | - |
151 | 101 | @Override |
152 | 102 | public String authenticate(String command, Map<String, Object[]> params, HttpSession session, String remoteAddress, String responseType, StringBuilder auditTrailSb, final HttpServletResponse resp) throws ServerApiException { |
153 | 103 |
|
@@ -197,10 +147,8 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes |
197 | 147 | if (username != null) { |
198 | 148 | final String pwd = ((password == null) ? null : password[0]); |
199 | 149 | try { |
200 | | - _apiServer.loginUser(session, username[0], pwd, domainId, domain, remoteAddress, params); |
201 | | - auditTrailSb.insert(0, "(userId=" + session.getAttribute("userid") + " accountId=" + ((Account) session.getAttribute("accountobj")).getId() + |
202 | | - " sessionId=" + session.getId() + ")"); |
203 | | - return createLoginResponse(session, responseType); |
| 150 | + return ApiResponseSerializer.toSerializedString(_apiServer.loginUser(session, username[0], pwd, domainId, domain, remoteAddress, params), |
| 151 | + responseType); |
204 | 152 | } catch (final CloudAuthenticationException ex) { |
205 | 153 | // TODO: fall through to API key, or just fail here w/ auth error? (HTTP 401) |
206 | 154 | try { |
|
0 commit comments