This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/master by this push:
new fd2d3e0d0b SCIM: better support for startIndex
fd2d3e0d0b is described below
commit fd2d3e0d0b8e95df0b0efcfe9149c5f95151598e
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Thu Jul 11 11:34:57 2024 +0200
SCIM: better support for startIndex
---
.../ext/scimv2/cxf/service/AbstractSCIMService.java | 15 ++++++++++++---
.../test/java/org/apache/syncope/fit/core/SCIMITCase.java | 13 +++++++++++--
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git
a/ext/scimv2/scim-rest-cxf/src/main/java/org/apache/syncope/ext/scimv2/cxf/service/AbstractSCIMService.java
b/ext/scimv2/scim-rest-cxf/src/main/java/org/apache/syncope/ext/scimv2/cxf/service/AbstractSCIMService.java
index 8f91c33303..d0f58ac605 100644
---
a/ext/scimv2/scim-rest-cxf/src/main/java/org/apache/syncope/ext/scimv2/cxf/service/AbstractSCIMService.java
+++
b/ext/scimv2/scim-rest-cxf/src/main/java/org/apache/syncope/ext/scimv2/cxf/service/AbstractSCIMService.java
@@ -155,13 +155,22 @@ abstract class AbstractSCIMService<R extends
SCIMResource> {
SearchCondVisitor visitor = new SearchCondVisitor(type,
confManager.get());
- int page = request.getStartIndex() <= 0
- ? 0
- : request.getStartIndex() / AnyDAO.DEFAULT_PAGE_SIZE;
int startIndex = request.getStartIndex() <= 1 ? 1 :
request.getStartIndex();
int itemsPerPage = request.getCount() <= 1 ? AnyDAO.DEFAULT_PAGE_SIZE
: request.getCount();
+ int page = request.getStartIndex() <= 0 ? 0 : request.getStartIndex()
/ itemsPerPage;
+
+ /*
+ * startIndex=1 and count=10 is supported
+ * startIndex=11 and count=10 is supported
+ * startIndex=21 and count=10 is supported
+ * startIndex=2 and count=10 is not supported
+ */
+ if ((startIndex - 1) % itemsPerPage != 0) {
+ throw new BadRequestException(ErrorType.invalidValue, "Unsupported
startIndex value provided");
+ }
+
List<Sort.Order> sort;
if (request.getSortBy() == null) {
sort = List.of();
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SCIMITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SCIMITCase.java
index 33fc0e738e..6cd78cbcc5 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SCIMITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SCIMITCase.java
@@ -322,7 +322,7 @@ public class SCIMITCase extends AbstractITCase {
response = webClient().path("Groups").
query("sortBy", "displayName").
- query("startIndex", 2).
+ query("startIndex", 12).
query("count", 11).
get();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
@@ -334,7 +334,7 @@ public class SCIMITCase extends AbstractITCase {
});
assertNotNull(result);
assertTrue(result.getTotalResults() > 0);
- assertEquals(2, result.getStartIndex());
+ assertEquals(12, result.getStartIndex());
assertEquals(11, result.getItemsPerPage());
assertFalse(result.getResources().isEmpty());
@@ -342,6 +342,15 @@ public class SCIMITCase extends AbstractITCase {
assertNotNull(group.getId());
assertNotNull(group.getDisplayName());
});
+
+ response = webClient().path("Groups").
+ query("sortBy", "displayName").
+ query("startIndex", 2).
+ query("count", 11).
+ get();
+ error = response.readEntity(SCIMError.class);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(),
error.getStatus());
+ assertEquals(ErrorType.invalidValue, error.getScimType());
}
@Test