This is an automated email from the ASF dual-hosted git repository.
winterhazel pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 3c1f03144fe Add null check for ApiKeyPair in getUserByApiKey (#12938)
3c1f03144fe is described below
commit 3c1f03144feee985404b0be0d65a25288d219d70
Author: Davi Torres <[email protected]>
AuthorDate: Tue May 19 16:29:50 2026 -0400
Add null check for ApiKeyPair in getUserByApiKey (#12938)
Co-authored-by: dahn <[email protected]>
Co-authored-by: Bernardo De Marco Gonçalves <[email protected]>
---
.../org/apache/cloudstack/api/command/admin/user/GetUserCmd.java | 4 ++--
server/src/main/java/com/cloud/user/AccountManagerImpl.java | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git
a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java
b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java
index 3427cef3366..a3dcf08c3a3 100644
---
a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java
+++
b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java
@@ -22,7 +22,7 @@ import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.UserResponse;
-
+import org.apache.cloudstack.api.ApiArgValidator;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.user.UserAccount;
@@ -35,7 +35,7 @@ public class GetUserCmd extends BaseCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
- @Parameter(name = ApiConstants.USER_API_KEY, type = CommandType.STRING,
required = true, description = "API key of the user")
+ @Parameter(name = ApiConstants.USER_API_KEY, type = CommandType.STRING,
required = true, description = "API key of the user", validations =
{ApiArgValidator.NotNullOrEmpty})
private String apiKey;
/////////////////////////////////////////////////////
diff --git a/server/src/main/java/com/cloud/user/AccountManagerImpl.java
b/server/src/main/java/com/cloud/user/AccountManagerImpl.java
index 74bf56cb083..d4f51301e78 100644
--- a/server/src/main/java/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/main/java/com/cloud/user/AccountManagerImpl.java
@@ -3848,6 +3848,11 @@ public class AccountManagerImpl extends ManagerBase
implements AccountManager, M
@Override
public UserAccount getUserByApiKey(String apiKey) {
ApiKeyPairVO keyPair = apiKeyPairDao.findByApiKey(apiKey);
+
+ if (keyPair == null) {
+ return null;
+ }
+
return userAccountDao.findById(keyPair.getUserId());
}