mirror of https://github.com/apache/cloudstack.git
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>
This commit is contained in:
parent
38c001296a
commit
3c1f03144f
|
|
@ -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;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue