Skip to content

Commit ffebb3e

Browse files
logs
1 parent 1001510 commit ffebb3e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.servlet.http.HttpServletResponse;
3535
import javax.servlet.http.HttpSession;
3636

37+
import com.cloud.api.auth.DefaultForgotPasswordAPIAuthenticatorCmd;
3738
import org.apache.cloudstack.api.ApiConstants;
3839
import org.apache.cloudstack.api.ApiErrorCode;
3940
import org.apache.cloudstack.api.ApiServerService;
@@ -225,7 +226,6 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp
225226
}
226227

227228
if (command != null && !command.equals(ValidateUserTwoFactorAuthenticationCodeCmd.APINAME)) {
228-
229229
APIAuthenticator apiAuthenticator = authManager.getAPIAuthenticator(command);
230230
if (apiAuthenticator != null) {
231231
auditTrailSb.append("command=");
@@ -261,7 +261,9 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp
261261
} catch (ServerApiException e) {
262262
httpResponseCode = e.getErrorCode().getHttpCode();
263263
responseString = e.getMessage();
264-
LOGGER.debug("Authentication failure: " + e.getMessage());
264+
if (!DefaultForgotPasswordAPIAuthenticatorCmd.APINAME.equalsIgnoreCase(command) || StringUtils.isNotBlank(username)) {
265+
LOGGER.debug("Authentication failure: {}", e.getMessage());
266+
}
265267
}
266268

267269
if (apiAuthenticator.getAPIType() == APIAuthenticationType.LOGOUT_API) {
@@ -329,7 +331,7 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp
329331
}
330332
}
331333

332-
if (! requestChecksoutAsSane(resp, auditTrailSb, responseType, params, session, command, userId, account, accountObj))
334+
if (!requestChecksoutAsSane(resp, auditTrailSb, responseType, params, session, command, userId, account, accountObj))
333335
return;
334336
} else {
335337
CallContext.register(accountMgr.getSystemUser(), accountMgr.getSystemAccount());
@@ -359,7 +361,6 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp
359361
apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials and/or request signature", params,
360362
responseType);
361363
HttpUtils.writeHttpResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType, ApiServer.JSONcontentType.value());
362-
363364
}
364365
} catch (final ServerApiException se) {
365366
final String serializedResponseText = apiServer.getSerializedApiError(se, params, responseType);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
import java.util.List;
4545
import java.util.Map;
4646

47-
@APICommand(name = "forgotPassword",
47+
@APICommand(name = DefaultForgotPasswordAPIAuthenticatorCmd.APINAME,
4848
description = "Sends an email to the user with a token to reset the password using resetPassword command.",
4949
since = "4.20.0.0",
5050
requestHasSensitiveInfo = true,
5151
responseObject = SuccessResponse.class)
5252
public class DefaultForgotPasswordAPIAuthenticatorCmd extends BaseCmd implements APIAuthenticator {
53-
53+
public static final String APINAME = "forgotPassword";
5454

5555
/////////////////////////////////////////////////////
5656
//////////////// API parameters /////////////////////
@@ -108,10 +108,12 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
108108
if (userDomain != null) {
109109
domainId = userDomain.getId();
110110
} else {
111+
logger.debug("Unable to find the domain from the path {}", domain);
111112
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("Unable to find the domain from the path %s", domain));
112113
}
113114
final UserAccount userAccount = _accountService.getActiveUserAccount(username[0], domainId);
114115
if (userAccount != null && List.of(User.Source.SAML2, User.Source.OAUTH2, User.Source.LDAP).contains(userAccount.getSource())) {
116+
logger.debug("Forgot Password is not allowed for the user {} from source {}", username[0], userAccount.getSource());
115117
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Forgot Password is not allowed for this user");
116118
}
117119
boolean success = _apiServer.forgotPassword(userAccount, userDomain);

0 commit comments

Comments
 (0)