Skip to content

Commit

Permalink
Merge branch 'develop' into QA-5637-refactor-classe-Miglioramento-cla…
Browse files Browse the repository at this point in the history
…sse-InvioNotificheB2bSteps
  • Loading branch information
tulli086 committed Feb 25, 2025
2 parents 04a5551 + 25c8278 commit fadaf56
Show file tree
Hide file tree
Showing 60 changed files with 814 additions and 465 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ build/
.vscode/
/config/api-keys-dev.properties
/config/bearer-token-dev.properties
/config/interop-tracing-dev.properties
/interop-qa-tests/src/main/resources/interop-tracing-dev.properties

token.json
5 changes: 0 additions & 5 deletions config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ pn.interop.clientId=${interop.clientId.value}
pn.interop.base-url=https://auth.uat.interop.pagopa.it
pn.interop.token-oauth2.path=/token.oauth2

#INTEROP TRACING
pn.interop.tracing.base-url=https://api.dev.tracing.interop.pagopa.it
pn.interop.tracing.bearerToken-1=${interop.configuration.tracing.bearerToken-1}
pn.interop.tracing.bearerToken-2=${interop.configuration.tracing.bearerToken-2}

#RADD ALT ADEGUAMENTO
pn.radd.alt.external.max-print-request=10

Expand Down
5 changes: 5 additions & 0 deletions interop-qa-tests/config/application-dev.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#TRACING
pn.interop.tracing.base-url=https://api.dev.tracing.interop.pagopa.it
tracing.success.csv.filepath=src/main/resources/tracing/dev/tracing-ok.csv
tracing.error.csv.filepath=src/main/resources/tracing/dev/tracing-error.csv

4 changes: 4 additions & 0 deletions interop-qa-tests/config/application-qa.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#TRACING
pn.interop.tracing.base-url=https://api.qa.tracing.interop.pagopa.it
tracing.success.csv.filepath=src/main/resources/tracing/qa/tracing-ok.csv
tracing.error.csv.filepath=src/main/resources/tracing/qa/tracing-error.csv
18 changes: 18 additions & 0 deletions interop-qa-tests/config/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spring.profiles.active=qa
#TRACING
pn.interop.tracing.base-url=https://api.qa.tracing.interop.pagopa.it
pn.interop.tracing.bearerToken-1=${interop.configuration.tracing.bearerToken-1}
pn.interop.tracing.bearerToken-2=${interop.configuration.tracing.bearerToken-2}
#PURPOSE_ID 28874634-6ea6-4def-b200-7377182c71be
interop.configuration.tracing.bearerToken-1=eyJhbGciOiJSUzI1NiIsInVzZSI6InNpZyIsInR5cCI6ImF0K2p3dCIsImtpZCI6IjBiOTEwNmExLWRiMGMtNDg4Zi05MDg0LWNlOGM2MzIxNDJiYyJ9.eyJqdGkiOiJhMGQzN2QxYy1iMzU3LTRlN2EtYjIzYy05MDViNTU3NzA2NjciLCJpc3MiOiJ0cmFjaW5nLWlzc3VlciIsImF1ZCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMSIsInN1YiI6InRyYWNpbmctc3ViamVjdCIsImlhdCI6MTcyOTYwNzUwMCwibmJmIjoxNzI5NjA3NTAwLCJleHAiOjE4Mjk2MDc0OTksIm9yZ2FuaXphdGlvbklkIjoiMGU5ZTJkYWItMmU5My00ZjI0LWJhNTktMzhkOWYxMTE5OGNhIiwicm9sZSI6ImludGVybmFsIn0.AEhPS-dnJWwTOY1gN5gqKtfAswKxZtRTPozHVM2xbG4TD3oSoo5TCyLyvPWYezFMEIIueMZykeiBnUvT_EEePl018cpio_lrlmKqHpGiYe-9u_6EU-cmPTAU9Cnpu6yESS7KyaGziFHm-Rp7qxmjnMsMgKG6IpxgmnbEwxnu4pBiFwHx_sJyUtVks7xZr50UVRzpNQNYRv9ypko140fx85bDQHyNzFqLa75wFX3hiF2yi7A-vmEuwqVwCRrpwuphMksNaSEs-E8bbxnXeq1zeiav7oc9wZHtnPruhth9fr6PoTcPwtftLEEh_QH_IssciqpTY8stA0S4AMwvFYyP_w
#PURPOSE_ID 5602d95a-9297-4221-86d0-f142b8690d5c
interop.configuration.tracing.bearerToken-2=eyJhbGciOiJSUzI1NiIsInVzZSI6InNpZyIsInR5cCI6ImF0K2p3dCIsImtpZCI6IjBiOTEwNmExLWRiMGMtNDg4Zi05MDg0LWNlOGM2MzIxNDJiYyJ9.eyJqdGkiOiI0MDNlYzc3ZC01OGM3LTQwMmYtYTg4Zi1iYzNmODFjMTBiNGIiLCJpc3MiOiJ0cmFjaW5nLWlzc3VlciIsImF1ZCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMSIsInN1YiI6InRyYWNpbmctc3ViamVjdCIsImlhdCI6MTczMDI3NzkwOCwibmJmIjoxNzMwMjc3OTA4LCJleHAiOjE4MzAyNzc5MDcsIm9yZ2FuaXphdGlvbklkIjoiNjllMjg2NWUtNjVhYi00ZTQ4LWE2MzgtMjAzN2E5ZWUyZWU3Iiwicm9sZSI6ImludGVybmFsIn0.JH2Rs9pDCHlMCBmrIvMOiCKd6eb_Xs1OdIDG47ET5gTpd1uPFio0wwHpKBnhzVZpjuFzi14EaMVHRuZqLq7NBkP4-xRAP5_muOdCKjRu6gcJVagXVTwtFXw-3WnP7jFX8FEOqjqmRoA83hX4s_dPewKZbqtC8VkKDPAHOaN9I0ZEUWwzwn9X07gCJPi3jimfhdsk4YgjcR4qlTUif73hxcHwNvfpiCqYCAXZDa_KWcz7D_QQsOLxRWFHKgfGNRr5gbuYDBSykb-ZLqsxecnXyhc3Fpwe5rTnIHWKcITfRNQjej5YnJ88HUyPrTqLqOfGvWIM3kY4n82Vt1oJYSmQNA
tracing.success.csv.filepath=src/main/resources/tracing/dev/tracing-ok.csv
tracing.error.csv.filepath=src/main/resources/tracing/dev/tracing-error.csv

#INTEROP GLOBAL PROPERTIES
bff.base-url=https://selfcare.qa.interop.pagopa.it/1.0/backend-for-frontend
session.tokens.duration.seconds=3000
interop-env=qa
max-polling-try-ms=50
max-polling-sleep-ms=1000
43 changes: 42 additions & 1 deletion interop-qa-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
<version>3.17.0</version>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.9</version>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -155,7 +161,7 @@
<typeMappings>
<typeMapping>OffsetDateTime=java.lang.String</typeMapping>
</typeMappings>
<inputSpec>https://raw.githubusercontent.com/pagopa/interop-be-monorepo/refs/heads/develop/packages/api-clients/open-api/bffApi.yml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/pagopa/interop-be-monorepo/bae46fcee339b15245ac748a6583e6dd829a6be5/packages/api-clients/open-api/bffApi.yml</inputSpec>
<generatorName>java</generatorName>
<library>resttemplate</library>
<generateApiTests>false</generateApiTests>
Expand All @@ -177,6 +183,41 @@
<modelPackage>it.pagopa.interop.generated.openapi.clients.bff.model</modelPackage>
</configuration>
</execution>

<execution>
<id>generate-external-interop-tracing-client</id>
<goals>
<goal>generate</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<typeMappings>
<typeMapping>OffsetDateTime=java.lang.String</typeMapping>
</typeMappings>
<inputSpec>https://raw.githubusercontent.com/pagopa/interop-tracing-core/refs/heads/develop/packages/api/open-api/api-external-interop-v1.yaml</inputSpec>
<generatorName>java</generatorName>
<library>resttemplate</library>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<skipValidateSpec>true</skipValidateSpec>
<configOptions>
<apiPackage>it.pagopa.interop.client.b2b.generated.openapi.clients.interop.tracing.api</apiPackage>
<modelPackage>it.pagopa.interop.client.b2b.generated.openapi.clients.interop.tracing.model</modelPackage>
<dateLibrary>java8</dateLibrary>
<annotationLibrary>none</annotationLibrary>
<documentationProvider>source</documentationProvider>
<openApiNullable>false</openApiNullable>
<useAbstractionForFiles>true</useAbstractionForFiles>
<useBeanValidation>false</useBeanValidation>
<additionalModelTypeAnnotations>
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
</additionalModelTypeAnnotations>
</configOptions>
<apiPackage>it.pagopa.interop.client.b2b.generated.openapi.clients.interop.tracing.api</apiPackage>
<modelPackage>it.pagopa.interop.client.b2b.generated.openapi.clients.interop.tracing.model</modelPackage>
</configuration>
</execution>

</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package it.pagopa.interop.agreement.service;

import it.pagopa.interop.authorization.service.utils.SettableBearerToken;
import it.pagopa.interop.generated.openapi.clients.bff.model.*;
import it.pagopa.interop.generated.openapi.clients.bff.model.Agreement;
import it.pagopa.interop.generated.openapi.clients.bff.model.AgreementPayload;
import it.pagopa.interop.generated.openapi.clients.bff.model.AgreementRejectionPayload;
import it.pagopa.interop.generated.openapi.clients.bff.model.AgreementSubmissionPayload;
import it.pagopa.interop.generated.openapi.clients.bff.model.CreatedResource;

import java.io.File;
import java.util.UUID;

public interface IAgreementClient extends SettableBearerToken {
CreatedResource createAgreement(String xCorrelationId, AgreementPayload agreementPayload);
CreatedResource createAgreement(AgreementPayload agreementPayload);
Agreement getAgreementById(String xCorrelationId, UUID agreementId);
Agreement activateAgreement(String xCorrelationId, UUID agreementId);
Agreement submitAgreement(String xCorrelationId, UUID agreementId, AgreementSubmissionPayload agreementSubmissionPayload);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.interop.agreement.service.impl;

import it.pagopa.interop.agreement.service.IAgreementClient;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.conf.InteropClientConfigs;
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.AgreementsApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.Agreement;
Expand Down Expand Up @@ -38,8 +38,8 @@ private ApiClient createApiClient(String bearerToken) {
}

@Override
public CreatedResource createAgreement(String xCorrelationId, AgreementPayload agreementPayload) {
return agreementsApi.createAgreement(xCorrelationId, agreementPayload);
public CreatedResource createAgreement(AgreementPayload agreementPayload) {
return agreementsApi.createAgreement(agreementPayload);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package it.pagopa.interop.agreement.service.impl;

import it.pagopa.interop.agreement.service.IEServiceClient;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.conf.InteropClientConfigs;
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.EservicesApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.*;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.interop.attribute.service.impl;

import it.pagopa.interop.attribute.service.IAttributeApiClient;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.conf.InteropClientConfigs;
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.AttributesApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.Attribute;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package it.pagopa.interop.authorization.service.factory;

import it.pagopa.interop.authorization.service.utils.ConfigFileReader;
import it.pagopa.interop.conf.InteropClientConfigs;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Getter
@Setter
public class InteropTokenFactory extends SessionTokenFactory {
private static final String WELLKNOWN_URL = "https://qa.interop.pagopa.it/.well-known/jwks.json";
private Map<String, Map<String, String>> cachedTokens = null;

public InteropTokenFactory(InteropClientConfigs interopClientConfigs, ConfigFileReader configFileReader) {
super(interopClientConfigs, configFileReader);
}

public Map<String, Map<String, String>> loadToken() {
getSessionTokenPayloadTemplate().put("aud", "{{ENVIRONMENT}}.interop.pagopa.it/ui");
try {
if (cachedTokens == null) cachedTokens = generateSessionToken();
} catch (Exception ex) {
throw new IllegalArgumentException("There was an error while creating the session token: " + ex.getMessage(), ex);
}
return cachedTokens;
}

@Override
public String getRemoteWellknownUrl() {
return WELLKNOWN_URL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import it.pagopa.interop.authorization.domain.Tenant;
import it.pagopa.interop.authorization.service.exception.UnsignedSTSGenerationException;
import it.pagopa.interop.authorization.service.utils.ConfigFileReader;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.conf.InteropClientConfigs;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
Expand Down Expand Up @@ -39,9 +39,7 @@
import software.amazon.awssdk.services.kms.model.VerifyResponse;

@Slf4j
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class SessionTokenFactory {
public abstract class SessionTokenFactory {
private static final Map<String, Map<String, String>> CONFIG = new HashMap<>();
private static final Map<String, Object> SESSION_TOKEN_PAYLOAD_TEMPLATE;
private static final Map<String, String> SESSION_TOKEN_HEADER_TEMPLATE = Map.of(
Expand Down Expand Up @@ -72,45 +70,33 @@ public class SessionTokenFactory {
));
SESSION_TOKEN_PAYLOAD_TEMPLATE.put("uid", "VALUES_UID");
SESSION_TOKEN_PAYLOAD_TEMPLATE.put("iss", "{{ENVIRONMENT}}.interop.pagopa.it");
SESSION_TOKEN_PAYLOAD_TEMPLATE.put("aud", "{{ENVIRONMENT}}.interop.pagopa.it/ui");
SESSION_TOKEN_PAYLOAD_TEMPLATE.put("nbf", 123);
SESSION_TOKEN_PAYLOAD_TEMPLATE.put("iat", 123);
SESSION_TOKEN_PAYLOAD_TEMPLATE.put("exp", 456);
SESSION_TOKEN_PAYLOAD_TEMPLATE.put("jti", "uuid");
}

private final InteropClientConfigs interopClientConfigs;
@Getter
private Map<String, Map<String, String>> cachedTokens = null;
private ConfigFileReader configFileReader;


public SessionTokenFactory(InteropClientConfigs interopClientConfigs, ConfigFileReader configFileReader) {
this.interopClientConfigs = interopClientConfigs;
this.configFileReader = configFileReader;
this.cachedTokens = loadToken();
}

private Map<String, Map<String, String>> loadToken() {
try {
if (cachedTokens == null) {
cachedTokens = generateSessionToken(configFileReader.getTenantList());
}
} catch (Exception ex) {
throw new IllegalArgumentException("There was an error while creating the session token: " + ex.getMessage(), ex);
}
return cachedTokens;
}
public abstract Map<String, Map<String, String>> loadToken();

public abstract String getRemoteWellknownUrl();

public Map<String, Map<String, String>> generateSessionToken(List<Tenant> configFile) throws Exception {
public Map<String, Map<String, String>> generateSessionToken() throws Exception {
// Step 1. Read session token payload values file
log.info("##Generating session token... ##");
log.debug("##Step 1. Read session token payload values file ##");
ObjectMapper objectMapper = new ObjectMapper();

// Step 2. Parse well known
log.debug("##Step 2. Parse well known ##");
URL wellKnownUrl = new URL(interopClientConfigs.getRemoteWellknownUrl());
URL wellKnownUrl = new URL(getRemoteWellknownUrl());
Map<String, String> wellKnownData = fetchWellKnown(wellKnownUrl.toString());
if (!wellKnownData.containsKey("kid") || !wellKnownData.containsKey("alg")) {
throw new IllegalStateException("Kid or alg not found.");
Expand Down Expand Up @@ -152,7 +138,7 @@ public Map<String, Map<String, String>> generateSessionToken(List<Tenant> config
log.debug("ST Payload Compiled: {}", stPayloadCompiled);

log.debug("## Step 5. Generate unsigned STs ##");
Map<String, Map<String, String>> unsignedSTs = unsignedStsGeneration(stHeaderCompiled, stPayloadCompiled, configFile, environment);
Map<String, Map<String, String>> unsignedSTs = unsignedStsGeneration(stHeaderCompiled, stPayloadCompiled, configFileReader.getTenantList(), environment);
log.debug("Unsigned STs: {}", unsignedSTs);

log.debug("## Step 6. Generate signed STs ##");
Expand Down Expand Up @@ -191,9 +177,8 @@ private static Map<String, String> fetchWellKnown(String wellKnownUrl) throws Ex
}


public Map<String, Map<String, String>> unsignedStsGeneration(
Map<String, String> stHeaderCompiled, HashMap<String, Object> stPayloadCompiled, List<Tenant> stPayloadValues, String environment) {

private Map<String, Map<String, String>> unsignedStsGeneration(Map<String, String> stHeaderCompiled,
HashMap<String, Object> stPayloadCompiled, List<Tenant> stPayloadValues, String environment) {
try {
log.debug("unsignedStsGeneration::Phase1:START: Build roles dynamic substitutions");
Map<String, Object> stsSubOutput = new HashMap<>();
Expand Down Expand Up @@ -290,7 +275,7 @@ private Map<String, Map<String, String>> signedStsGeneration(Map<String, Map<Str
}

// Base64 URL-safe encoding function (without padding)
public static String b64UrlEncode(String str) {
private static String b64UrlEncode(String str) {
return Base64.getUrlEncoder().withoutPadding().encodeToString(str.getBytes());
}

Expand Down Expand Up @@ -347,4 +332,8 @@ private boolean kmsVerify(String unsignedToken, SignResponse signature) {
}
}

public Map<String, Object> getSessionTokenPayloadTemplate() {
return SESSION_TOKEN_PAYLOAD_TEMPLATE;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package it.pagopa.interop.authorization.service.factory;

import it.pagopa.interop.authorization.service.utils.ConfigFileReader;
import it.pagopa.interop.conf.InteropClientConfigs;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Getter
@Setter
public class TracingTokenFactory extends SessionTokenFactory {
private static final String WELLKNOWN_URL = "https://tracing-qa-only-well-known-qa.s3.eu-south-1.amazonaws.com/.well-known/jwks.json";
private Map<String, Map<String, String>> cachedTokens = null;

public TracingTokenFactory(InteropClientConfigs interopClientConfigs, ConfigFileReader configFileReader) {
super(interopClientConfigs, configFileReader);
}

@Override
public Map<String, Map<String, String>> loadToken() {
getSessionTokenPayloadTemplate().put("aud", "{{ENVIRONMENT}}.interop.pagopa.it/m2m");
try {
if (cachedTokens == null) cachedTokens = generateSessionToken();
} catch (Exception ex) {
throw new IllegalArgumentException("There was an error while creating the session token: " + ex.getMessage(), ex);
}
return cachedTokens;
}

@Override
public String getRemoteWellknownUrl() {
return WELLKNOWN_URL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.stereotype.Component;

import it.pagopa.interop.authorization.service.IAuthorizationClient;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.conf.InteropClientConfigs;
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.ClientsApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.Client;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.interop.authorization.service.impl;

import it.pagopa.interop.authorization.service.IProducerClient;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.conf.InteropClientConfigs;
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.EservicesApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.ProducerEServiceDescriptor;
Expand Down
Loading

0 comments on commit fadaf56

Please sign in to comment.