Skip to content

Commit

Permalink
feat: P4ADEV-1832 Arricchire la UserInfo con organizationId (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElisKina-dev authored Jan 13, 2025
1 parent 77f86e6 commit 3f1a43b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions openapi/p4pa-auth.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ components:
- operatorId
- organizationIpaCode
- roles
- organizationId
properties:
operatorId:
type: string
Expand All @@ -597,6 +598,9 @@ components:
type: array
items:
type: string
organizationId:
type: integer
format: int64
OperatorsPage:
type: object
required:
Expand Down
7 changes: 4 additions & 3 deletions postman/p4pa-auth-E2E.postman_collection.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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<UserOrganizationRoles> userOrganizations, String accessToken) {
String orgIpaCode = Optional.ofNullable(iamUserInfoDTO.getOrganizationAccess())
.map(IamUserOrganizationRolesDTO::getOrganizationIpaCode)
Expand Down

0 comments on commit 3f1a43b

Please sign in to comment.