From da07abb672b92e889b4e82d8856f4585ed9ad40a Mon Sep 17 00:00:00 2001 From: Jorden_Reuter Date: Mon, 21 Oct 2024 14:42:22 +0200 Subject: [PATCH 1/3] feat: search assignments by roles --- .../onecx-permission-svc-extensions.adoc | 72 +++++++++---------- .../pages/onecx-permission-svc.adoc | 14 ++-- .../controllers/AssignmentRestController.java | 11 +++ .../onecx-permission-internal-openapi.yaml | 44 ++++++++++++ .../AssignmentRestControllerTest.java | 21 ++++++ 5 files changed, 119 insertions(+), 43 deletions(-) diff --git a/docs/modules/onecx-permission-svc/pages/onecx-permission-svc-extensions.adoc b/docs/modules/onecx-permission-svc/pages/onecx-permission-svc-extensions.adoc index 3d5794e..4857297 100644 --- a/docs/modules/onecx-permission-svc/pages/onecx-permission-svc-extensions.adoc +++ b/docs/modules/onecx-permission-svc/pages/onecx-permission-svc-extensions.adoc @@ -12,158 +12,158 @@ h| Version | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link] | -| 0.30.0 +| 0.33.0 | onecx-tenant | https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-tenant.html[Link] -| https://github.com/onecx/onecx-quarkus/blob/0.30.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link] -| 0.30.0 +| https://github.com/onecx/onecx-quarkus/blob/0.33.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link] +| 0.33.0 | tkit-quarkus-data-import | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-data-import.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link] +| 2.36.0 | tkit-quarkus-rest-context | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest-context.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link] +| 2.36.0 | tkit-quarkus-jpa-tenant | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa-tenant.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link] +| 2.36.0 | tkit-quarkus-jpa | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link] +| 2.36.0 | tkit-quarkus-log-cdi | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-cdi.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link] +| 2.36.0 | tkit-quarkus-log-rs | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-rs.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link] +| 2.36.0 | tkit-quarkus-log-json | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-json.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link] +| 2.36.0 | tkit-quarkus-rest | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link] +| 2.36.0 | quarkus-arc | https://quarkus.io/guides/cdi-reference[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-arc.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-liquibase | https://quarkus.io/guides/liquibase[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-liquibase.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-smallrye-health | https://quarkus.io/guides/smallrye-health[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-health.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-micrometer-registry-prometheus | https://quarkus.io/guides/telemetry-micrometer[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-micrometer-registry-prometheus.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-hibernate-orm | https://quarkus.io/guides/hibernate-orm[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-orm.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-rest | https://quarkus.io/guides/rest[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-rest.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-rest-jackson | https://quarkus.io/guides/rest-json[Link] | -| 3.14.4 +| 3.15.1 | quarkus-jdbc-postgresql | https://quarkus.io/guides/datasource[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-jdbc-postgresql.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-smallrye-openapi | https://quarkus.io/guides/openapi-swaggerui[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-openapi.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-hibernate-validator | https://quarkus.io/guides/validation[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-validator.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-opentelemetry | https://quarkus.io/guides/opentelemetry[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-opentelemetry.adoc[Link] -| 3.14.4 +| 3.15.1 | quarkus-oidc | https://quarkus.io/guides/security-oidc-bearer-token-authentication-tutorial[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-oidc.adoc[Link] -| 3.14.4 +| 3.15.1 | tkit-quarkus-security | https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-security.html[Link] -| https://github.com/1000kit/tkit-quarkus/blob/2.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] -| 2.32.0 +| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link] +| 2.36.0 | quarkus-container-image-docker | https://quarkus.io/guides/container-image[Link] | https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-container-image-docker.adoc[Link] -| 3.14.4 +| 3.15.1 | onecx-security | | -| 0.30.0 +| 0.33.0 | quarkus-smallrye-context-propagation | | -| 3.14.4 +| 3.15.1 |=== \ No newline at end of file diff --git a/docs/modules/onecx-permission-svc/pages/onecx-permission-svc.adoc b/docs/modules/onecx-permission-svc/pages/onecx-permission-svc.adoc index a6bf70a..3e95bc4 100644 --- a/docs/modules/onecx-permission-svc/pages/onecx-permission-svc.adoc +++ b/docs/modules/onecx-permission-svc/pages/onecx-permission-svc.adoc @@ -8,7 +8,7 @@ h|[.header-title]##Configuration property## h|Type h|Default -a| [[onecx-permission-svc_onecx-permission-token-verified]] [.property-path]##`onecx.permission.token.verified`## +a| [[onecx-permission-svc_onecx-permission-token-verified]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-verified[`onecx.permission.token.verified`]## [.description] -- @@ -25,7 +25,7 @@ endif::add-copy-button-to-env-var[] |boolean |`false` -a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-suffix]] [.property-path]##`onecx.permission.token.issuer.public-key-location.suffix`## +a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-suffix]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-issuer-public-key-location-suffix[`onecx.permission.token.issuer.public-key-location.suffix`]## [.description] -- @@ -42,7 +42,7 @@ endif::add-copy-button-to-env-var[] |string |`/protocol/openid-connect/certs` -a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-enabled]] [.property-path]##`onecx.permission.token.issuer.public-key-location.enabled`## +a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-enabled]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-issuer-public-key-location-enabled[`onecx.permission.token.issuer.public-key-location.enabled`]## [.description] -- @@ -59,7 +59,7 @@ endif::add-copy-button-to-env-var[] |boolean |`false` -a| [[onecx-permission-svc_onecx-permission-token-claim-separator]] [.property-path]##`onecx.permission.token.claim.separator`## +a| [[onecx-permission-svc_onecx-permission-token-claim-separator]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-claim-separator[`onecx.permission.token.claim.separator`]## [.description] -- @@ -76,7 +76,7 @@ endif::add-copy-button-to-env-var[] |string | -a| [[onecx-permission-svc_onecx-permission-token-claim-path]] [.property-path]##`onecx.permission.token.claim.path`## +a| [[onecx-permission-svc_onecx-permission-token-claim-path]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-claim-path[`onecx.permission.token.claim.path`]## [.description] -- @@ -93,7 +93,7 @@ endif::add-copy-button-to-env-var[] |string |`realm_access/roles` -a| [[onecx-permission-svc_onecx-permission-template-role-mapping-role-mapping]] [.property-path]##`onecx.permission.template.role-mapping."role-mapping"`## +a| [[onecx-permission-svc_onecx-permission-template-role-mapping-role-mapping]] [.property-path]##link:#onecx-permission-svc_onecx-permission-template-role-mapping-role-mapping[`onecx.permission.template.role-mapping."role-mapping"`]## [.description] -- @@ -110,7 +110,7 @@ endif::add-copy-button-to-env-var[] |Map | -a| [[onecx-permission-svc_onecx-permission-template-tenants]] [.property-path]##`onecx.permission.template.tenants`## +a| [[onecx-permission-svc_onecx-permission-template-tenants]] [.property-path]##link:#onecx-permission-svc_onecx-permission-template-tenants[`onecx.permission.template.tenants`]## [.description] -- diff --git a/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestController.java b/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestController.java index 6e5c4a0..a8ccd6f 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestController.java +++ b/src/main/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestController.java @@ -81,6 +81,17 @@ public Response searchAssignments(AssignmentSearchCriteriaDTO assignmentSearchCr return Response.ok(mapper.map(result)).build(); } + @Override + public Response searchAssignmentsByRoles(AssignmentRolesSearchCriteriaDTO assignmentRolesSearchCriteriaDTO) { + var page = dao.findUserAssignments(assignmentRolesSearchCriteriaDTO.getRoles(), + assignmentRolesSearchCriteriaDTO.getPageNumber(), + assignmentRolesSearchCriteriaDTO.getPageSize()); + var assignments = dao.loadAssignments(page.getStream().map(TraceableEntity::getId).toList()); + PageResult pageResult = new PageResult<>(page.getTotalElements(), assignments.stream(), + page.getNumber(), page.getSize()); + return Response.ok().entity(mapper.mapUserAssignments(pageResult)).build(); + } + @Override public Response createAssignment(CreateAssignmentRequestDTO createAssignmentRequestDTO) { var role = roleDAO.findById(createAssignmentRequestDTO.getRoleId()); diff --git a/src/main/openapi/onecx-permission-internal-openapi.yaml b/src/main/openapi/onecx-permission-internal-openapi.yaml index f5fc16b..808404d 100644 --- a/src/main/openapi/onecx-permission-internal-openapi.yaml +++ b/src/main/openapi/onecx-permission-internal-openapi.yaml @@ -276,6 +276,32 @@ paths: responses: 204: description: Assignment deleted + /internal/assignments/roles/search: + post: + security: + - oauth2: [ ocx-pm:all, ocx-pm:read ] + tags: + - assignmentInternal + operationId: searchAssignmentsByRoles + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/AssignmentRolesSearchCriteria' + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserAssignmentPageResult' + 400: + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemDetailResponse' /internal/assignments/me: post: security: @@ -732,6 +758,24 @@ components: roleId: type: string description: The size of page + AssignmentRolesSearchCriteria: + type: object + properties: + roles: + type: array + items: + type: string + pageNumber: + format: int32 + description: The number of page. + default: 0 + type: integer + pageSize: + format: int32 + description: The size of page + default: 100 + maximum: 1000 + type: integer AssignmentPageResult: type: object properties: diff --git a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java index 56fab61..59b2b1e 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java @@ -653,4 +653,25 @@ void getUsersAssignmentsTest() { assertThat(dto).isNotNull(); } + + @Test + void searchAssignmentsByRolesTest() { + + // bearer prefix + var accessToken = createAccessTokenBearer(USER_ALICE); + + var dto = given() + .auth().oauth2(getKeycloakClientToken("testClient")) + .contentType(APPLICATION_JSON) + .body(new AssignmentRolesSearchCriteriaDTO().roles(List.of("n3")).pageNumber(0).pageSize(10)) + .post("/roles/search") + .then() + .log().all() + .statusCode(OK.getStatusCode()) + .extract() + .body().as(UserAssignmentPageResultDTO.class); + + assertThat(dto).isNotNull(); + assertThat(1).isEqualTo(dto.getStream().size()); + } } From df7b5f533ee40d87d114a004dc601482c77befa9 Mon Sep 17 00:00:00 2001 From: Jorden_Reuter Date: Mon, 21 Oct 2024 14:58:22 +0200 Subject: [PATCH 2/3] fix: code smelss --- .../internal/controllers/AssignmentRestControllerTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java index 59b2b1e..66ced0c 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java @@ -657,9 +657,6 @@ void getUsersAssignmentsTest() { @Test void searchAssignmentsByRolesTest() { - // bearer prefix - var accessToken = createAccessTokenBearer(USER_ALICE); - var dto = given() .auth().oauth2(getKeycloakClientToken("testClient")) .contentType(APPLICATION_JSON) @@ -672,6 +669,6 @@ void searchAssignmentsByRolesTest() { .body().as(UserAssignmentPageResultDTO.class); assertThat(dto).isNotNull(); - assertThat(1).isEqualTo(dto.getStream().size()); + assertThat(dto.getStream().size()).isEqualTo(1); } } From dc30fab2fe014fe6e671502a8bb1e081ea0375a8 Mon Sep 17 00:00:00 2001 From: Jorden_Reuter Date: Mon, 21 Oct 2024 15:12:17 +0200 Subject: [PATCH 3/3] fix: sonar issue --- .../rs/internal/controllers/AssignmentRestControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java index 66ced0c..0f5e144 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/internal/controllers/AssignmentRestControllerTest.java @@ -669,6 +669,6 @@ void searchAssignmentsByRolesTest() { .body().as(UserAssignmentPageResultDTO.class); assertThat(dto).isNotNull(); - assertThat(dto.getStream().size()).isEqualTo(1); + assertThat(dto.getStream()).hasSize(1); } }