Skip to content

Commit 9c7204d

Browse files
committed
DefaultLoginAPIAuthenticatorCmd: move createLoginResponse to ApiServer
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 1a3813a commit 9c7204d

1 file changed

Lines changed: 2 additions & 54 deletions

File tree

‎server/src/com/cloud/api/auth/DefaultLoginAPIAuthenticatorCmd.java‎

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
import org.apache.cloudstack.api.ApiErrorCode;
2626
import org.apache.cloudstack.api.BaseCmd;
2727
import org.apache.cloudstack.api.Parameter;
28-
import org.apache.cloudstack.api.ResponseObject;
2928
import org.apache.cloudstack.api.ServerApiException;
3029
import org.apache.cloudstack.api.response.LoginCmdResponse;
3130
import org.apache.log4j.Logger;
3231

3332
import javax.inject.Inject;
3433
import javax.servlet.http.HttpServletResponse;
3534
import javax.servlet.http.HttpSession;
36-
import java.util.Enumeration;
3735
import java.util.Map;
3836

3937
@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 {
10098
throw new ServerApiException(ApiErrorCode.METHOD_NOT_ALLOWED, "This is an authentication api, cannot be used directly");
10199
}
102100

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-
151101
@Override
152102
public String authenticate(String command, Map<String, Object[]> params, HttpSession session, String remoteAddress, String responseType, StringBuilder auditTrailSb, final HttpServletResponse resp) throws ServerApiException {
153103

@@ -197,10 +147,8 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
197147
if (username != null) {
198148
final String pwd = ((password == null) ? null : password[0]);
199149
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);
204152
} catch (final CloudAuthenticationException ex) {
205153
// TODO: fall through to API key, or just fail here w/ auth error? (HTTP 401)
206154
try {

0 commit comments

Comments
 (0)