From 10f7e2d9b4b4eb6d5d8fce46b197beaca74bf179 Mon Sep 17 00:00:00 2001 From: Samuele Varianti <128470180+svariant@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:38:07 +0200 Subject: [PATCH] [PPANTT-93] feat: Add api key ACA (#482) Co-authored-by: pagopa-github-bot --- helm/Chart.yaml | 4 +-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 5 +-- pom.xml | 2 +- .../model/institutions/Subscription.java | 22 +++++++------ .../service/ApiManagementService.java | 32 ++++--------------- 8 files changed, 27 insertions(+), 44 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 53381c32e..1e5e9a486 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-selfcare-ms-backoffice description: Microservice that manage api keys for pagopa product from selfcare type: application -version: 0.382.0 -appVersion: "2.20.0" +version: 0.383.0 +appVersion: "2.20.0-1-PPANTT-93-new-api-key-aca" dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index ec66431d8..d80c3e4c7 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.20.0" + tag: "2.20.0-1-PPANTT-93-new-api-key-aca" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index ed3825fbb..0232749a0 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.20.0" #improve + tag: "2.20.0-1-PPANTT-93-new-api-key-aca" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index d23f442ab..11716e368 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-selfcare-ms-backoffice-backend - tag: "2.20.0" #improve + tag: "2.20.0-1-PPANTT-93-new-api-key-aca" #improve pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index 4d52cc0e5..edf830962 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "description": "Microservice to manage PagoPA Backoffice", "termsOfService": "https://www.pagopa.gov.it/", "title": "SelfCare Backoffice", - "version": "2.20.0" + "version": "2.20.0-1-PPANTT-93-new-api-key-aca" }, "servers": [ { @@ -8721,7 +8721,8 @@ "FDR_PSP", "BO_EXT_EC", "BO_EXT_PSP", - "PRINT_NOTICE" + "PRINT_NOTICE", + "ACA" ] } } diff --git a/pom.xml b/pom.xml index 9c4405238..dfa72521f 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 2.5.14 pagopa-selfcare-ms-backoffice - 2.20.0 + 2.20.0-1-PPANTT-93-new-api-key-aca SelfCare Backoffice Microservice to manage PagoPA Backoffice diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java index 422d52227..7bd15ac36 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/model/institutions/Subscription.java @@ -14,20 +14,22 @@ @AllArgsConstructor public enum Subscription { - NODOAUTH("/products/nodo-auth", "Connessione con nodo", "nodauth-"), - GPD("/products/debt-positions", "GPD - Posizioni Debitorie", "gdp-"), - GPD_REP("/products/product-gpd-reporting", "GPD - Gestione flussi di rendicontazione", "gpdrep-"), - GPD_PAY("/products/gpd-payments-rest-aks", "GPD - Recupero ricevute", "gpdpay-"), - BIZ("/products/bizevents", "BIZ - Recupero ricevute Ente Creditore", "biz-"), - FDR_ORG("/products/fdr-org", "FdR - Flussi di Rendicontazione (EC)", "fdrorg-"), - FDR_PSP("/products/fdr-psp", "FdR - Flussi di Rendicontazione (PSP)", "fdrpsp-"), - BO_EXT_EC("/apis/%s-backoffice-external-ec-api-v1", "Backoffice External (EC)", "selfcareboexternalec-"), - BO_EXT_PSP("/apis/%s-backoffice-external-psp-api-v1", "Backoffice External (PSP)", "selfcareboexternalpsp-"), - PRINT_NOTICE("/products/pagopa_notices_service_external", "Stampa Avvisi", "printnotice-");; + NODOAUTH("/products/nodo-auth", "Connessione con nodo", "nodauth-", ""), + GPD("/products/debt-positions", "GPD - Posizioni Debitorie", "gdp-", "gpd"), + GPD_REP("/products/product-gpd-reporting", "GPD - Gestione flussi di rendicontazione", "gpdrep-", "gpd"), + GPD_PAY("/products/gpd-payments-rest-aks", "GPD - Recupero ricevute", "gpdpay-", "gpd"), + BIZ("/products/bizevents", "BIZ - Recupero ricevute Ente Creditore", "biz-", ""), + FDR_ORG("/products/fdr-org", "FdR - Flussi di Rendicontazione (EC)", "fdrorg-", "fdr"), + FDR_PSP("/products/fdr-psp", "FdR - Flussi di Rendicontazione (PSP)", "fdrpsp-", "fdr"), + BO_EXT_EC("/apis/%s-backoffice-external-ec-api-v1", "Backoffice External (EC)", "selfcareboexternalec-", "backoffice_external"), + BO_EXT_PSP("/apis/%s-backoffice-external-psp-api-v1", "Backoffice External (PSP)", "selfcareboexternalpsp-", "backoffice_external"), + PRINT_NOTICE("/products/pagopa_notices_service_external", "Stampa Avvisi", "printnotice-", ""), + ACA("/products/aca", "ACA - paCreatePosition", "aca-", "aca"); private final String scope; private final String displayName; private final String prefixId; + private final String authDomain; public static Subscription fromPrefix(String prefix) { return Arrays.stream(Subscription.values()) diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java index db7a02c5c..09c475774 100644 --- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java +++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementService.java @@ -177,7 +177,7 @@ public InstitutionApiKeysResource createSubscriptionKeys(String institutionId, S List apiSubscriptions = this.apimClient.getApiSubscriptions(institutionId); - if (isAuthorizerConfigurationRequired(subscriptionCode)) { + if (!subscriptionCode.getAuthDomain().isEmpty()) { List delegationResponse = getDelegationResponse(institutionId, subscriptionCode); InstitutionApiKeys apiKeys = apiSubscriptions.stream() @@ -186,11 +186,11 @@ public InstitutionApiKeysResource createSubscriptionKeys(String institutionId, S .orElseThrow(() -> new AppException(AppError.APIM_KEY_NOT_FOUND, institutionId)); // configure primary key - Authorization authorizationPrimaryKey = buildAuthorization(getAuthorizerDomain(subscriptionCode), subscriptionCode.getPrefixId(), apiKeys.getPrimaryKey(), institution, true, delegationResponse); + Authorization authorizationPrimaryKey = buildAuthorization(subscriptionCode.getAuthDomain(), subscriptionCode.getPrefixId(), apiKeys.getPrimaryKey(), institution, true, delegationResponse); this.authorizerConfigClient.createAuthorization(authorizationPrimaryKey); // configure secondary key - Authorization authorizationSecondaryKey = buildAuthorization(getAuthorizerDomain(subscriptionCode), subscriptionCode.getPrefixId(), apiKeys.getSecondaryKey(), institution, false, delegationResponse); + Authorization authorizationSecondaryKey = buildAuthorization(subscriptionCode.getAuthDomain(), subscriptionCode.getPrefixId(), apiKeys.getSecondaryKey(), institution, false, delegationResponse); this.authorizerConfigClient.createAuthorization(authorizationSecondaryKey); } @@ -223,7 +223,7 @@ public void regeneratePrimaryKey(@NotNull String institutionId, @NotNull String this.apimClient.regeneratePrimaryKey(subscriptionId); var prefix = subscriptionId.split("-")[0] + "-"; - if (isAuthorizerConfigurationRequired(Subscription.fromPrefix(prefix))) { + if (!Subscription.fromPrefix(prefix).getAuthDomain().isEmpty()) { updateAuthorization(institutionId, subscriptionId, prefix, true); } } @@ -241,7 +241,7 @@ public void regenerateSecondaryKey(@NotNull String institutionId, @NotNull Strin this.apimClient.regenerateSecondaryKey(subscriptionId); var prefix = subscriptionId.split("-")[0] + "-"; - if (isAuthorizerConfigurationRequired(Subscription.fromPrefix(prefix))) { + if (!Subscription.fromPrefix(prefix).getAuthDomain().isEmpty()) { updateAuthorization(institutionId, subscriptionId, prefix, false); } } @@ -312,7 +312,7 @@ private Authorization buildAuthorization( } private String getOwnerType(InstitutionResponse institution) { - RoleType type = RoleType.fromSelfcareRole(institution.getTaxCode(), institution.getInstitutionType().name()); + RoleType type = RoleType.fromSelfcareRole(institution.getTaxCode(), institution.getInstitutionType().name()); return RoleType.PT.equals(type) ? "BROKER" : type.name(); } @@ -337,25 +337,5 @@ private void createUserIfNotExist(String institutionId, private char getEnvironment() { return environment.toLowerCase().charAt(0); } - - private String getAuthorizerDomain(Subscription subType) { - if (subType == Subscription.BO_EXT_EC || subType == Subscription.BO_EXT_PSP) { - return "backoffice_external"; - } - if (subType == Subscription.GPD) { - return "gpd"; - } - if (subType == Subscription.FDR_PSP || subType == Subscription.FDR_ORG) { - return "fdr"; - } - return null; - } - - - private boolean isAuthorizerConfigurationRequired(Subscription subscriptionCode) { - return subscriptionCode == Subscription.FDR_PSP || subscriptionCode == Subscription.FDR_ORG || // FdR - subscriptionCode == Subscription.GPD || // GPD - subscriptionCode == Subscription.BO_EXT_EC || subscriptionCode == Subscription.BO_EXT_PSP; // BO - } }