Skip to content

Commit

Permalink
Validate the count query param with the max items configured.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpmadhavig committed Mar 25, 2024
1 parent c842b8d commit 6f8a80c
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public Response getUser(@HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String
throw new FormatNotSupportedException(error);
}

// Validates the count parameter if exists.
if (count != null && IdentityUtil.isSCIM2UserEndpointPaginationEnabled()) {
count = validateCountParameter(count);
}

// obtain the user store manager
UserManager userManager = IdentitySCIMManager.getInstance().getUserManager();

Expand Down Expand Up @@ -392,4 +397,25 @@ private void removeAskPasswordConfirmationCodeThreadLocal() {
IdentityUtil.threadLocalProperties.get()
.remove(IdentityRecoveryConstants.AP_CONFIRMATION_CODE_THREAD_LOCAL_PROPERTY);
}

/**
* Validate the count query parameter.
*
* @param count Requested item count.
* @return Validated count parameter.
* @throws CharonException If the count is negative.
*/
private int validateCountParameter(Integer count) throws CharonException {

int maximumItemsPerPage = IdentityUtil.getMaximumItemPerPage();
if (count > maximumItemsPerPage) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Given limit exceeds the maximum limit. Therefore the limit is set to %s.",
maximumItemsPerPage));
}
return maximumItemsPerPage;
}

return count;
}
}

0 comments on commit 6f8a80c

Please sign in to comment.