@@ -3202,7 +3202,7 @@ public Pair<Boolean, Map<String, String>> getKeys(GetUserKeysCmd cmd) {
32023202 ApiKeyPair keyPair ;
32033203 if (accessingApiKey != null ) {
32043204 ApiKeyPair accessingKeyPair = apiKeyPairService .findByApiKey (accessingApiKey );
3205- if (userId == accessingKeyPair .getUserId ()) {
3205+ if (accessingKeyPair != null && userId == accessingKeyPair .getUserId ()) {
32063206 keyPair = apiKeyPairService .findByApiKey (accessingApiKey );
32073207 } else {
32083208 keyPair = _accountService .getLatestUserKeyPair (userId );
@@ -3320,6 +3320,10 @@ private Boolean isAccessingKeypairSuperset(ApiKeyPair accessedKeyPair, BaseCmd c
33203320 return Boolean .TRUE ;
33213321 }
33223322 ApiKeyPair accessingKeyPair = apiKeyPairService .findByApiKey (apiKey );
3323+ if (accessingKeyPair == null ) {
3324+ logger .warn ("Unable to find API key pair for the accessing API key: {}" , apiKey );
3325+ return Boolean .TRUE ;
3326+ }
33233327 return isApiKeySupersetOfPermission (new ArrayList <>(getAllKeypairPermissions (accessingKeyPair .getApiKey ())), new ArrayList <>(getAllKeypairPermissions (accessedKeyPair .getApiKey ())));
33243328 }
33253329
@@ -3335,7 +3339,7 @@ public String getAccessingApiKey(BaseCmd cmd) {
33353339 return accessingApiKey ;
33363340 }
33373341 } catch (NullPointerException e ) {
3338- logger .info ("Accessing API through session." );
3342+ logger .info ("Accessing API through session." , e );
33393343 }
33403344 return null ;
33413345 }
@@ -3582,6 +3586,10 @@ public List<RolePermissionEntity> getAllKeypairPermissions(String apiKey) {
35823586 throw new InvalidParameterValueException ("API key not present in the request's URL and, thus, unable to fetch API key rules." );
35833587 }
35843588 ApiKeyPair apiKeyPair = keyPairManager .findByApiKey (apiKey );
3589+ if (apiKeyPair == null ) {
3590+ logger .warn ("Unable to find API key pair by API key: {}" , apiKey );
3591+ return new ArrayList <>();
3592+ }
35853593 Account account = _accountDao .findById (apiKeyPair .getAccountId ());
35863594 List <ApiKeyPairPermission > keyPairPermissions = keyPairManager .findAllPermissionsByKeyPairId (apiKeyPair .getId (), account .getRoleId ());
35873595 return new ArrayList <>(keyPairPermissions );
@@ -3848,12 +3856,11 @@ public void buildACLViewSearchCriteria(SearchCriteria<? extends ControlledViewEn
38483856 @ Override
38493857 public UserAccount getUserByApiKey (String apiKey ) {
38503858 ApiKeyPairVO keyPair = apiKeyPairDao .findByApiKey (apiKey );
3851-
3852- if (keyPair == null ) {
3853- return null ;
3859+ if (keyPair != null ) {
3860+ return userAccountDao .findById (keyPair .getUserId ());
38543861 }
38553862
3856- return userAccountDao . findById ( keyPair . getUserId ()) ;
3863+ return null ;
38573864 }
38583865
38593866 @ Override
0 commit comments