diff --git a/openapi/p4pa-auth.openapi.yaml b/openapi/p4pa-auth.openapi.yaml index fd357ba..60c8ca1 100644 --- a/openapi/p4pa-auth.openapi.yaml +++ b/openapi/p4pa-auth.openapi.yaml @@ -586,6 +586,7 @@ components: - operatorId - organizationIpaCode - roles + - organizationId properties: operatorId: type: string @@ -597,6 +598,9 @@ components: type: array items: type: string + organizationId: + type: integer + format: int64 OperatorsPage: type: object required: diff --git a/postman/p4pa-auth-E2E.postman_collection.json b/postman/p4pa-auth-E2E.postman_collection.json index 47e1ac1..d5585c2 100644 --- a/postman/p4pa-auth-E2E.postman_collection.json +++ b/postman/p4pa-auth-E2E.postman_collection.json @@ -1,10 +1,10 @@ { "info": { - "_postman_id": "eb0efc3f-4546-4f06-922e-722a785ae180", + "_postman_id": "8f7a992f-183d-48b7-9d75-60a3adb2cd39", "name": "p4pa-auth-E2E", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "15747968", - "_collection_link": "https://warped-astronaut-141685.postman.co/workspace/P4PA~9a8b7dd5-97b6-4dd0-b3f5-95f25fd0b455/collection/15747968-eb0efc3f-4546-4f06-922e-722a785ae180?action=share&source=collection_link&creator=15747968" + "_exporter_id": "29647564", + "_collection_link": "https://galactic-eclipse-948669.postman.co/workspace/New-Team-Workspace~be56c5f1-de0c-4252-95d0-ee80f35e2474/collection/29647564-8f7a992f-183d-48b7-9d75-60a3adb2cd39?action=share&source=collection_link&creator=29647564" }, "item": [ { @@ -337,6 +337,7 @@ " ]\r", " jsonResponse.organizations.forEach(org => {\r", " pm.expect(org).have.property(\"operatorId\")\r", + " pm.expect(org).have.property(\"organizationId\").that.is.a(\"number\");\r", " if(registeredOrganizations.includes(org.organizationIpaCode)){\r", " pm.expect(org.roles).have.property(\"length\").to.eq(1)\r", " pm.expect(org).have.property(\"email\")\r", diff --git a/src/main/java/it/gov/pagopa/payhub/auth/service/user/IamUserInfoDTO2UserInfoMapper.java b/src/main/java/it/gov/pagopa/payhub/auth/service/user/IamUserInfoDTO2UserInfoMapper.java index 4b9a360..21e9af5 100644 --- a/src/main/java/it/gov/pagopa/payhub/auth/service/user/IamUserInfoDTO2UserInfoMapper.java +++ b/src/main/java/it/gov/pagopa/payhub/auth/service/user/IamUserInfoDTO2UserInfoMapper.java @@ -1,5 +1,6 @@ package it.gov.pagopa.payhub.auth.service.user; +import io.micrometer.common.util.StringUtils; import it.gov.pagopa.payhub.auth.connector.client.OrganizationSearchClient; import it.gov.pagopa.payhub.auth.dto.IamUserInfoDTO; import it.gov.pagopa.payhub.auth.dto.IamUserOrganizationRolesDTO; @@ -86,6 +87,7 @@ private UserInfo userInfoMapper(IamUserInfoDTO iamUserInfoDTO, String accessToke .organizationIpaCode(r.getOrganizationIpaCode()) .roles(new ArrayList<>(r.getRoles())) .email(r.getEmail()) + .organizationId(retrieveOrganizationId(r.getOrganizationIpaCode(), accessToken)) .build()) .toList()) .build(); @@ -98,6 +100,16 @@ private UserInfo userInfoMapper(IamUserInfoDTO iamUserInfoDTO, String accessToke return userInfo; } + private Long retrieveOrganizationId(String organizationIpaCode, String accessToken) { + if (StringUtils.isNotBlank(organizationIpaCode)) { + Organization organization = organizationSearchClient.getOrganizationByIpaCode(organizationIpaCode, accessToken); + if (organization != null) { + return organization.getOrganizationId(); + } + } + return null; + } + private Broker getSessionBroker(IamUserInfoDTO iamUserInfoDTO, List userOrganizations, String accessToken) { String orgIpaCode = Optional.ofNullable(iamUserInfoDTO.getOrganizationAccess()) .map(IamUserOrganizationRolesDTO::getOrganizationIpaCode)