From 7efb907acf7aa3ac57d2cbf8f1a19fe1a12a26cb Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Mon, 19 Feb 2024 15:18:20 +0100 Subject: [PATCH] feat: add product name (#22) --- .../domain/daos/ApplicationDAO.java | 6 +- .../permission/domain/daos/PermissionDAO.java | 21 ----- .../domain/di/PermissionImportService.java | 6 +- .../domain/di/mappers/DataImportV1Mapper.java | 19 +++-- .../permission/domain/models/Application.java | 7 +- .../permission/domain/models/Permission.java | 7 +- .../controllers/PermissionRestController.java | 10 +-- .../controllers/OperatorRestController.java | 8 +- .../v1/mappers/OperatorPermissionMapper.java | 13 +-- src/main/openapi/onecx-permission-di-v1.yaml | 18 +++- .../onecx-permission-internal-openapi.yaml | 8 ++ .../openapi/onecx-permission-operator-v1.yaml | 8 +- src/main/openapi/onecx-permission-v1.yaml | 37 +++------ src/main/resources/db/changeLog.xml | 2 - .../db/v1/2024-01-04-create-tables.xml | 82 +++++++------------ .../resources/db/v1/2024-01-30-app-tables.xml | 31 ------- .../v1/2024-02-12-delete-workspace-tables.xml | 17 ---- .../domain/daos/ApplicationDAOTest.java | 2 +- .../domain/daos/PermissionDAOTest.java | 2 - .../PermissionRestControllerTenantTest.java | 40 +-------- .../v1/PermissionRestControllerTest.java | 40 ++++----- .../OperatorRestControllerTest.java | 7 +- src/test/resources/data/test-internal.xml | 18 ++-- src/test/resources/data/test-operator-v1.xml | 18 ++-- src/test/resources/data/test-v1.xml | 18 ++-- .../resources/import/permission-import.json | 72 ++++++++++------ 26 files changed, 207 insertions(+), 310 deletions(-) delete mode 100644 src/main/resources/db/v1/2024-01-30-app-tables.xml delete mode 100644 src/main/resources/db/v1/2024-02-12-delete-workspace-tables.xml diff --git a/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java b/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java index c77c0ac..cb66ecd 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java +++ b/src/main/java/org/tkit/onecx/permission/domain/daos/ApplicationDAO.java @@ -41,12 +41,14 @@ public PageResult findByCriteria(ApplicationSearchCriteria criteria } } - public Application loadByAppId(String appId) { + public Application loadByAppId(String productName, String appId) { try { var cb = this.getEntityManager().getCriteriaBuilder(); var cq = cb.createQuery(Application.class); var root = cq.from(Application.class); - cq.where(cb.equal(root.get(Application_.APP_ID), appId)); + cq.where( + cb.equal(root.get(Application_.PRODUCT_NAME), productName), + cb.equal(root.get(Application_.APP_ID), appId)); return this.getEntityManager().createQuery(cq).getSingleResult(); } catch (NoResultException ne) { return null; diff --git a/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java b/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java index 6af98d7..413d383 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java +++ b/src/main/java/org/tkit/onecx/permission/domain/daos/PermissionDAO.java @@ -74,29 +74,8 @@ public List findPermissionForUser(String appId, List roles) } } - public List findAllPermissionForUser(List roles) { - try { - var cb = this.getEntityManager().getCriteriaBuilder(); - var cq = cb.createQuery(Permission.class); - var root = cq.from(Permission.class); - - Subquery sq = cq.subquery(String.class); - var subRoot = sq.from(Assignment.class); - sq.select(subRoot.get(Assignment_.PERMISSION_ID)); - sq.where( - subRoot.get(Assignment_.role).get(Role_.name).in(roles)); - - cq.where(root.get(TraceableEntity_.id).in(sq)); - - return this.getEntityManager().createQuery(cq).getResultList(); - } catch (Exception ex) { - throw new DAOException(ErrorKeys.ERROR_FIND_ALL_PERMISSION_FOR_USER, ex); - } - } - public enum ErrorKeys { - ERROR_FIND_ALL_PERMISSION_FOR_USER, ERROR_FIND_PERMISSION_FOR_USER, ERROR_LOAD_BY_APP_ID, ERROR_FIND_PERMISSION_BY_CRITERIA; diff --git a/src/main/java/org/tkit/onecx/permission/domain/di/PermissionImportService.java b/src/main/java/org/tkit/onecx/permission/domain/di/PermissionImportService.java index 9697f90..532f224 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/di/PermissionImportService.java +++ b/src/main/java/org/tkit/onecx/permission/domain/di/PermissionImportService.java @@ -66,10 +66,12 @@ public void createAllApplications(Map createAllPermissions(Map>> permissions) { + public Map createAllPermissions( + Map>>> permissions) { var items = mapper.map(permissions); permissionDAO.create(items); - return items.stream().collect(Collectors.toMap(r -> r.getAppId() + r.getResource() + r.getAction(), r -> r)); + return items.stream() + .collect(Collectors.toMap(r -> r.getProductName() + r.getAppId() + r.getResource() + r.getAction(), r -> r)); } @Transactional(Transactional.TxType.REQUIRES_NEW) diff --git a/src/main/java/org/tkit/onecx/permission/domain/di/mappers/DataImportV1Mapper.java b/src/main/java/org/tkit/onecx/permission/domain/di/mappers/DataImportV1Mapper.java index 5df22c9..fb6b48a 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/di/mappers/DataImportV1Mapper.java +++ b/src/main/java/org/tkit/onecx/permission/domain/di/mappers/DataImportV1Mapper.java @@ -30,8 +30,9 @@ default Map> createMapping(Map dtoRoles.forEach((role, item) -> { Set perms = new HashSet<>(); - item.getAssignments().forEach((appId, an) -> an - .forEach((resource, actions) -> actions.forEach(action -> perms.add(appId + resource + action)))); + item.getAssignments() + .forEach((productName, apps) -> apps.forEach((appId, an) -> an.forEach((resource, actions) -> actions + .forEach(action -> perms.add(productName + appId + resource + action))))); mapping.put(role, perms); }); @@ -75,7 +76,7 @@ default List createApps(Map result = new ArrayList<>(); dtos.forEach((appId, dto) -> { - var tmp = createApp(appId, dto.getName(), dto.getDescription()); + var tmp = createApp(appId, dto.getName(), dto.getDescription(), dto.getProductName()); result.add(tmp); }); return result; @@ -90,21 +91,21 @@ default List createApps(Map map(Map>> permissions) { + default List map(Map>>> permissions) { if (permissions == null) { return List.of(); } List result = new ArrayList<>(); - permissions.forEach((appId, perm) -> perm.forEach((resource, actions) -> actions + permissions.forEach((productName, apps) -> apps.forEach((appId, perm) -> perm.forEach((resource, actions) -> actions .forEach((action, description) -> { - var tmp = map(appId, resource, action); + var tmp = map(appId, resource, action, productName); if (tmp != null) { tmp.setDescription(description); result.add(tmp); } - }))); + })))); return result; } @@ -117,5 +118,5 @@ default List map(Map>> permi @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "persisted", ignore = true) @Mapping(target = "description", ignore = true) - Permission map(String appId, String resource, String action); + Permission map(String appId, String resource, String action, String productName); } diff --git a/src/main/java/org/tkit/onecx/permission/domain/models/Application.java b/src/main/java/org/tkit/onecx/permission/domain/models/Application.java index ee08774..30cc7b3 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/models/Application.java +++ b/src/main/java/org/tkit/onecx/permission/domain/models/Application.java @@ -11,9 +11,9 @@ @Setter @Entity @Table(name = "APPLICATION", uniqueConstraints = { - @UniqueConstraint(name = "APPLICATION_KEY", columnNames = { "APP_ID" }), + @UniqueConstraint(name = "APPLICATION_KEY", columnNames = { "PRODUCT_NAME", "APP_ID" }), }, indexes = { - @Index(name = "APPLICATION_APP_ID", columnList = "APP_ID") + @Index(name = "APPLICATION_APP_ID", columnList = "PRODUCT_NAME,APP_ID") }) @SuppressWarnings("squid:S2160") public class Application extends TraceableEntity { @@ -26,4 +26,7 @@ public class Application extends TraceableEntity { @Column(name = "DESCRIPTION") private String description; + + @Column(name = "PRODUCT_NAME") + private String productName; } diff --git a/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java b/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java index db17350..28effd1 100644 --- a/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java +++ b/src/main/java/org/tkit/onecx/permission/domain/models/Permission.java @@ -11,9 +11,9 @@ @Setter @Entity @Table(name = "PERMISSION", uniqueConstraints = { - @UniqueConstraint(name = "PERMISSION_KEY", columnNames = { "APP_ID", "RESOURCE", "ACTION" }), + @UniqueConstraint(name = "PERMISSION_KEY", columnNames = { "PRODUCT_NAME", "APP_ID", "RESOURCE", "ACTION" }), }, indexes = { - @Index(name = "PERMISSION_APP_ID", columnList = "APP_ID") + @Index(name = "PERMISSION_PRODUCT_APP_ID", columnList = "PRODUCT_NAME,APP_ID") }) @SuppressWarnings("squid:S2160") public class Permission extends TraceableEntity { @@ -21,6 +21,9 @@ public class Permission extends TraceableEntity { @Column(name = "APP_ID") private String appId; + @Column(name = "PRODUCT_NAME") + private String productName; + /** * The permission action. */ diff --git a/src/main/java/org/tkit/onecx/permission/rs/external/v1/controllers/PermissionRestController.java b/src/main/java/org/tkit/onecx/permission/rs/external/v1/controllers/PermissionRestController.java index 8dddf17..c3d4847 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/external/v1/controllers/PermissionRestController.java +++ b/src/main/java/org/tkit/onecx/permission/rs/external/v1/controllers/PermissionRestController.java @@ -35,14 +35,8 @@ public class PermissionRestController implements PermissionApiV1 { ExceptionMapper exceptionMapper; @Override - public Response getAllApplicationsPermissions(PermissionRequestDTOV1 permissionRequestDTOV1) { - var roles = tokenService.getTokenRoles(permissionRequestDTOV1.getToken()); - var permissions = permissionDAO.findAllPermissionForUser(roles); - return Response.ok(mapper.create(permissions)).build(); - } - - @Override - public Response getApplicationPermissions(String appId, @LogExclude PermissionRequestDTOV1 permissionRequestDTOV1) { + public Response getApplicationPermissions(String productName, String appId, + @LogExclude PermissionRequestDTOV1 permissionRequestDTOV1) { var roles = tokenService.getTokenRoles(permissionRequestDTOV1.getToken()); var permissions = permissionDAO.findPermissionForUser(appId, roles); return Response.ok(mapper.create(appId, permissions)).build(); diff --git a/src/main/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestController.java b/src/main/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestController.java index b66441f..3d7e894 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestController.java +++ b/src/main/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestController.java @@ -42,17 +42,17 @@ public class OperatorRestController implements PermissionOperatorApi { @Override @TenantExclude @Transactional(Transactional.TxType.REQUIRED) - public Response createOrUpdatePermission(String appId, PermissionRequestDTOV1 permissionRequestDTOV1) { + public Response createOrUpdatePermission(String productName, String appId, PermissionRequestDTOV1 permissionRequestDTOV1) { - var app = applicationDAO.loadByAppId(appId); + var app = applicationDAO.loadByAppId(productName, appId); if (app == null) { - app = mapper.createApp(permissionRequestDTOV1, appId); + app = mapper.createApp(permissionRequestDTOV1, appId, productName); applicationDAO.create(app); } else { mapper.updateApp(permissionRequestDTOV1, app); applicationDAO.update(app); } - var data = mapper.map(permissionRequestDTOV1, appId); + var data = mapper.map(permissionRequestDTOV1, appId, productName); if (data.isEmpty()) { return Response.ok().build(); } diff --git a/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java b/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java index 9562880..463c4ea 100644 --- a/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java +++ b/src/main/java/org/tkit/onecx/permission/rs/operator/v1/mappers/OperatorPermissionMapper.java @@ -23,7 +23,7 @@ public interface OperatorPermissionMapper { @Mapping(target = "controlTraceabilityManual", ignore = true) @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "persisted", ignore = true) - Application createApp(PermissionRequestDTOV1 dto, String appId); + Application createApp(PermissionRequestDTOV1 dto, String appId, String productName); @Mapping(target = "id", ignore = true) @Mapping(target = "creationDate", ignore = true) @@ -34,19 +34,20 @@ public interface OperatorPermissionMapper { @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "persisted", ignore = true) @Mapping(target = "appId", ignore = true) + @Mapping(target = "productName", ignore = true) void updateApp(PermissionRequestDTOV1 dto, @MappingTarget Application app); - default List map(PermissionRequestDTOV1 dto, String appId) { - return map(dto.getPermissions(), appId); + default List map(PermissionRequestDTOV1 dto, String appId, String productName) { + return map(dto.getPermissions(), appId, productName); } - default List map(List list, String appId) { + default List map(List list, String appId, String productName) { if (list == null) { return List.of(); } List data = new ArrayList<>(); for (PermissionDTOV1 dto : list) { - data.add(map(dto, appId)); + data.add(map(dto, appId, productName)); } return data; } @@ -59,5 +60,5 @@ default List map(List list, String appId) { @Mapping(target = "controlTraceabilityManual", ignore = true) @Mapping(target = "modificationCount", ignore = true) @Mapping(target = "persisted", ignore = true) - Permission map(PermissionDTOV1 dto, String appId); + Permission map(PermissionDTOV1 dto, String appId, String productName); } diff --git a/src/main/openapi/onecx-permission-di-v1.yaml b/src/main/openapi/onecx-permission-di-v1.yaml index 146498d..76489c5 100644 --- a/src/main/openapi/onecx-permission-di-v1.yaml +++ b/src/main/openapi/onecx-permission-di-v1.yaml @@ -27,7 +27,7 @@ components: applications: $ref: '#/components/schemas/DataImportApplicationWrapper' permissions: - $ref: '#/components/schemas/DataImportPermissionWrapper' + $ref: '#/components/schemas/DataImportProductWrapper' DataImportApplicationWrapper: type: object nullable: false @@ -37,8 +37,16 @@ components: properties: name: type: string + productName: + type: string description: type: string + DataImportProductWrapper: + type: object + nullable: false + description: product name + additionalProperties: + $ref: '#/components/schemas/DataImportPermissionWrapper' DataImportPermissionWrapper: type: object nullable: false @@ -80,7 +88,13 @@ components: description: type: string assignments: - $ref: '#/components/schemas/DataImportAssignmentWrapper' + $ref: '#/components/schemas/DataImportProductAssignmentWrapper' + DataImportProductAssignmentWrapper: + type: object + nullable: false + description: product name + additionalProperties: + $ref: '#/components/schemas/DataImportAssignmentWrapper' DataImportAssignmentWrapper: type: object nullable: false diff --git a/src/main/openapi/onecx-permission-internal-openapi.yaml b/src/main/openapi/onecx-permission-internal-openapi.yaml index 7fbe679..92501a0 100644 --- a/src/main/openapi/onecx-permission-internal-openapi.yaml +++ b/src/main/openapi/onecx-permission-internal-openapi.yaml @@ -433,6 +433,8 @@ components: properties: appId: type: string + productName: + type: string pageNumber: format: int32 description: The number of page. @@ -448,6 +450,8 @@ components: properties: appId: type: string + productName: + type: string name: type: string pageNumber: @@ -498,6 +502,8 @@ components: type: string appId: type: string + productName: + type: string name: type: string description: @@ -540,6 +546,8 @@ components: type: string appId: type: string + productName: + type: string resource: type: string action: diff --git a/src/main/openapi/onecx-permission-operator-v1.yaml b/src/main/openapi/onecx-permission-operator-v1.yaml index e38e66b..3c01108 100644 --- a/src/main/openapi/onecx-permission-operator-v1.yaml +++ b/src/main/openapi/onecx-permission-operator-v1.yaml @@ -8,13 +8,19 @@ servers: tags: - name: permissionOperator paths: - /operator/v1/update/{appId}: + /operator/v1/{productName}/{appId}: put: tags: - permissionOperator description: Creates or updates permission for application. operationId: createOrUpdatePermission parameters: + - name: productName + in: path + description: Product name + required: true + schema: + type: string - name: appId in: path description: Application ID diff --git a/src/main/openapi/onecx-permission-v1.yaml b/src/main/openapi/onecx-permission-v1.yaml index a9d6004..e254da5 100644 --- a/src/main/openapi/onecx-permission-v1.yaml +++ b/src/main/openapi/onecx-permission-v1.yaml @@ -8,38 +8,19 @@ servers: tags: - name: permission paths: - /v1/permissions/user/applications: + /v1/permissions/user/{productName}/{appId}: post: tags: - permission - description: Get permission of all applications for the user - operationId: getAllApplicationsPermissions - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/PermissionRequest' - responses: - 200: - description: Workspace permission - content: - application/json: - schema: - $ref: '#/components/schemas/ApplicationsPermissions' - 400: - description: Bad request - content: - application/json: - schema: - $ref: '#/components/schemas/ProblemDetailResponse' - /v1/permissions/user/applications/{appId}: - post: - tags: - - permission - description: Get permissions of the application for the user + description: Get permissions of the product application for the user operationId: getApplicationPermissions parameters: + - name: productName + in: path + description: Product name + required: true + schema: + type: string - name: appId in: path description: Application ID @@ -86,6 +67,8 @@ components: properties: appId: type: string + productName: + type: string permissions: type: object nullable: false diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml index 4b12e4d..6956266 100644 --- a/src/main/resources/db/changeLog.xml +++ b/src/main/resources/db/changeLog.xml @@ -5,7 +5,5 @@ - - \ No newline at end of file diff --git a/src/main/resources/db/v1/2024-01-04-create-tables.xml b/src/main/resources/db/v1/2024-01-04-create-tables.xml index 88c912e..6699820 100644 --- a/src/main/resources/db/v1/2024-01-04-create-tables.xml +++ b/src/main/resources/db/v1/2024-01-04-create-tables.xml @@ -6,47 +6,24 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd" objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS"> - - + + - - - - - - - - - - - - - - - - - - - - + - - - + - - @@ -65,64 +42,63 @@ - - - - - - + + + + - - - - - - + + + - - - + - - + - + - + + + + - - - - - - + - + + + + + + + + + + diff --git a/src/main/resources/db/v1/2024-01-30-app-tables.xml b/src/main/resources/db/v1/2024-01-30-app-tables.xml deleted file mode 100644 index baf8077..0000000 --- a/src/main/resources/db/v1/2024-01-30-app-tables.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/db/v1/2024-02-12-delete-workspace-tables.xml b/src/main/resources/db/v1/2024-02-12-delete-workspace-tables.xml deleted file mode 100644 index 5724ccd..0000000 --- a/src/main/resources/db/v1/2024-02-12-delete-workspace-tables.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java b/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java index a349222..68f8a9b 100644 --- a/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java +++ b/src/test/java/org/tkit/onecx/permission/domain/daos/ApplicationDAOTest.java @@ -15,7 +15,7 @@ class ApplicationDAOTest extends AbstractDAOTest { @Test @SuppressWarnings("java:S2699") void methodExceptionTests() { - methodExceptionTests(() -> dao.loadByAppId(null), + methodExceptionTests(() -> dao.loadByAppId(null, null), ApplicationDAO.ErrorKeys.ERROR_LOAD_BY_APP_ID); methodExceptionTests(() -> dao.findByCriteria(null), ApplicationDAO.ErrorKeys.ERROR_FIND_APPLICATIONS_BY_CRITERIA); diff --git a/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java b/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java index dbbbb79..e37a4bc 100644 --- a/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java +++ b/src/test/java/org/tkit/onecx/permission/domain/daos/PermissionDAOTest.java @@ -15,8 +15,6 @@ class PermissionDAOTest extends AbstractDAOTest { @Test @SuppressWarnings("java:S2699") void methodExceptionTests() { - methodExceptionTests(() -> dao.findAllPermissionForUser(null), - PermissionDAO.ErrorKeys.ERROR_FIND_ALL_PERMISSION_FOR_USER); methodExceptionTests(() -> dao.findPermissionForUser(null, null), PermissionDAO.ErrorKeys.ERROR_FIND_PERMISSION_FOR_USER); methodExceptionTests(() -> dao.loadByAppId(null), diff --git a/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTenantTest.java b/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTenantTest.java index 3101852..caa0827 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTenantTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTenantTest.java @@ -31,7 +31,9 @@ void getApplicationPermissionsTest() { .contentType(APPLICATION_JSON) .header(APM_HEADER_PARAM, idToken) .body(new PermissionRequestDTOV1().token(accessToken)) - .post("app1") + .pathParam("productName", "test1") + .pathParam("appId", "app1") + .post() .then() .statusCode(OK.getStatusCode()) .extract() @@ -43,40 +45,4 @@ void getApplicationPermissionsTest() { } - @Test - void getApplicationsPermissionsTest() { - - var accessToken = createAccessTokenBearer(USER_BOB); - - var idToken = createToken("org1", List.of("n3-100")); - - var dto = given() - .contentType(APPLICATION_JSON) - .header(APM_HEADER_PARAM, idToken) - .body(new PermissionRequestDTOV1().token(accessToken)) - .post() - .then() - .statusCode(OK.getStatusCode()) - .extract() - .body().as(ApplicationsPermissionsDTOV1.class); - - assertThat(dto).isNotNull(); - assertThat(dto.getApplications()).isNotNull().isNotEmpty().hasSize(1); - - dto = given() - .contentType(APPLICATION_JSON) - .header(APM_HEADER_PARAM, idToken) - .body(new PermissionRequestDTOV1().token(accessToken)) - .post() - .then() - .statusCode(OK.getStatusCode()) - .extract() - .body().as(ApplicationsPermissionsDTOV1.class); - - assertThat(dto).isNotNull(); - assertThat(dto.getApplications()).isNotNull().hasSize(1); - assertThat(dto.getApplications().get(0)).isNotNull(); - assertThat(dto.getApplications().get(0).getPermissions()).isNotNull().hasSize(1); - assertThat(dto.getApplications().get(0).getPermissions().get("o1")).isNotNull().hasSize(1).containsExactly("a2"); - } } diff --git a/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTest.java index 81d4152..3748f05 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/external/v1/PermissionRestControllerTest.java @@ -34,7 +34,9 @@ void getApplicationPermissionsTest() { var dto = given() .contentType(APPLICATION_JSON) .body(new PermissionRequestDTOV1().token(accessToken)) - .post("app1") + .pathParam("productName", "test1") + .pathParam("appId", "app1") + .post() .then() .statusCode(OK.getStatusCode()) .extract() @@ -50,7 +52,9 @@ void getApplicationPermissionsTest() { dto = given() .contentType(APPLICATION_JSON) .body(new PermissionRequestDTOV1().token(accessToken)) - .post("app1") + .pathParam("productName", "test1") + .pathParam("appId", "app1") + .post() .then() .statusCode(OK.getStatusCode()) .extract() @@ -64,16 +68,18 @@ void getApplicationPermissionsTest() { private static Stream badRequestData() { return Stream.of( - Arguments.of("app1", "getApplicationPermissions.permissionRequestDTOV1: must not be null")); + Arguments.of("test1", "app1", "getApplicationPermissions.permissionRequestDTOV1: must not be null")); } @ParameterizedTest @MethodSource("badRequestData") - void getApplicationPermissionsNoBodyTest(String post, String check) { + void getApplicationPermissionsNoBodyTest(String productName, String appId, String check) { var exception = given() .contentType(APPLICATION_JSON) - .post(post) + .pathParam("productName", productName) + .pathParam("appId", appId) + .post() .then() .statusCode(BAD_REQUEST.getStatusCode()) .extract() @@ -91,29 +97,11 @@ void getApplicationPermissionsWrongTongTest() { given() .contentType(APPLICATION_JSON) .body(new PermissionRequestDTOV1().token("this-is-not-token")) - .post("app1") + .pathParam("productName", "test1") + .pathParam("appId", "app1") + .post() .then() .statusCode(INTERNAL_SERVER_ERROR.getStatusCode()); } - @Test - void getApplicationsPermissionsTest() { - - var accessToken = createAccessTokenBearer(USER_ALICE); - - var dto = given() - .contentType(APPLICATION_JSON) - .body(new PermissionRequestDTOV1().token(accessToken)) - .post() - .then() - .statusCode(OK.getStatusCode()) - .extract() - .body().as(ApplicationsPermissionsDTOV1.class); - - assertThat(dto).isNotNull(); - assertThat(dto.getApplications()).isNotNull().hasSize(1); - assertThat(dto.getApplications().get(0)).isNotNull(); - assertThat(dto.getApplications().get(0).getPermissions()).isNotNull().hasSize(1); - assertThat(dto.getApplications().get(0).getPermissions().get("o1")).isNotNull().hasSize(1).containsExactly("a3"); - } } diff --git a/src/test/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestControllerTest.java index 390fbc6..8d1c5f2 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/operator/v1/controllers/OperatorRestControllerTest.java @@ -28,6 +28,7 @@ class OperatorRestControllerTest extends AbstractTest { void requestNoBodyTest() { var exception = given() .contentType(APPLICATION_JSON) + .pathParam("productName", "test1") .pathParam("appId", "app1") .put() .then() @@ -49,6 +50,7 @@ void requestEmptyListTest() { given() .contentType(APPLICATION_JSON) .body(request) + .pathParam("productName", "test1") .pathParam("appId", "app1") .put() .then() @@ -67,6 +69,7 @@ void requestWrongPermissionTest() { var exception = given() .contentType(APPLICATION_JSON) .body(request) + .pathParam("productName", "test1") .pathParam("appId", "app1") .put() .then() @@ -92,6 +95,7 @@ void requestPermissionTest() { given() .contentType(APPLICATION_JSON) .body(request) + .pathParam("productName", "test1") .pathParam("appId", "app1") .put() .then() @@ -110,6 +114,7 @@ void requestDuplicatePermissionTest() { var exception = given() .contentType(APPLICATION_JSON) .body(request) + .pathParam("productName", "test1") .pathParam("appId", "app3") .put() .then() @@ -121,6 +126,6 @@ void requestDuplicatePermissionTest() { assertThat(exception).isNotNull(); assertThat(exception.getErrorCode()).isEqualTo("PERSIST_ENTITY_FAILED"); assertThat(exception.getDetail()).isEqualTo( - "could not execute statement [ERROR: duplicate key value violates unique constraint 'permission_key' Detail: Key (app_id, resource, action)=(app3, o1, a1) already exists.]"); + "could not execute statement [ERROR: duplicate key value violates unique constraint 'permission_key' Detail: Key (product_name, app_id, resource, action)=(test1, app3, o1, a1) already exists.]"); } } diff --git a/src/test/resources/data/test-internal.xml b/src/test/resources/data/test-internal.xml index b74b06e..ad3bac1 100644 --- a/src/test/resources/data/test-internal.xml +++ b/src/test/resources/data/test-internal.xml @@ -1,19 +1,19 @@ - - + + - - - + + + - - + + - - + + diff --git a/src/test/resources/data/test-operator-v1.xml b/src/test/resources/data/test-operator-v1.xml index f21e02b..bee5b7a 100644 --- a/src/test/resources/data/test-operator-v1.xml +++ b/src/test/resources/data/test-operator-v1.xml @@ -1,17 +1,17 @@ - - + + - - - + + + - - + + - - + + \ No newline at end of file diff --git a/src/test/resources/data/test-v1.xml b/src/test/resources/data/test-v1.xml index 09a458d..6e42eb2 100644 --- a/src/test/resources/data/test-v1.xml +++ b/src/test/resources/data/test-v1.xml @@ -1,19 +1,19 @@ - - + + - - - + + + - - + + - - + + diff --git a/src/test/resources/import/permission-import.json b/src/test/resources/import/permission-import.json index 1a3b9f2..b21b65d 100644 --- a/src/test/resources/import/permission-import.json +++ b/src/test/resources/import/permission-import.json @@ -2,32 +2,36 @@ "applications": { "application1": { "name": "test", + "productName": "test", "description": "description" }, "application2": { "name": "test2", + "productName": "test", "description": "description2" } }, "permissions": { - "application1" : { - "resource1": { - "action1": "description11", - "action2": "description12" - }, - "resource2": { - "action1": "description21", - "action2": "description22" - } - }, - "application2" : { - "r3": { - "a1": "d31", - "a2": "d31" + "product1": { + "application1": { + "resource1": { + "action1": "description11", + "action2": "description12" + }, + "resource2": { + "action1": "description21", + "action2": "description22" + } }, - "r4": { - "a1": "d41", - "a2": "d41" + "application2": { + "r3": { + "a1": "d31", + "a2": "d31" + }, + "r4": { + "a1": "d41", + "a2": "d41" + } } } }, @@ -37,22 +41,36 @@ "role1": { "description": "description1", "assignments": { - "application1": { - "resource1": ["action1","action2"] - }, - "application2": { - "r4": ["a1"] + "product1": { + "application1": { + "resource1": [ + "action1", + "action2" + ] + }, + "application2": { + "r4": [ + "a1" + ] + } } } }, "role2": { "description": "description1", "assignments": { - "application1": { - "resource1": ["action1","action2"] - }, - "application2": { - "r4": ["a1"] + "product1": { + "application1": { + "resource1": [ + "action1", + "action2" + ] + }, + "application2": { + "r4": [ + "a1" + ] + } } } }