Skip to content

Commit

Permalink
Refactor the users list limit to a common method
Browse files Browse the repository at this point in the history
  • Loading branch information
sandushi committed Jul 19, 2024
1 parent 71b0ccd commit 9d4b64f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ public UsersGetResponse listUsersWithGET(Node rootNode, Integer startIndex, Inte
String sortOrder, String domainName, Map<String, Boolean> requiredAttributes)
throws CharonException, NotImplementedException, BadRequestException {

// Validates the count parameter if exists.
if (count != null && IdentityUtil.isSCIM2UserMaxItemsPerPageEnabled()) {
count = validateCountParameter(count);
}
// Validate NULL value for startIndex.
startIndex = handleStartIndexEqualsNULL(startIndex);
if (sortBy != null || sortOrder != null) {
Expand Down Expand Up @@ -6437,4 +6441,24 @@ private String maskIfRequired(String value) {

return LoggerUtils.isLogMaskingEnable ? LoggerUtils.getMaskedContent(value) : value;
}

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

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ public Response getUser(@HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String
throw new FormatNotSupportedException(error);
}

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

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

Expand Down Expand Up @@ -400,24 +395,4 @@ 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.
*/
private int validateCountParameter(Integer count) {

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 9d4b64f

Please sign in to comment.