Skip to content

Commit 1001510

Browse files
Fix NPE during reset password, and some code improvements
1 parent 9ae696d commit 1001510

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,8 @@ private String doOauthAuthentication(HttpSession session, Long domainId, String
177177

178178
protected Long getDomainIdFromParams(Map<String, Object[]> params, StringBuilder auditTrailSb, String responseType) {
179179
String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
180-
181-
if (domainIdArr == null) {
182-
domainIdArr = (String[])params.get(ApiConstants.DOMAIN__ID);
183-
}
184180
Long domainId = null;
185-
if ((domainIdArr != null) && (domainIdArr.length > 0)) {
181+
if (domainIdArr != null && domainIdArr.length > 0) {
186182
try {
187183
//check if UUID is passed in for domain
188184
domainId = _apiServer.fetchDomainId(domainIdArr[0]);

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,17 @@ public String authenticate(final String command, final Map<String, Object[]> par
158158
String domainPath = null;
159159

160160
if (params.containsKey(ApiConstants.IDP_ID)) {
161-
idpId = ((String[])params.get(ApiConstants.IDP_ID))[0];
161+
String[] idpIds = (String[])params.get(ApiConstants.IDP_ID);
162+
if (idpIds != null && idpIds.length > 0) {
163+
idpId = idpIds[0];
164+
}
162165
}
163166

164167
if (params.containsKey(ApiConstants.DOMAIN)) {
165-
domainPath = ((String[])params.get(ApiConstants.DOMAIN))[0];
168+
String[] domainPaths = (String[])params.get(ApiConstants.DOMAIN);
169+
if (domainPaths != null && domainPaths.length > 0) {
170+
domainPath = domainPaths[0];
171+
}
166172
}
167173

168174
if (domainPath != null && !domainPath.isEmpty()) {

server/src/main/java/com/cloud/api/ApiServlet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ private void checkSingleQueryParameterValue(Map<String, String[]> params) {
164164
LOGGER.warn(message);
165165
}
166166
});
167-
168167
}
169168

170169
void processRequestInContext(final HttpServletRequest req, final HttpServletResponse resp) {
@@ -550,6 +549,9 @@ public static void invalidateHttpSession(HttpSession session, String msg) {
550549
if (LOGGER.isTraceEnabled()) {
551550
LOGGER.trace(msg);
552551
}
552+
if (session == null) {
553+
return;
554+
}
553555
session.invalidate();
554556
} catch (final IllegalStateException ise) {
555557
if (LOGGER.isTraceEnabled()) {

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
@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 = {})
4848
public class DefaultLoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthenticator {
4949

50-
5150
/////////////////////////////////////////////////////
5251
//////////////// API parameters /////////////////////
5352
/////////////////////////////////////////////////////
@@ -107,17 +106,13 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
107106
if (HTTPMethod.valueOf(req.getMethod()) != HTTPMethod.POST) {
108107
throw new ServerApiException(ApiErrorCode.METHOD_NOT_ALLOWED, "Please use HTTP POST to authenticate using this API");
109108
}
109+
110110
// FIXME: ported from ApiServlet, refactor and cleanup
111111
final String[] username = (String[])params.get(ApiConstants.USERNAME);
112112
final String[] password = (String[])params.get(ApiConstants.PASSWORD);
113-
String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
114-
115-
if (domainIdArr == null) {
116-
domainIdArr = (String[])params.get(ApiConstants.DOMAIN__ID);
117-
}
118-
final String[] domainName = (String[])params.get(ApiConstants.DOMAIN);
113+
final String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
119114
Long domainId = null;
120-
if ((domainIdArr != null) && (domainIdArr.length > 0)) {
115+
if (domainIdArr != null && domainIdArr.length > 0) {
121116
try {
122117
//check if UUID is passed in for domain
123118
domainId = _apiServer.fetchDomainId(domainIdArr[0]);
@@ -135,6 +130,7 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
135130
}
136131

137132
String domain = null;
133+
final String[] domainName = (String[])params.get(ApiConstants.DOMAIN);
138134
domain = getDomainName(auditTrailSb, domainName, domain);
139135

140136
String serializedResponse = null;

server/src/main/java/com/cloud/api/auth/DefaultResetPasswordAPIAuthenticatorCmd.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
responseObject = SuccessResponse.class)
5454
public class DefaultResetPasswordAPIAuthenticatorCmd extends BaseCmd implements APIAuthenticator {
5555

56-
5756
/////////////////////////////////////////////////////
5857
//////////////// API parameters /////////////////////
5958
/////////////////////////////////////////////////////

0 commit comments

Comments
 (0)