Skip to content

Commit

Permalink
[PPANTT-93] feat: Add api key ACA (#482)
Browse files Browse the repository at this point in the history
Co-authored-by: pagopa-github-bot <[email protected]>
  • Loading branch information
svariant and pagopa-github-bot authored Aug 23, 2024
1 parent fafa825 commit 10f7e2d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 44 deletions.
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -8721,7 +8721,8 @@
"FDR_PSP",
"BO_EXT_EC",
"BO_EXT_PSP",
"PRINT_NOTICE"
"PRINT_NOTICE",
"ACA"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<version>2.5.14</version>
</parent>
<artifactId>pagopa-selfcare-ms-backoffice</artifactId>
<version>2.20.0</version>
<version>2.20.0-1-PPANTT-93-new-api-key-aca</version>
<name>SelfCare Backoffice</name>
<description>Microservice to manage PagoPA Backoffice</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public InstitutionApiKeysResource createSubscriptionKeys(String institutionId, S

List<InstitutionApiKeys> apiSubscriptions = this.apimClient.getApiSubscriptions(institutionId);

if (isAuthorizerConfigurationRequired(subscriptionCode)) {
if (!subscriptionCode.getAuthDomain().isEmpty()) {
List<DelegationExternal> delegationResponse = getDelegationResponse(institutionId, subscriptionCode);

InstitutionApiKeys apiKeys = apiSubscriptions.stream()
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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();
}

Expand All @@ -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
}
}

0 comments on commit 10f7e2d

Please sign in to comment.