Skip to content

Commit 3c1f031

Browse files
daviftorresDaanHooglandbernardodemarco
authored
Add null check for ApiKeyPair in getUserByApiKey (#12938)
Co-authored-by: dahn <daan.hoogland@gmail.com> Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
1 parent 38c0012 commit 3c1f031

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.cloudstack.api.BaseCmd;
2323
import org.apache.cloudstack.api.Parameter;
2424
import org.apache.cloudstack.api.response.UserResponse;
25-
25+
import org.apache.cloudstack.api.ApiArgValidator;
2626
import com.cloud.exception.InvalidParameterValueException;
2727
import com.cloud.user.UserAccount;
2828

@@ -35,7 +35,7 @@ public class GetUserCmd extends BaseCmd {
3535
//////////////// API parameters /////////////////////
3636
/////////////////////////////////////////////////////
3737

38-
@Parameter(name = ApiConstants.USER_API_KEY, type = CommandType.STRING, required = true, description = "API key of the user")
38+
@Parameter(name = ApiConstants.USER_API_KEY, type = CommandType.STRING, required = true, description = "API key of the user", validations = {ApiArgValidator.NotNullOrEmpty})
3939
private String apiKey;
4040

4141
/////////////////////////////////////////////////////

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,6 +3848,11 @@ public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledViewEn
38483848
@Override
38493849
public UserAccount getUserByApiKey(String apiKey) {
38503850
ApiKeyPairVO keyPair = apiKeyPairDao.findByApiKey(apiKey);
3851+
3852+
if (keyPair == null) {
3853+
return null;
3854+
}
3855+
38513856
return userAccountDao.findById(keyPair.getUserId());
38523857
}
38533858

0 commit comments

Comments
 (0)