-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix NPE with ApiKeyPair during listApis call (from cmk) #13149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3202,7 +3202,7 @@ public Pair<Boolean, Map<String, String>> getKeys(GetUserKeysCmd cmd) { | |
| ApiKeyPair keyPair; | ||
| if (accessingApiKey != null) { | ||
| ApiKeyPair accessingKeyPair = apiKeyPairService.findByApiKey(accessingApiKey); | ||
| if (userId == accessingKeyPair.getUserId()) { | ||
| if (accessingKeyPair != null && userId == accessingKeyPair.getUserId()) { | ||
| keyPair = apiKeyPairService.findByApiKey(accessingApiKey); | ||
|
sureshanaparti marked this conversation as resolved.
Comment on lines
3204
to
3206
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for this suggestion, we could apply it in this PR, if you're willing to, @sureshanaparti. But it is nitpicking IMO |
||
| } else { | ||
| keyPair = _accountService.getLatestUserKeyPair(userId); | ||
|
|
@@ -3320,6 +3320,10 @@ private Boolean isAccessingKeypairSuperset(ApiKeyPair accessedKeyPair, BaseCmd c | |
| return Boolean.TRUE; | ||
| } | ||
| ApiKeyPair accessingKeyPair = apiKeyPairService.findByApiKey(apiKey); | ||
| if (accessingKeyPair == null) { | ||
| logger.warn("Unable to find API key pair for the accessing API key."); | ||
| return Boolean.FALSE; | ||
| } | ||
| return isApiKeySupersetOfPermission(new ArrayList<>(getAllKeypairPermissions(accessingKeyPair.getApiKey())), new ArrayList<>(getAllKeypairPermissions(accessedKeyPair.getApiKey()))); | ||
| } | ||
|
|
||
|
|
@@ -3334,8 +3338,8 @@ public String getAccessingApiKey(BaseCmd cmd) { | |
| if (accessedByApiKey) { | ||
| return accessingApiKey; | ||
| } | ||
| } catch (NullPointerException e) { | ||
| logger.info("Accessing API through session."); | ||
| } catch (Exception e) { | ||
| logger.info("Error accessing API through session.", e); | ||
| } | ||
|
Comment on lines
+3341
to
3343
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Copilot suggestion does not make sense in the context of this method |
||
| return null; | ||
| } | ||
|
|
@@ -3582,6 +3586,10 @@ public List<RolePermissionEntity> getAllKeypairPermissions(String apiKey) { | |
| throw new InvalidParameterValueException("API key not present in the request's URL and, thus, unable to fetch API key rules."); | ||
| } | ||
| ApiKeyPair apiKeyPair = keyPairManager.findByApiKey(apiKey); | ||
| if (apiKeyPair == null) { | ||
| logger.warn("Unable to find API key pair by API key."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. throw an exception ? |
||
| return new ArrayList<>(); | ||
| } | ||
|
Comment on lines
+3589
to
+3592
|
||
| Account account = _accountDao.findById(apiKeyPair.getAccountId()); | ||
| List<ApiKeyPairPermission> keyPairPermissions = keyPairManager.findAllPermissionsByKeyPairId(apiKeyPair.getId(), account.getRoleId()); | ||
| return new ArrayList<>(keyPairPermissions); | ||
|
|
@@ -3848,12 +3856,11 @@ public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledViewEn | |
| @Override | ||
| public UserAccount getUserByApiKey(String apiKey) { | ||
| ApiKeyPairVO keyPair = apiKeyPairDao.findByApiKey(apiKey); | ||
|
|
||
| if (keyPair == null) { | ||
| return null; | ||
| if (keyPair != null) { | ||
| return userAccountDao.findById(keyPair.getUserId()); | ||
| } | ||
|
|
||
| return userAccountDao.findById(keyPair.getUserId()); | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to throw an exception here, if apikeypair is not found
similar to change with
getAllKeypairPermissionsmethodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be nice