This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/3_0_X by this push:
     new b09e3c1c36 SCIM: better support for startIndex
b09e3c1c36 is described below

commit b09e3c1c36b1816eba80bfd1d942d3938378893b
Author: Francesco Chicchiriccò <ilgro...@apache.org>
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 268c006bd7..223d559712 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() <= 1
-                ? 1
-                : (request.getStartIndex() / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
         int startIndex = request.getStartIndex() <= 1 ? 1 : 
request.getStartIndex();
 
         int itemsPerPage = request.getCount() <= 1 ? AnyDAO.DEFAULT_PAGE_SIZE 
: request.getCount();
 
+        int page = request.getStartIndex() <= 1 ? 1 : (request.getStartIndex() 
/ itemsPerPage) + 1;
+
+        /*
+         * 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<OrderByClause> 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 f28bafd5b4..9d9b091a57 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

Reply via email to