From a66239c2a3f0bdc0c4fde28ab1c1e023e1cec309 Mon Sep 17 00:00:00 2001 From: Cato Olsen <olsen.cato@gmail.com> Date: Fri, 27 Oct 2023 08:33:29 +0200 Subject: [PATCH] =?UTF-8?q?Fjernet=20"boilerplate"=20fra=20resterende=20ap?= =?UTF-8?q?p'er=20sin=20bruk=20av=20ServerProperties=20for=20=C3=A5=20beho?= =?UTF-8?q?lde=20et=20konsistent=20pattern.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/adresseservice/config/Consumers.java | 29 +++++++++++++++ .../credentials/PdlServiceProperties.java | 11 ------ .../consumer/PdlAdresseConsumer.java | 14 ++++--- .../ameldingservice/config/Consumers.java | 29 +++++++++++++++ .../OppsummeringsdokumentConsumer.java | 28 +++++++------- ...OppsummeringsdokumentServerProperties.java | 14 ------- .../service/AMeldingService.java | 8 ++-- .../config/Consumers.java | 29 +++++++++++++++ .../credentials/AaregServiceProperties.java | 11 ------ .../consumer/AaregConsumer.java | 28 +++++++------- .../config/Consumers.java | 29 +++++++++++++++ .../consumer/DollyBackendConsumer.java | 15 ++++---- .../DollyBackendServiceProperties.java | 11 ------ .../apps/brukerservice/config/Consumers.java | 29 +++++++++++++++ .../PersonOrganisasjonTilgangConsumer.java | 32 ++++++++-------- ...nOrganisasjonTilgangServiceProperties.java | 11 ------ .../java/no/nav/dolly/budpro/Consumers.java | 29 +++++++++++++++ .../budpro/navn/GeneratedNameService.java | 25 ++++++------- .../config/Consumers.java | 29 +++++++++++++++ .../consumer/SyntAmeldingConsumer.java | 30 ++++++++------- .../credentials/SyntAmeldingProperties.java | 11 ------ .../consumer/SyntAmeldingConsumerTest.java | 5 ++- .../apps/hodejegeren/config/Consumers.java | 29 +++++++++++++++ .../hodejegeren/consumer/TpsfConsumer.java | 37 ++++++++++--------- .../credential/TpsfProxyProperties.java | 11 ------ .../importpersonservice/config/Consumers.java | 29 +++++++++++++++ .../consumer/PdlForvalterConsumer.java | 8 ++-- .../TestnavPdlForvalterProperties.java | 12 ------ .../config/Consumers.java | 29 +++++++++++++++ .../TestnavSafProxyServiceProperties.java | 12 ------ .../consumer/SafConsumer.java | 27 +++++++------- .../config/Consumers.java | 29 +++++++++++++++ .../AaregSyntServiceProperties.java | 11 ------ .../consumer/AaregSyntConsumer.java | 16 ++++---- .../config/Consumers.java | 29 +++++++++++++++ ...ganisasjonBestillingServiceProperties.java | 17 --------- .../OrganisasjonBestillingConsumer.java | 10 ++--- .../organisasjonservice/config/Consumers.java | 29 +++++++++++++++ .../credentials/EregServiceProperties.java | 12 ------ .../consumer/EregConsumer.java | 17 +++++---- ...sjonTilgangFrontendApplicationStarter.java | 13 +++---- .../config/Consumers.java | 29 +++++++++++++++ ...vOrganisasjonTilgangServiceProperties.java | 12 ------ .../personsearchservice/config/Consumers.java | 29 +++++++++++++++ .../credentials/PdlProxyProperties.java | 10 ----- .../consumer/ElasticSearchConsumer.java | 23 +++++++----- .../apps/personservice/config/Consumers.java | 29 +++++++++++++++ .../credentials/PdlProxyProperties.java | 12 ------ .../consumer/v1/PdlApiConsumer.java | 37 ++++++++++--------- .../consumer/v1/PdlTestdataConsumer.java | 37 +++++++++---------- .../consumer/v2/PdlPersonConsumer.java | 29 ++++++++------- .../testnorge/profil/config/Consumers.java | 29 +++++++++++++++ ...nOrganisasjonTilgangServiceProperties.java | 12 ------ .../PersonOrganisasjonTilgangConsumer.java | 36 ++++++++++-------- .../testnav/identpool/config/Consumers.java | 29 +++++++++++++++ .../TpsMessagingServiceProperties.java | 10 ----- .../consumers/TpsMessagingConsumer.java | 19 +++++----- .../no/nav/registre/tp/config/Consumers.java | 29 +++++++++++++++ .../tp/consumer/HodejegerenConsumer.java | 21 ++++++----- .../credential/HodejegerenProperties.java | 10 ----- .../tilbakemeldingapi/config/Consumers.java | 29 +++++++++++++++ .../credentials/ProfilServiceProperties.java | 12 ------ .../consumer/ProfilApiConsumer.java | 20 +++++----- .../tpsmessagingservice/config/Consumers.java | 29 +++++++++++++++ .../TestmiljoerServiceProperties.java | 11 ------ .../consumer/TestmiljoerServiceConsumer.java | 19 +++++----- 66 files changed, 898 insertions(+), 498 deletions(-) create mode 100644 apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/Consumers.java delete mode 100644 apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/credentials/PdlServiceProperties.java create mode 100644 apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/config/Consumers.java delete mode 100644 apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/credentials/OppsummeringsdokumentServerProperties.java create mode 100644 apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/Consumers.java delete mode 100644 apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/credentials/AaregServiceProperties.java create mode 100644 apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/config/Consumers.java delete mode 100644 apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/credentials/DollyBackendServiceProperties.java create mode 100644 apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/config/Consumers.java delete mode 100644 apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/credentials/PersonOrganisasjonTilgangServiceProperties.java create mode 100644 apps/budpro-service/src/main/java/no/nav/dolly/budpro/Consumers.java create mode 100644 apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/config/Consumers.java delete mode 100644 apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/credentials/SyntAmeldingProperties.java create mode 100644 apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/config/Consumers.java delete mode 100644 apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/credential/TpsfProxyProperties.java create mode 100644 apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/config/Consumers.java delete mode 100644 apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/credentias/TestnavPdlForvalterProperties.java create mode 100644 apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/Consumers.java delete mode 100644 apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/credentias/TestnavSafProxyServiceProperties.java create mode 100644 apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/Consumers.java delete mode 100644 apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/credentials/AaregSyntServiceProperties.java create mode 100644 apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/Consumers.java delete mode 100644 apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/credentials/OrganisasjonBestillingServiceProperties.java create mode 100644 apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/Consumers.java delete mode 100644 apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/credentials/EregServiceProperties.java create mode 100644 apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/config/Consumers.java delete mode 100644 apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/credentials/TestnavOrganisasjonTilgangServiceProperties.java create mode 100644 apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/Consumers.java delete mode 100644 apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/credentials/PdlProxyProperties.java create mode 100644 apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/Consumers.java delete mode 100644 apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/credentials/PdlProxyProperties.java create mode 100644 apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/Consumers.java delete mode 100644 apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/TestnavPersonOrganisasjonTilgangServiceProperties.java create mode 100644 apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/Consumers.java delete mode 100644 apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/credentials/TpsMessagingServiceProperties.java create mode 100644 apps/testnorge-tp/src/main/java/no/nav/registre/tp/config/Consumers.java delete mode 100644 apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/credential/HodejegerenProperties.java create mode 100644 apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/Consumers.java delete mode 100644 apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/credentials/ProfilServiceProperties.java create mode 100644 apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/Consumers.java delete mode 100644 apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/credentials/TestmiljoerServiceProperties.java diff --git a/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/Consumers.java b/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/Consumers.java new file mode 100644 index 00000000000..b684a79e257 --- /dev/null +++ b/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.adresseservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties pdlServices; + +} diff --git a/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/credentials/PdlServiceProperties.java b/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/credentials/PdlServiceProperties.java deleted file mode 100644 index f27e2494679..00000000000 --- a/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/config/credentials/PdlServiceProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.testnav.apps.adresseservice.config.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.pdl-services") -public class PdlServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/consumer/PdlAdresseConsumer.java b/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/consumer/PdlAdresseConsumer.java index 49931250099..c70e707f816 100644 --- a/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/consumer/PdlAdresseConsumer.java +++ b/apps/adresse-service/src/main/java/no/nav/testnav/apps/adresseservice/consumer/PdlAdresseConsumer.java @@ -1,6 +1,6 @@ package no.nav.testnav.apps.adresseservice.consumer; -import no.nav.testnav.apps.adresseservice.config.credentials.PdlServiceProperties; +import no.nav.testnav.apps.adresseservice.config.Consumers; import no.nav.testnav.apps.adresseservice.consumer.command.PdlAdresseSoekCommand; import no.nav.testnav.apps.adresseservice.dto.GraphQLRequest; import no.nav.testnav.apps.adresseservice.dto.PdlAdresseResponse; @@ -13,19 +13,21 @@ public class PdlAdresseConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final ServerProperties properties; + private final ServerProperties serverProperties; - public PdlAdresseConsumer(TokenExchange tokenExchange, PdlServiceProperties properties) { + public PdlAdresseConsumer( + TokenExchange tokenExchange, + Consumers consumers) { this.tokenExchange = tokenExchange; - this.properties = properties; + serverProperties = consumers.getPdlServices(); this.webClient = WebClient .builder() - .baseUrl(properties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } public PdlAdresseResponse sendAdressesoek(GraphQLRequest adresseQuery) { - return tokenExchange.exchange(properties) + return tokenExchange.exchange(serverProperties) .flatMap(token -> new PdlAdresseSoekCommand(webClient, adresseQuery, token.getTokenValue()).call()) .block(); } diff --git a/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/config/Consumers.java b/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/config/Consumers.java new file mode 100644 index 00000000000..90798e40fb2 --- /dev/null +++ b/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnav.ameldingservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties oppsummeringsdokumentService; + +} diff --git a/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/consumer/OppsummeringsdokumentConsumer.java b/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/consumer/OppsummeringsdokumentConsumer.java index e3ef3513084..f3c83c07043 100644 --- a/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/consumer/OppsummeringsdokumentConsumer.java +++ b/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/consumer/OppsummeringsdokumentConsumer.java @@ -1,7 +1,7 @@ package no.nav.registre.testnav.ameldingservice.consumer; import com.fasterxml.jackson.databind.ObjectMapper; -import no.nav.registre.testnav.ameldingservice.credentials.OppsummeringsdokumentServerProperties; +import no.nav.registre.testnav.ameldingservice.config.Consumers; import no.nav.testnav.libs.commands.GetOppsummeringsdokumentByIdCommand; import no.nav.testnav.libs.commands.GetOppsummeringsdokumentCommand; import no.nav.testnav.libs.commands.SaveOppsummeringsdokumenterCommand; @@ -25,23 +25,25 @@ public class OppsummeringsdokumentConsumer { private final ApplicationProperties applicationProperties; public OppsummeringsdokumentConsumer( - OppsummeringsdokumentServerProperties properties, + Consumers consumers, ObjectMapper objectMapper, ApplicationProperties applicationProperties) { - this.applicationProperties = applicationProperties; this.webClient = WebClient .builder() - .baseUrl(properties.getUrl()) - .codecs(clientDefaultCodecsConfigurer -> { - clientDefaultCodecsConfigurer.defaultCodecs().maxInMemorySize(BYTE_COUNT); - clientDefaultCodecsConfigurer - .defaultCodecs() - .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - clientDefaultCodecsConfigurer - .defaultCodecs() - .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }) + .baseUrl(consumers.getOppsummeringsdokumentService().getUrl()) + .codecs( + clientDefaultCodecsConfigurer -> { + clientDefaultCodecsConfigurer + .defaultCodecs() + .maxInMemorySize(BYTE_COUNT); + clientDefaultCodecsConfigurer + .defaultCodecs() + .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); + clientDefaultCodecsConfigurer + .defaultCodecs() + .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); + }) .build(); } diff --git a/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/credentials/OppsummeringsdokumentServerProperties.java b/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/credentials/OppsummeringsdokumentServerProperties.java deleted file mode 100644 index 4f4d3426e6b..00000000000 --- a/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/credentials/OppsummeringsdokumentServerProperties.java +++ /dev/null @@ -1,14 +0,0 @@ -package no.nav.registre.testnav.ameldingservice.credentials; - -import lombok.Getter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Getter -@Configuration -@ConfigurationProperties(prefix = "consumers.oppsummeringsdokument-service") -public class OppsummeringsdokumentServerProperties extends ServerProperties { -} diff --git a/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/service/AMeldingService.java b/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/service/AMeldingService.java index 2873263cd77..117a241c0fe 100644 --- a/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/service/AMeldingService.java +++ b/apps/amelding-service/src/main/java/no/nav/registre/testnav/ameldingservice/service/AMeldingService.java @@ -1,8 +1,8 @@ package no.nav.registre.testnav.ameldingservice.service; import lombok.RequiredArgsConstructor; +import no.nav.registre.testnav.ameldingservice.config.Consumers; import no.nav.registre.testnav.ameldingservice.consumer.OppsummeringsdokumentConsumer; -import no.nav.registre.testnav.ameldingservice.credentials.OppsummeringsdokumentServerProperties; import no.nav.registre.testnav.ameldingservice.domain.AMelding; import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; import no.nav.testnav.libs.securitycore.domain.AccessToken; @@ -13,11 +13,11 @@ @RequiredArgsConstructor public class AMeldingService { private final OppsummeringsdokumentConsumer oppsummeringsdokumentConsumer; - private final OppsummeringsdokumentServerProperties applicationProperties; + private final Consumers consumers; private final TokenExchange tokenExchange; public Mono<String> save(AMelding aMelding, String miljo) { - return tokenExchange.exchange(applicationProperties).flatMap(accessToken -> oppsummeringsdokumentConsumer + return tokenExchange.exchange(consumers.getOppsummeringsdokumentService()).flatMap(accessToken -> oppsummeringsdokumentConsumer .get( aMelding.getOpplysningspliktigOrganisajonsnummer(), aMelding.getKalendermaaned(), @@ -29,7 +29,7 @@ public Mono<String> save(AMelding aMelding, String miljo) { } public Mono<AMelding> get(String id) { - Mono<String> accessToken = tokenExchange.exchange(applicationProperties).map(AccessToken::getTokenValue); + Mono<String> accessToken = tokenExchange.exchange(consumers.getOppsummeringsdokumentService()).map(AccessToken::getTokenValue); return oppsummeringsdokumentConsumer.get(id, accessToken).map(AMelding::new); } } diff --git a/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/Consumers.java b/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/Consumers.java new file mode 100644 index 00000000000..38f7ef3b5f9 --- /dev/null +++ b/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.arbeidsforholdservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavAaregProxy; + +} diff --git a/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/credentials/AaregServiceProperties.java b/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/credentials/AaregServiceProperties.java deleted file mode 100644 index 6d75d467b89..00000000000 --- a/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/config/credentials/AaregServiceProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.registre.testnorge.arbeidsforholdservice.config.credentials; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-aareg-proxy") -public class AaregServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/consumer/AaregConsumer.java b/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/consumer/AaregConsumer.java index 9e44ddd8680..a148b946e8e 100644 --- a/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/consumer/AaregConsumer.java +++ b/apps/arbeidsforhold-service/src/main/java/no/nav/registre/testnorge/arbeidsforholdservice/consumer/AaregConsumer.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.testnorge.arbeidsforholdservice.config.credentials.AaregServiceProperties; +import no.nav.registre.testnorge.arbeidsforholdservice.config.Consumers; import no.nav.registre.testnorge.arbeidsforholdservice.consumer.command.GetArbeidstakerArbeidsforholdCommand; import no.nav.registre.testnorge.arbeidsforholdservice.consumer.dto.ArbeidsforholdDTO; import no.nav.testnav.libs.securitycore.domain.ServerProperties; @@ -30,21 +30,23 @@ public class AaregConsumer { private final TokenExchange tokenExchange; public AaregConsumer( - AaregServiceProperties serverProperties, + Consumers consumers, TokenExchange tokenExchange, ObjectMapper objectMapper) { - - this.serverProperties = serverProperties; + serverProperties = consumers.getTestnavAaregProxy(); this.tokenExchange = tokenExchange; - - ExchangeStrategies jacksonStrategy = ExchangeStrategies.builder() - .codecs(config -> { - config.defaultCodecs() - .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - config.defaultCodecs() - .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }).build(); - + ExchangeStrategies jacksonStrategy = ExchangeStrategies + .builder() + .codecs( + config -> { + config + .defaultCodecs() + .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); + config + .defaultCodecs() + .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); + }) + .build(); this.webClient = WebClient .builder() .exchangeStrategies(jacksonStrategy) diff --git a/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/config/Consumers.java b/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/config/Consumers.java new file mode 100644 index 00000000000..f6a07c0ea2d --- /dev/null +++ b/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.batchbestillingservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties dollyBackend; + +} diff --git a/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/consumer/DollyBackendConsumer.java b/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/consumer/DollyBackendConsumer.java index 5dd3f928c2d..bc542df61cf 100644 --- a/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/consumer/DollyBackendConsumer.java +++ b/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/consumer/DollyBackendConsumer.java @@ -3,7 +3,7 @@ import lombok.extern.slf4j.Slf4j; import no.nav.registre.testnorge.batchbestillingservice.command.GetAktiveBestillingerCommand; import no.nav.registre.testnorge.batchbestillingservice.command.PostBestillingCommand; -import no.nav.registre.testnorge.batchbestillingservice.credentials.DollyBackendServiceProperties; +import no.nav.registre.testnorge.batchbestillingservice.config.Consumers; import no.nav.registre.testnorge.batchbestillingservice.request.RsDollyBestillingRequest; import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange; @@ -21,18 +21,17 @@ public class DollyBackendConsumer { private final WebClient webClient; private final TokenExchange tokenService; - private final ServerProperties serviceProperties; + private final ServerProperties serverProperties; public DollyBackendConsumer( - DollyBackendServiceProperties properties, + Consumers consumers, TokenExchange tokenService, WebClient.Builder webClientBuilder ) { - - this.serviceProperties = properties; + serverProperties = consumers.getDollyBackend(); this.tokenService = tokenService; this.webClient = webClientBuilder - .baseUrl(serviceProperties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } @@ -41,7 +40,7 @@ public void postDollyBestilling(Long gruppeId, RsDollyBestillingRequest request, request.setAntall(antall.intValue()); tokenService - .exchange(serviceProperties) + .exchange(serverProperties) .map(token -> new PostBestillingCommand(webClient, token.getTokenValue(), gruppeId, request).call()) .doOnError(error -> log.error("Bestilling feilet for gruppe {}", gruppeId, error)) .doOnSuccess(response -> log.info("Bestilling med {} identer startet i backend for gruppe {}", antall, gruppeId)) @@ -53,7 +52,7 @@ public List<Object> getAktiveBestillinger(Long gruppeId) { return Optional .ofNullable( tokenService - .exchange(serviceProperties) + .exchange(serverProperties) .map(token -> new GetAktiveBestillingerCommand(webClient, token.getTokenValue(), gruppeId).call()) .doOnError(error -> log.error("Henting av aktive bestillinger feilet for gruppe {}", gruppeId, error)) .onErrorReturn(Flux.empty()) diff --git a/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/credentials/DollyBackendServiceProperties.java b/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/credentials/DollyBackendServiceProperties.java deleted file mode 100644 index caa8d3294bf..00000000000 --- a/apps/batch-bestilling-service/src/main/java/no/nav/registre/testnorge/batchbestillingservice/credentials/DollyBackendServiceProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.registre.testnorge.batchbestillingservice.credentials; - - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.dolly-backend") -public class DollyBackendServiceProperties extends ServerProperties { -} diff --git a/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/config/Consumers.java b/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/config/Consumers.java new file mode 100644 index 00000000000..51662bd8e36 --- /dev/null +++ b/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.brukerservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavPersonOrganisasjonTilgangService; + +} diff --git a/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/PersonOrganisasjonTilgangConsumer.java b/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/PersonOrganisasjonTilgangConsumer.java index 15754020f6f..e48fb284892 100644 --- a/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/PersonOrganisasjonTilgangConsumer.java +++ b/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/PersonOrganisasjonTilgangConsumer.java @@ -1,15 +1,15 @@ package no.nav.testnav.apps.brukerservice.consumer; import com.fasterxml.jackson.databind.ObjectMapper; +import no.nav.testnav.apps.brukerservice.config.Consumers; import no.nav.testnav.apps.brukerservice.consumer.command.GetOrganisasjonCommand; -import no.nav.testnav.apps.brukerservice.consumer.credentials.PersonOrganisasjonTilgangServiceProperties; import no.nav.testnav.apps.brukerservice.domain.Organisasjon; import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import org.springframework.http.MediaType; import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.stereotype.Component; - import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -17,34 +17,34 @@ @Component public class PersonOrganisasjonTilgangConsumer { private final WebClient webClient; - private final PersonOrganisasjonTilgangServiceProperties properties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public PersonOrganisasjonTilgangConsumer( - PersonOrganisasjonTilgangServiceProperties properties, + Consumers consumers, TokenExchange tokenExchange, ObjectMapper objectMapper) { - - this.properties = properties; + serverProperties = consumers.getTestnavPersonOrganisasjonTilgangService(); this.tokenExchange = tokenExchange; - ExchangeStrategies jacksonStrategy = ExchangeStrategies.builder() - .codecs(config -> { - config.defaultCodecs() - .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - config.defaultCodecs() - .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }) + ExchangeStrategies jacksonStrategy = ExchangeStrategies + .builder() + .codecs( + config -> { + config.defaultCodecs() + .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); + config.defaultCodecs() + .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); + }) .build(); - this.webClient = WebClient .builder() .exchangeStrategies(jacksonStrategy) - .baseUrl(properties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } public Mono<Organisasjon> getOrganisasjon(String orgnummer) { - return tokenExchange.exchange(properties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new GetOrganisasjonCommand(webClient, orgnummer, accessToken.getTokenValue()).call()) .map(Organisasjon::new); } diff --git a/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/credentials/PersonOrganisasjonTilgangServiceProperties.java b/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/credentials/PersonOrganisasjonTilgangServiceProperties.java deleted file mode 100644 index 982f85fec93..00000000000 --- a/apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/credentials/PersonOrganisasjonTilgangServiceProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.testnav.apps.brukerservice.consumer.credentials; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-person-organisasjon-tilgang-service") -public class PersonOrganisasjonTilgangServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/budpro-service/src/main/java/no/nav/dolly/budpro/Consumers.java b/apps/budpro-service/src/main/java/no/nav/dolly/budpro/Consumers.java new file mode 100644 index 00000000000..92e2d8851bf --- /dev/null +++ b/apps/budpro-service/src/main/java/no/nav/dolly/budpro/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.dolly.budpro; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties genererNavnService; + +} diff --git a/apps/budpro-service/src/main/java/no/nav/dolly/budpro/navn/GeneratedNameService.java b/apps/budpro-service/src/main/java/no/nav/dolly/budpro/navn/GeneratedNameService.java index d318c452625..686b4bc56de 100644 --- a/apps/budpro-service/src/main/java/no/nav/dolly/budpro/navn/GeneratedNameService.java +++ b/apps/budpro-service/src/main/java/no/nav/dolly/budpro/navn/GeneratedNameService.java @@ -1,11 +1,10 @@ package no.nav.dolly.budpro.navn; +import no.nav.dolly.budpro.Consumers; import no.nav.testnav.libs.commands.generernavnservice.v1.GenererNavnCommand; import no.nav.testnav.libs.reactivecore.config.WebClientConfig; import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; @@ -16,23 +15,27 @@ @Import(WebClientConfig.class) public class GeneratedNameService { - private final GenererNavnServiceProperties properties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; private final WebClient webClient; - GeneratedNameService(GenererNavnServiceProperties properties, TokenExchange tokenExchange, WebClient.Builder webClientBuilder) { - this.properties = properties; + GeneratedNameService( + Consumers consumers, + TokenExchange tokenExchange, + WebClient.Builder webClientBuilder + ) { + serverProperties = consumers.getGenererNavnService(); this.tokenExchange = tokenExchange; this.webClient = webClientBuilder - .baseUrl(properties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } public String[] getNames(Long seed, int number) { var accessToken = tokenExchange - .exchange(properties) + .exchange(serverProperties) .blockOptional() - .orElseThrow(() -> new IllegalStateException("Failed to get token for %s".formatted(properties.getName()))) + .orElseThrow(() -> new IllegalStateException("Failed to get token for %s".formatted(serverProperties.getName()))) .getTokenValue(); var arrayOfDTOs = new GenererNavnCommand(webClient, accessToken, seed, number) .call(); @@ -43,10 +46,4 @@ public String[] getNames(Long seed, int number) { .toArray(new String[0]); } - @Configuration - @ConfigurationProperties(prefix = "consumers.generer-navn-service") - public static class GenererNavnServiceProperties extends ServerProperties { - - } - } diff --git a/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/config/Consumers.java b/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/config/Consumers.java new file mode 100644 index 00000000000..3ab25367a16 --- /dev/null +++ b/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.generersyntameldingservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties syntAmelding; + +} diff --git a/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumer.java b/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumer.java index de30dcf54e0..5ff0de5ac43 100644 --- a/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumer.java +++ b/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumer.java @@ -1,8 +1,8 @@ package no.nav.registre.testnorge.generersyntameldingservice.consumer; +import no.nav.registre.testnorge.generersyntameldingservice.config.Consumers; import no.nav.registre.testnorge.generersyntameldingservice.consumer.command.PostHentArbeidsforholdCommand; import no.nav.registre.testnorge.generersyntameldingservice.consumer.command.PostHentHistorikkCommand; -import no.nav.registre.testnorge.generersyntameldingservice.consumer.credentials.SyntAmeldingProperties; import no.nav.registre.testnorge.generersyntameldingservice.domain.ArbeidsforholdType; import no.nav.testnav.libs.domain.dto.aareg.amelding.Arbeidsforhold; import no.nav.testnav.libs.domain.dto.aareg.amelding.ArbeidsforholdPeriode; @@ -18,33 +18,35 @@ public class SyntAmeldingConsumer { private final WebClient webClient; - private final ServerProperties properties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public SyntAmeldingConsumer(TokenExchange tokenExchange, - SyntAmeldingProperties properties) { - + Consumers consumers) { this.tokenExchange = tokenExchange; - this.properties = properties; - this.webClient = WebClient.builder() - .exchangeStrategies(ExchangeStrategies.builder() - .codecs(configurer -> configurer - .defaultCodecs() - .maxInMemorySize(16 * 1024 * 1024)) - .build()) - .baseUrl(properties.getUrl()) + serverProperties = consumers.getSyntAmelding(); + this.webClient = WebClient + .builder() + .exchangeStrategies( + ExchangeStrategies + .builder() + .codecs(configurer -> configurer + .defaultCodecs() + .maxInMemorySize(16 * 1024 * 1024)) + .build()) + .baseUrl(serverProperties.getUrl()) .build(); } public Arbeidsforhold getEnkeltArbeidsforhold(ArbeidsforholdPeriode periode, ArbeidsforholdType arbeidsforholdType) { - return tokenExchange.exchange(properties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new PostHentArbeidsforholdCommand( webClient, periode, arbeidsforholdType.getPath(), accessToken.getTokenValue()).call()) .block(); } public List<Arbeidsforhold> getHistorikk(Arbeidsforhold arbeidsforhold) { - return tokenExchange.exchange(properties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new PostHentHistorikkCommand( webClient, arbeidsforhold, accessToken.getTokenValue()).call()) .block(); diff --git a/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/credentials/SyntAmeldingProperties.java b/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/credentials/SyntAmeldingProperties.java deleted file mode 100644 index 34466f8d269..00000000000 --- a/apps/generer-synt-amelding-service/src/main/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/credentials/SyntAmeldingProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.registre.testnorge.generersyntameldingservice.consumer.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.synt-amelding") -public class SyntAmeldingProperties extends ServerProperties{ -} diff --git a/apps/generer-synt-amelding-service/src/test/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumerTest.java b/apps/generer-synt-amelding-service/src/test/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumerTest.java index d2d6508b003..efbc634fe2e 100644 --- a/apps/generer-synt-amelding-service/src/test/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumerTest.java +++ b/apps/generer-synt-amelding-service/src/test/java/no/nav/registre/testnorge/generersyntameldingservice/consumer/SyntAmeldingConsumerTest.java @@ -1,10 +1,10 @@ package no.nav.registre.testnorge.generersyntameldingservice.consumer; -import no.nav.registre.testnorge.generersyntameldingservice.consumer.credentials.SyntAmeldingProperties; import no.nav.registre.testnorge.generersyntameldingservice.domain.ArbeidsforholdType; import no.nav.testnav.libs.domain.dto.aareg.amelding.Arbeidsforhold; import no.nav.testnav.libs.domain.dto.aareg.amelding.ArbeidsforholdPeriode; import no.nav.testnav.libs.securitycore.domain.AccessToken; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,6 +33,7 @@ @AutoConfigureWireMock(port = 0) class SyntAmeldingConsumerTest { + @SuppressWarnings("unused") @MockBean private JwtDecoder jwtDecoder; @@ -44,7 +45,7 @@ class SyntAmeldingConsumerTest { @BeforeEach public void setup() { - when(tokenExchange.exchange(ArgumentMatchers.any(SyntAmeldingProperties.class))).thenReturn(Mono.just(new AccessToken("token"))); + when(tokenExchange.exchange(ArgumentMatchers.any(ServerProperties.class))).thenReturn(Mono.just(new AccessToken("token"))); } @Test diff --git a/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/config/Consumers.java b/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/config/Consumers.java new file mode 100644 index 00000000000..fdc9e87ee5d --- /dev/null +++ b/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.hodejegeren.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties tpsfProxy; + +} diff --git a/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/TpsfConsumer.java b/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/TpsfConsumer.java index f8f3a7b0540..25ba1d929e9 100644 --- a/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/TpsfConsumer.java +++ b/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/TpsfConsumer.java @@ -3,13 +3,14 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.core.annotation.Timed; +import no.nav.testnav.apps.hodejegeren.config.Consumers; import no.nav.testnav.apps.hodejegeren.consumer.command.GetTpsIdenterCommand; import no.nav.testnav.apps.hodejegeren.consumer.command.GetTpsServiceRoutineV1Command; import no.nav.testnav.apps.hodejegeren.consumer.command.GetTpsServiceRoutineV2Command; import no.nav.testnav.apps.hodejegeren.consumer.command.GetTpsStatusPaaIdenterCommand; -import no.nav.testnav.apps.hodejegeren.consumer.credential.TpsfProxyProperties; import no.nav.testnav.apps.hodejegeren.consumer.dto.ServiceRoutineDTO; import no.nav.testnav.libs.securitycore.domain.AccessToken; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.apache.tomcat.util.buf.StringUtils; import org.springframework.http.client.reactive.ReactorClientHttpConnector; @@ -29,26 +30,28 @@ public class TpsfConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final TpsfProxyProperties serviceProperties; + private final ServerProperties serverProperties; public TpsfConsumer( - TpsfProxyProperties serviceProperties, + Consumers consumers, TokenExchange tokenExchange ) { - this.serviceProperties = serviceProperties; + serverProperties = consumers.getTpsfProxy(); this.tokenExchange = tokenExchange; - HttpClient client = HttpClient .create() .responseTimeout(Duration.ofMinutes(2)); - - this.webClient = WebClient.builder() - .exchangeStrategies(ExchangeStrategies.builder() - .codecs(configurer -> configurer - .defaultCodecs() - .maxInMemorySize(16 * 1024 * 1024)) - .build()) - .baseUrl(serviceProperties.getUrl()) + this.webClient = WebClient + .builder() + .exchangeStrategies( + ExchangeStrategies + .builder() + .codecs( + configurer -> configurer + .defaultCodecs() + .maxInMemorySize(16 * 1024 * 1024)) + .build()) + .baseUrl(serverProperties.getUrl()) .clientConnector(new ReactorClientHttpConnector(client)) .build(); } @@ -59,7 +62,7 @@ public Set<String> getIdenterFiltrertPaaAarsakskode( List<String> aarsakskode, String transaksjonstype ) { - return tokenExchange.exchange(serviceProperties).flatMap(accessToken -> new GetTpsIdenterCommand( + return tokenExchange.exchange(serverProperties).flatMap(accessToken -> new GetTpsIdenterCommand( webClient, accessToken.getTokenValue(), StringUtils.join(aarsakskode, ','), @@ -73,14 +76,14 @@ public JsonNode getTpsServiceRoutine( String miljoe, String fnr ) throws IOException { - var response = tokenExchange.exchange(serviceProperties) + var response = tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new GetTpsServiceRoutineV1Command( webClient, accessToken.getTokenValue(), routineName, aksjonsKode, miljoe, fnr).call()).block(); return new ObjectMapper().readTree(response); } public Mono<AccessToken> getToken() { - return tokenExchange.exchange(serviceProperties); + return tokenExchange.exchange(serverProperties); } public Flux<ServiceRoutineDTO> getTpsServiceRoutineV2(String routineName, String aksjonsKode, String miljoe, String fnr, AccessToken token) { @@ -94,7 +97,7 @@ public JsonNode hentTpsStatusPaaIdenter( List<String> identer ) throws IOException { var identerSomString = String.join(",", identer); - var response = tokenExchange.exchange(serviceProperties).flatMap(accessToken -> + var response = tokenExchange.exchange(serverProperties).flatMap(accessToken -> new GetTpsStatusPaaIdenterCommand( webClient, accessToken.getTokenValue(), aksjonskode, identer.size(), miljoe, identerSomString).call()) .block(); diff --git a/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/credential/TpsfProxyProperties.java b/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/credential/TpsfProxyProperties.java deleted file mode 100644 index cf5dd9c1081..00000000000 --- a/apps/hodejegeren/src/main/java/no/nav/testnav/apps/hodejegeren/consumer/credential/TpsfProxyProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.testnav.apps.hodejegeren.consumer.credential; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.tpsf-proxy") -public class TpsfProxyProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/config/Consumers.java b/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/config/Consumers.java new file mode 100644 index 00000000000..5b3b1edac09 --- /dev/null +++ b/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.importpersonservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavPdlForvalter; + +} diff --git a/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/consumer/PdlForvalterConsumer.java b/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/consumer/PdlForvalterConsumer.java index f17db02d5dd..4b68679fc21 100644 --- a/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/consumer/PdlForvalterConsumer.java +++ b/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/consumer/PdlForvalterConsumer.java @@ -1,9 +1,9 @@ package no.nav.testnav.apps.importpersonservice.consumer; +import no.nav.testnav.apps.importpersonservice.config.Consumers; import no.nav.testnav.apps.importpersonservice.consumer.command.OppdaterPersonCommand; import no.nav.testnav.apps.importpersonservice.consumer.command.SendPersonTilPdlCommand; import no.nav.testnav.apps.importpersonservice.consumer.request.OppdaterPersonRequest; -import no.nav.testnav.apps.importpersonservice.credentias.TestnavPdlForvalterProperties; import no.nav.testnav.apps.importpersonservice.domain.PersonList; import no.nav.testnav.libs.dto.pdlforvalter.v1.OrdreResponseDTO; import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; @@ -21,12 +21,10 @@ public class PdlForvalterConsumer { private final TokenExchange tokenExchange; public PdlForvalterConsumer( - TestnavPdlForvalterProperties serverProperties, + Consumers consumers, TokenExchange tokenExchange) { - - this.serverProperties = serverProperties; + serverProperties = consumers.getTestnavPdlForvalter(); this.tokenExchange = tokenExchange; - this.webClient = WebClient .builder() .baseUrl(serverProperties.getUrl()) diff --git a/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/credentias/TestnavPdlForvalterProperties.java b/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/credentias/TestnavPdlForvalterProperties.java deleted file mode 100644 index c039fc51126..00000000000 --- a/apps/import-person-service/src/main/java/no/nav/testnav/apps/importpersonservice/credentias/TestnavPdlForvalterProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.testnav.apps.importpersonservice.credentias; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-pdl-forvalter") -public class TestnavPdlForvalterProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/Consumers.java b/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/Consumers.java new file mode 100644 index 00000000000..73a75fdbee3 --- /dev/null +++ b/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.joarkdokumentservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavSafProxy; + +} diff --git a/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/credentias/TestnavSafProxyServiceProperties.java b/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/credentias/TestnavSafProxyServiceProperties.java deleted file mode 100644 index 4448eae36c4..00000000000 --- a/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/config/credentias/TestnavSafProxyServiceProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.testnav.joarkdokumentservice.config.credentias; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-saf-proxy") -public class TestnavSafProxyServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/consumer/SafConsumer.java b/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/consumer/SafConsumer.java index b31aa876627..88268b987eb 100644 --- a/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/consumer/SafConsumer.java +++ b/apps/joark-dokument-service/src/main/java/no/nav/testnav/joarkdokumentservice/consumer/SafConsumer.java @@ -1,7 +1,7 @@ package no.nav.testnav.joarkdokumentservice.consumer; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.joarkdokumentservice.config.credentias.TestnavSafProxyServiceProperties; +import no.nav.testnav.joarkdokumentservice.config.Consumers; import no.nav.testnav.joarkdokumentservice.consumer.command.GetDokumentCommand; import no.nav.testnav.joarkdokumentservice.consumer.command.GetDokumentInfoCommand; import no.nav.testnav.joarkdokumentservice.consumer.command.GetPDFCommand; @@ -10,7 +10,6 @@ import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.stereotype.Component; - import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; @@ -21,25 +20,27 @@ public class SafConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final ServerProperties properties; + private final ServerProperties serverProperties; public SafConsumer( - TestnavSafProxyServiceProperties properties, + Consumers consumers, TokenExchange tokenExchange) { - this.tokenExchange = tokenExchange; - this.properties = properties; - this.webClient = WebClient.builder() + serverProperties = consumers.getTestnavSafProxy(); + this.webClient = WebClient + .builder() .exchangeStrategies( - ExchangeStrategies.builder() - .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * 50)).build()) - .baseUrl(properties.getUrl()) + ExchangeStrategies + .builder() + .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * 50)) + .build()) + .baseUrl(serverProperties.getUrl()) .build(); } public JournalpostDTO getJournalpost(String journalpostId, String miljo) { return tokenExchange - .exchange(properties) + .exchange(serverProperties) .flatMap(accessToken -> new GetDokumentInfoCommand( webClient, accessToken.getTokenValue(), @@ -58,7 +59,7 @@ public JournalpostDTO getJournalpost(String journalpostId, String miljo) { public String getDokument(String journalpostId, String dokumentInfoId, DokumentType dokumentType, String miljo) { return tokenExchange - .exchange(properties) + .exchange(serverProperties) .flatMap(accessToken -> new GetDokumentCommand( webClient, accessToken.getTokenValue(), @@ -72,7 +73,7 @@ public String getDokument(String journalpostId, String dokumentInfoId, DokumentT public byte[] getPDF(String journalpostId, String dokumentInfoId, String miljo) { return tokenExchange - .exchange(properties) + .exchange(serverProperties) .flatMap(accessToken -> new GetPDFCommand( webClient, accessToken.getTokenValue(), diff --git a/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/Consumers.java b/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/Consumers.java new file mode 100644 index 00000000000..5692ee22c85 --- /dev/null +++ b/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.oppsummeringsdokumentservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties aaregSyntServices; + +} diff --git a/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/credentials/AaregSyntServiceProperties.java b/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/credentials/AaregSyntServiceProperties.java deleted file mode 100644 index 42ade9ab8d4..00000000000 --- a/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/config/credentials/AaregSyntServiceProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.testnav.apps.oppsummeringsdokumentservice.config.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.aareg-synt-services") -public class AaregSyntServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/consumer/AaregSyntConsumer.java b/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/consumer/AaregSyntConsumer.java index 2f4f456ee75..ffc3c7e5d2e 100644 --- a/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/consumer/AaregSyntConsumer.java +++ b/apps/oppsummeringsdokument-service/src/main/java/no/nav/testnav/apps/oppsummeringsdokumentservice/consumer/AaregSyntConsumer.java @@ -2,7 +2,7 @@ import io.swagger.v3.core.util.Json; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.apps.oppsummeringsdokumentservice.config.credentials.AaregSyntServiceProperties; +import no.nav.testnav.apps.oppsummeringsdokumentservice.config.Consumers; import no.nav.testnav.apps.oppsummeringsdokumentservice.consumer.command.SaveOpplysningspliktigCommand; import no.nav.testnav.apps.oppsummeringsdokumentservice.domain.Oppsummeringsdokument; import no.nav.testnav.libs.securitycore.domain.ServerProperties; @@ -17,16 +17,16 @@ public class AaregSyntConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final ServerProperties properties; - - public AaregSyntConsumer(TokenExchange tokenExchange, - AaregSyntServiceProperties properties) { + private final ServerProperties serverProperties; + public AaregSyntConsumer( + TokenExchange tokenExchange, + Consumers consumers) { this.tokenExchange = tokenExchange; - this.properties = properties; + serverProperties = consumers.getAaregSyntServices(); this.webClient = WebClient .builder() - .baseUrl(properties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } @@ -41,7 +41,7 @@ public void saveOpplysningspliktig(Oppsummeringsdokument oppsummeringsdokument, } private String getAccessToken() { - var token = tokenExchange.exchange(properties).block(); + var token = tokenExchange.exchange(serverProperties).block(); if (isNull(token)) { throw new IllegalArgumentException("Klarte ikke å generere AccessToken for AaregSyntService"); } diff --git a/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/Consumers.java b/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/Consumers.java new file mode 100644 index 00000000000..9eef5389340 --- /dev/null +++ b/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.organisasjonfastedataservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties organisasjonBestillingService; + +} diff --git a/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/credentials/OrganisasjonBestillingServiceProperties.java b/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/credentials/OrganisasjonBestillingServiceProperties.java deleted file mode 100644 index d52d41670bd..00000000000 --- a/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/config/credentials/OrganisasjonBestillingServiceProperties.java +++ /dev/null @@ -1,17 +0,0 @@ -package no.nav.registre.testnorge.organisasjonfastedataservice.config.credentials; - - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Setter -@Getter -@Configuration -@ConfigurationProperties(prefix = "consumers.organisasjon-bestilling-service") -public class OrganisasjonBestillingServiceProperties extends ServerProperties { - private Integer threads; -} diff --git a/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/consumer/OrganisasjonBestillingConsumer.java b/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/consumer/OrganisasjonBestillingConsumer.java index 41799f96c70..89d98e35e9c 100644 --- a/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/consumer/OrganisasjonBestillingConsumer.java +++ b/apps/organisasjon-faste-data-service/src/main/java/no/nav/registre/testnorge/organisasjonfastedataservice/consumer/OrganisasjonBestillingConsumer.java @@ -1,8 +1,9 @@ package no.nav.registre.testnorge.organisasjonfastedataservice.consumer; -import no.nav.registre.testnorge.organisasjonfastedataservice.config.credentials.OrganisasjonBestillingServiceProperties; +import no.nav.registre.testnorge.organisasjonfastedataservice.config.Consumers; import no.nav.registre.testnorge.organisasjonfastedataservice.consumer.command.GetOrdreCommand; import no.nav.testnav.libs.dto.organiasjonbestilling.v1.ItemDTO; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; @@ -12,14 +13,13 @@ @Component public class OrganisasjonBestillingConsumer { private final WebClient webClient; - private final OrganisasjonBestillingServiceProperties serverProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public OrganisasjonBestillingConsumer( - OrganisasjonBestillingServiceProperties serverProperties, + Consumers consumers, TokenExchange tokenExchange) { - - this.serverProperties = serverProperties; + serverProperties = consumers.getOrganisasjonBestillingService(); this.tokenExchange = tokenExchange; this.webClient = WebClient .builder() diff --git a/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/Consumers.java b/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/Consumers.java new file mode 100644 index 00000000000..9e3f6954eba --- /dev/null +++ b/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.organisasjonservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavEregProxy; + +} diff --git a/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/credentials/EregServiceProperties.java b/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/credentials/EregServiceProperties.java deleted file mode 100644 index 0b4fdc250cd..00000000000 --- a/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/config/credentials/EregServiceProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.registre.testnorge.organisasjonservice.config.credentials; - - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-ereg-proxy") -public class EregServiceProperties extends ServerProperties { -} diff --git a/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/consumer/EregConsumer.java b/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/consumer/EregConsumer.java index 1f44ae07150..094eb3ff75c 100644 --- a/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/consumer/EregConsumer.java +++ b/apps/organisasjon-service/src/main/java/no/nav/registre/testnorge/organisasjonservice/consumer/EregConsumer.java @@ -1,10 +1,11 @@ package no.nav.registre.testnorge.organisasjonservice.consumer; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.testnorge.organisasjonservice.config.credentials.EregServiceProperties; +import no.nav.registre.testnorge.organisasjonservice.config.Consumers; import no.nav.registre.testnorge.organisasjonservice.consumer.command.GetOrganisasjonCommand; import no.nav.registre.testnorge.organisasjonservice.consumer.dto.OrganisasjonDTO; import no.nav.registre.testnorge.organisasjonservice.domain.Organisasjon; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; @@ -14,23 +15,23 @@ @Component public class EregConsumer { private final WebClient webClient; - private final EregServiceProperties serviceProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public EregConsumer( - EregServiceProperties serviceProperties, + Consumers consumers, TokenExchange tokenExchange) { - - this.webClient = WebClient.builder() - .baseUrl(serviceProperties.getUrl()) + serverProperties = consumers.getTestnavEregProxy(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) .build(); - this.serviceProperties = serviceProperties; this.tokenExchange = tokenExchange; } public Organisasjon getOrganisasjon(String orgnummer, String miljo) { - var accessToken = tokenExchange.exchange(serviceProperties).block(); + var accessToken = tokenExchange.exchange(serverProperties).block(); OrganisasjonDTO dto = new GetOrganisasjonCommand(webClient, accessToken.getTokenValue(), miljo, orgnummer).call(); return dto != null ? new Organisasjon(dto) : null; } diff --git a/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/OrganisasjonTilgangFrontendApplicationStarter.java b/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/OrganisasjonTilgangFrontendApplicationStarter.java index 0f8f334d9b7..e6e15ed3d06 100644 --- a/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/OrganisasjonTilgangFrontendApplicationStarter.java +++ b/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/OrganisasjonTilgangFrontendApplicationStarter.java @@ -1,7 +1,7 @@ package no.nav.testnav.apps.organisasjontilgangfrontend; import lombok.RequiredArgsConstructor; -import no.nav.testnav.apps.organisasjontilgangfrontend.credentials.TestnavOrganisasjonTilgangServiceProperties; +import no.nav.testnav.apps.organisasjontilgangfrontend.config.Consumers; import no.nav.testnav.libs.reactivecore.config.CoreConfig; import no.nav.testnav.libs.reactivefrontend.config.FrontendConfig; import no.nav.testnav.libs.reactivefrontend.filter.AddAuthenticationHeaderToRequestGatewayFilterFactory; @@ -32,17 +32,14 @@ @RequiredArgsConstructor public class OrganisasjonTilgangFrontendApplicationStarter { - private final TestnavOrganisasjonTilgangServiceProperties testnavOrganisasjonTilgangServiceProperties; + private final Consumers consumers; private final TokenExchange tokenExchange; @Bean public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { return builder .routes() - .route(createRoute( - testnavOrganisasjonTilgangServiceProperties.getUrl(), - addAuthenticationHeaderFilterFrom(testnavOrganisasjonTilgangServiceProperties) - )) + .route(createRoute(consumers.getTestnavOrganisasjonTilgangService())) .build(); } @@ -59,7 +56,9 @@ private GatewayFilter addAuthenticationHeaderFilterFrom(ServerProperties serverP }); } - private Function<PredicateSpec, Buildable<Route>> createRoute(String host, GatewayFilter filter) { + private Function<PredicateSpec, Buildable<Route>> createRoute(ServerProperties serverProperties) { + var host = serverProperties.getUrl(); + var filter = addAuthenticationHeaderFilterFrom(serverProperties); return spec -> spec .path("/organisasjon-tilgang-service/**") .filters(filterSpec -> filterSpec diff --git a/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/config/Consumers.java b/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/config/Consumers.java new file mode 100644 index 00000000000..b9ccbfe89d9 --- /dev/null +++ b/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.organisasjontilgangfrontend.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavOrganisasjonTilgangService; + +} diff --git a/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/credentials/TestnavOrganisasjonTilgangServiceProperties.java b/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/credentials/TestnavOrganisasjonTilgangServiceProperties.java deleted file mode 100644 index 92d5a58f5eb..00000000000 --- a/apps/organisasjon-tilgang-frontend/src/main/java/no/nav/testnav/apps/organisasjontilgangfrontend/credentials/TestnavOrganisasjonTilgangServiceProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.testnav.apps.organisasjontilgangfrontend.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-organisasjon-tilgang-service") -public class TestnavOrganisasjonTilgangServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/Consumers.java b/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/Consumers.java new file mode 100644 index 00000000000..ffba1b4d5d2 --- /dev/null +++ b/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.personsearchservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavPdlProxy; + +} diff --git a/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/credentials/PdlProxyProperties.java b/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/credentials/PdlProxyProperties.java deleted file mode 100644 index a961c6b8a0b..00000000000 --- a/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/config/credentials/PdlProxyProperties.java +++ /dev/null @@ -1,10 +0,0 @@ -package no.nav.registre.testnorge.personsearchservice.config.credentials; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-pdl-proxy") -public class PdlProxyProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/consumer/ElasticSearchConsumer.java b/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/consumer/ElasticSearchConsumer.java index dc0a78b2750..c7fc1851e4a 100644 --- a/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/consumer/ElasticSearchConsumer.java +++ b/apps/person-search-service/src/main/java/no/nav/registre/testnorge/personsearchservice/consumer/ElasticSearchConsumer.java @@ -4,10 +4,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.testnorge.personsearchservice.config.credentials.PdlProxyProperties; +import no.nav.registre.testnorge.personsearchservice.config.Consumers; import no.nav.registre.testnorge.personsearchservice.consumer.command.ElasticSearchCommand; import no.nav.registre.testnorge.personsearchservice.model.Response; import no.nav.registre.testnorge.personsearchservice.model.SearchResponse; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.elasticsearch.action.search.SearchRequest; import org.springframework.stereotype.Component; @@ -24,24 +25,26 @@ public class ElasticSearchConsumer { private final ObjectMapper objectMapper; private final WebClient webClient; private final TokenExchange tokenExchange; - private final PdlProxyProperties pdlProxyProperties; + private final ServerProperties serverProperties; - public ElasticSearchConsumer(TokenExchange tokenExchange, - PdlProxyProperties pdlProxyProperties, - ObjectMapper objectMapper) { - - this.webClient = WebClient.builder() - .baseUrl(pdlProxyProperties.getUrl()) + public ElasticSearchConsumer( + TokenExchange tokenExchange, + Consumers consumers, + ObjectMapper objectMapper + ) { + serverProperties = consumers.getTestnavPdlProxy(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) .exchangeStrategies(getJacksonStrategy(objectMapper)) .build(); this.tokenExchange = tokenExchange; - this.pdlProxyProperties = pdlProxyProperties; this.objectMapper = objectMapper; } @SneakyThrows private Flux<Object> getSearchResponse(SearchRequest searchRequest) { - return tokenExchange.exchange(pdlProxyProperties) + return tokenExchange.exchange(serverProperties) .flatMapMany(token -> new ElasticSearchCommand(webClient, searchRequest.indices()[0], token.getTokenValue(), searchRequest.source().toString()).call()) .map(SearchResponse::getHits) diff --git a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/Consumers.java b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/Consumers.java new file mode 100644 index 00000000000..f5191676903 --- /dev/null +++ b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.personservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties pdlProxy; + +} diff --git a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/credentials/PdlProxyProperties.java b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/credentials/PdlProxyProperties.java deleted file mode 100644 index 8b4d89335a8..00000000000 --- a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/config/credentials/PdlProxyProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.testnav.apps.personservice.config.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.pdl-proxy") -public class PdlProxyProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlApiConsumer.java b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlApiConsumer.java index 16ad7610911..65143c79100 100644 --- a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlApiConsumer.java +++ b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlApiConsumer.java @@ -2,12 +2,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.apps.personservice.config.credentials.PdlProxyProperties; +import no.nav.testnav.apps.personservice.config.Consumers; import no.nav.testnav.apps.personservice.consumer.v1.command.GetPdlAktoerCommand; import no.nav.testnav.apps.personservice.consumer.v1.command.GetPdlPersonCommand; import no.nav.testnav.apps.personservice.consumer.v1.pdl.graphql.MetadataDTO; import no.nav.testnav.apps.personservice.consumer.v1.pdl.graphql.PdlAktoer; import no.nav.testnav.apps.personservice.domain.Person; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.http.MediaType; import org.springframework.http.codec.json.Jackson2JsonDecoder; @@ -37,29 +38,31 @@ public class PdlApiConsumer { private static final String PDL_Q1_URL = "/pdl-api-q1"; private final WebClient webClient; - private final PdlProxyProperties serviceProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public PdlApiConsumer( - PdlProxyProperties serviceProperties, + Consumers consumers, TokenExchange tokenExchange, - ObjectMapper objectMapper) { - - this.serviceProperties = serviceProperties; + ObjectMapper objectMapper + ) { + serverProperties = consumers.getPdlProxy(); this.tokenExchange = tokenExchange; ExchangeStrategies jacksonStrategy = ExchangeStrategies.builder() - .codecs(config -> { - config.defaultCodecs() - .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - config.defaultCodecs() - .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }) + .codecs( + config -> { + config + .defaultCodecs() + .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); + config + .defaultCodecs() + .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); + }) .build(); - this.webClient = WebClient .builder() .exchangeStrategies(jacksonStrategy) - .baseUrl(serviceProperties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } @@ -67,7 +70,7 @@ public Mono<Optional<Person>> getPerson(String ident) { log.info("Henter person {} fra PDL", ident); return tokenExchange - .exchange(serviceProperties) + .exchange(serverProperties) .flatMap(token -> new GetPdlPersonCommand(webClient, PDL_URL, ident, token.getTokenValue()).call()) .map(pdlPerson -> { if (pdlPerson.getErrors().stream().anyMatch(value -> value.getMessage().equals("Fant ikke person"))) { @@ -140,7 +143,7 @@ public Mono<Optional<PdlAktoer.AktoerIdent>> getAktoer(String ident) { log.info("Henter ident {} fra PDL", ident); return tokenExchange - .exchange(serviceProperties) + .exchange(serverProperties) .flatMap(token -> Mono.zip(new GetPdlAktoerCommand(webClient, PDL_URL, ident, token.getTokenValue()).call(), new GetPdlAktoerCommand(webClient, PDL_Q1_URL, ident, token.getTokenValue()).call()) .map(tuple -> { @@ -154,7 +157,7 @@ public Mono<Optional<PdlAktoer.AktoerIdent>> getAktoer(String ident) { public Mono<Boolean> isPerson(String ident, Set<String> opplysningId) { return tokenExchange - .exchange(serviceProperties) + .exchange(serverProperties) .flatMap(token -> Mono.zip(new GetPdlAktoerCommand(webClient, PDL_Q1_URL, ident, token.getTokenValue()).call(), new GetPdlAktoerCommand(webClient, PDL_URL, ident, token.getTokenValue()).call()) .map(tuple -> isPresent(ident, tuple, opplysningId))); diff --git a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlTestdataConsumer.java b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlTestdataConsumer.java index 4ac3a7c0ab6..ed8dfdbb406 100644 --- a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlTestdataConsumer.java +++ b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v1/PdlTestdataConsumer.java @@ -2,20 +2,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.apps.personservice.consumer.v1.command.OpprettFoedselCommand; -import no.nav.testnav.apps.personservice.consumer.v1.command.OpprettPersonCommand; -import no.nav.testnav.apps.personservice.consumer.v1.command.PostAdresseCommand; -import no.nav.testnav.apps.personservice.consumer.v1.command.PostNavnCommand; -import no.nav.testnav.apps.personservice.consumer.v1.command.PostTagsCommand; +import no.nav.testnav.apps.personservice.config.Consumers; +import no.nav.testnav.apps.personservice.consumer.v1.command.*; import no.nav.testnav.apps.personservice.consumer.v1.exception.PdlCreatePersonException; -import no.nav.testnav.apps.personservice.config.credentials.PdlProxyProperties; import no.nav.testnav.apps.personservice.domain.Person; import no.nav.testnav.libs.securitycore.domain.AccessToken; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.http.MediaType; import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonEncoder; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; @@ -25,28 +21,31 @@ public class PdlTestdataConsumer { private final WebClient webClient; - private final PdlProxyProperties serviceProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public PdlTestdataConsumer( - PdlProxyProperties serviceProperties, + Consumers consumers, TokenExchange tokenExchange, - ObjectMapper objectMapper) { - - this.serviceProperties = serviceProperties; + ObjectMapper objectMapper + ) { + serverProperties = consumers.getPdlProxy(); this.tokenExchange = tokenExchange; - ExchangeStrategies jacksonStrategy = ExchangeStrategies.builder() + ExchangeStrategies jacksonStrategy = ExchangeStrategies + .builder() .codecs(config -> { - config.defaultCodecs() + config + .defaultCodecs() .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - config.defaultCodecs() + config + .defaultCodecs() .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }).build(); - + }) + .build(); this.webClient = WebClient .builder() .exchangeStrategies(jacksonStrategy) - .baseUrl(serviceProperties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } @@ -81,7 +80,7 @@ public String ordrePerson(Person person, String kilde) { log.info("Oppretter person med ident {} i PDL", person.getIdent()); try { - var accessToken = tokenExchange.exchange(serviceProperties).block(); + var accessToken = tokenExchange.exchange(serverProperties).block(); opprettPerson(person, kilde, accessToken); opprettNavn(person, kilde, accessToken); opprettAdresse(person, kilde, accessToken); diff --git a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v2/PdlPersonConsumer.java b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v2/PdlPersonConsumer.java index 40a69cb2909..844b7fe7b32 100644 --- a/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v2/PdlPersonConsumer.java +++ b/apps/person-service/src/main/java/no/nav/testnav/apps/personservice/consumer/v2/PdlPersonConsumer.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import lombok.val; -import no.nav.testnav.apps.personservice.config.credentials.PdlProxyProperties; +import no.nav.testnav.apps.personservice.config.Consumers; import no.nav.testnav.apps.personservice.consumer.v2.commad.PdlBolkPersonCommand; import no.nav.testnav.apps.personservice.consumer.v2.commad.PdlPersonGetCommand; import no.nav.testnav.apps.personservice.provider.v2.PdlMiljoer; @@ -34,40 +34,43 @@ public class PdlPersonConsumer { private final TokenExchange tokenService; - private final ServerProperties serviceProperties; + private final ServerProperties serverProperties; private final WebClient webClient; public PdlPersonConsumer( TokenExchange tokenService, - PdlProxyProperties serverProperties, + Consumers consumers, ObjectMapper objectMapper, WebClient.Builder webClientBuilder ) { - this.serviceProperties = serverProperties; + serverProperties = consumers.getPdlProxy(); this.tokenService = tokenService; webClient = webClientBuilder .baseUrl(serverProperties.getUrl()) .exchangeStrategies(getJacksonStrategy(objectMapper)) - .clientConnector(new ReactorClientHttpConnector( - HttpClient.create(ConnectionProvider.builder("custom") - .maxConnections(10) - .pendingAcquireMaxCount(5000) - .pendingAcquireTimeout(Duration.ofMinutes(15)) - .build()) - .responseTimeout(Duration.ofSeconds(5)))) + .clientConnector( + new ReactorClientHttpConnector( + HttpClient.create( + ConnectionProvider + .builder("custom") + .maxConnections(10) + .pendingAcquireMaxCount(5000) + .pendingAcquireTimeout(Duration.ofMinutes(15)) + .build()) + .responseTimeout(Duration.ofSeconds(5)))) .build(); } public Mono<JsonNode> getPdlPerson(String ident, PdlMiljoer pdlMiljoe) { - return tokenService.exchange(serviceProperties) + return tokenService.exchange(serverProperties) .flatMap((AccessToken token) -> new PdlPersonGetCommand(webClient, ident, token.getTokenValue(), pdlMiljoe) .call()); } public Mono<JsonNode> getPdlPersoner(List<String> identer) { - return tokenService.exchange(serviceProperties) + return tokenService.exchange(serverProperties) .flatMap(token -> new PdlBolkPersonCommand(webClient, identer, token.getTokenValue()).call()); } diff --git a/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/Consumers.java b/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/Consumers.java new file mode 100644 index 00000000000..121e1e769d9 --- /dev/null +++ b/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.profil.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testnavPersonOrganisasjonTilgangService; + +} diff --git a/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/TestnavPersonOrganisasjonTilgangServiceProperties.java b/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/TestnavPersonOrganisasjonTilgangServiceProperties.java deleted file mode 100644 index f74fef2e1ce..00000000000 --- a/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/config/TestnavPersonOrganisasjonTilgangServiceProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.registre.testnorge.profil.config; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.testnav-person-organisasjon-tilgang-service") -public class TestnavPersonOrganisasjonTilgangServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/consumer/PersonOrganisasjonTilgangConsumer.java b/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/consumer/PersonOrganisasjonTilgangConsumer.java index 311c16186b0..2f466963955 100644 --- a/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/consumer/PersonOrganisasjonTilgangConsumer.java +++ b/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/consumer/PersonOrganisasjonTilgangConsumer.java @@ -2,9 +2,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.testnorge.profil.config.TestnavPersonOrganisasjonTilgangServiceProperties; +import no.nav.registre.testnorge.profil.config.Consumers; import no.nav.registre.testnorge.profil.consumer.command.GetPersonOrganisasjonTilgangCommand; import no.nav.registre.testnorge.profil.consumer.dto.OrganisasjonDTO; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.http.MediaType; import org.springframework.http.codec.json.Jackson2JsonDecoder; @@ -20,34 +21,37 @@ @Component public class PersonOrganisasjonTilgangConsumer { private final WebClient webClient; - private final TestnavPersonOrganisasjonTilgangServiceProperties serviceProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public PersonOrganisasjonTilgangConsumer( - TestnavPersonOrganisasjonTilgangServiceProperties serviceProperties, + Consumers consumers, TokenExchange tokenExchange, - ObjectMapper objectMapper) { - - this.serviceProperties = serviceProperties; + ObjectMapper objectMapper + ) { + serverProperties = consumers.getTestnavPersonOrganisasjonTilgangService(); this.tokenExchange = tokenExchange; - ExchangeStrategies jacksonStrategy = ExchangeStrategies.builder() - .codecs(config -> { - config.defaultCodecs() - .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - config.defaultCodecs() - .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }) + ExchangeStrategies jacksonStrategy = ExchangeStrategies + .builder() + .codecs( + config -> { + config + .defaultCodecs() + .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); + config + .defaultCodecs() + .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); + }) .build(); - this.webClient = WebClient .builder() .exchangeStrategies(jacksonStrategy) - .baseUrl(serviceProperties.getUrl()) + .baseUrl(serverProperties.getUrl()) .build(); } public Mono<OrganisasjonDTO> getOrganisasjon(String organisasjonsnummer) { - return tokenExchange.exchange(serviceProperties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new GetPersonOrganisasjonTilgangCommand(webClient, accessToken.getTokenValue(), organisasjonsnummer).call()) .onErrorResume( WebClientResponseException.class::isInstance, diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/Consumers.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/Consumers.java new file mode 100644 index 00000000000..d98864b2ccc --- /dev/null +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.identpool.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties tpsMessagingService; + +} diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/credentials/TpsMessagingServiceProperties.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/credentials/TpsMessagingServiceProperties.java deleted file mode 100644 index 33e85ef4ec5..00000000000 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/config/credentials/TpsMessagingServiceProperties.java +++ /dev/null @@ -1,10 +0,0 @@ -package no.nav.testnav.identpool.config.credentials; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.tps.messaging.service") -public class TpsMessagingServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/consumers/TpsMessagingConsumer.java b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/consumers/TpsMessagingConsumer.java index 6b7c2323e84..e03bdb2d486 100644 --- a/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/consumers/TpsMessagingConsumer.java +++ b/apps/testnav-ident-pool/src/main/java/no/nav/testnav/identpool/consumers/TpsMessagingConsumer.java @@ -1,7 +1,7 @@ package no.nav.testnav.identpool.consumers; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.identpool.config.credentials.TpsMessagingServiceProperties; +import no.nav.testnav.identpool.config.Consumers; import no.nav.testnav.identpool.consumers.command.TpsMessagingGetCommand; import no.nav.testnav.identpool.consumers.command.TpsValidation; import no.nav.testnav.identpool.dto.TpsStatusDTO; @@ -24,16 +24,17 @@ public class TpsMessagingConsumer { private static final int PAGESIZE = 80; private final WebClient webClient; - private final ServerProperties serviceProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public TpsMessagingConsumer( - TpsMessagingServiceProperties serviceProperties, - TokenExchange tokenExchange) { - - this.serviceProperties = serviceProperties; - this.webClient = WebClient.builder() - .baseUrl(serviceProperties.getUrl()) + Consumers consumers, + TokenExchange tokenExchange + ) { + serverProperties = consumers.getTpsMessagingService(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) .build(); this.tokenExchange = tokenExchange; } @@ -52,7 +53,7 @@ private List<TpsStatusDTO> getIdenterStatus(List<String> identer, Set<String> mi var startTid = System.currentTimeMillis(); - var response = tokenExchange.exchange(serviceProperties) + var response = tokenExchange.exchange(serverProperties) .flatMapMany(token -> Flux.range(0, identer.size() / PAGESIZE + 1) .flatMap(page -> new TpsMessagingGetCommand(webClient, token.getTokenValue(), identer.subList(page * PAGESIZE, Math.min(identer.size(), (page + 1) * PAGESIZE)), diff --git a/apps/testnorge-tp/src/main/java/no/nav/registre/tp/config/Consumers.java b/apps/testnorge-tp/src/main/java/no/nav/registre/tp/config/Consumers.java new file mode 100644 index 00000000000..dbf7fe25e30 --- /dev/null +++ b/apps/testnorge-tp/src/main/java/no/nav/registre/tp/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.tp.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties hodejegeren; + +} diff --git a/apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/HodejegerenConsumer.java b/apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/HodejegerenConsumer.java index 7783ba65760..6a2a334ff3a 100644 --- a/apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/HodejegerenConsumer.java +++ b/apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/HodejegerenConsumer.java @@ -1,8 +1,8 @@ package no.nav.registre.tp.consumer; import lombok.extern.slf4j.Slf4j; +import no.nav.registre.tp.config.Consumers; import no.nav.registre.tp.consumer.command.GetLevendeIdenterCommand; -import no.nav.registre.tp.consumer.credential.HodejegerenProperties; import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.stereotype.Component; @@ -17,23 +17,24 @@ public class HodejegerenConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final ServerProperties serviceProperties; + private final ServerProperties serverProperties; - public HodejegerenConsumer(HodejegerenProperties serviceProperties, - TokenExchange tokenExchange) { - - this.serviceProperties = serviceProperties; + public HodejegerenConsumer( + Consumers consumers, + TokenExchange tokenExchange + ) { + serverProperties = consumers.getHodejegeren(); this.tokenExchange = tokenExchange; - - this.webClient = WebClient.builder() - .baseUrl(serviceProperties.getUrl()) + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) .build(); } public List<String> getLevende( Long avspillergruppeId ) { - return tokenExchange.exchange(serviceProperties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> new GetLevendeIdenterCommand(avspillergruppeId, accessToken.getTokenValue(), webClient).call()) .block(); } diff --git a/apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/credential/HodejegerenProperties.java b/apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/credential/HodejegerenProperties.java deleted file mode 100644 index 69b3b3ad104..00000000000 --- a/apps/testnorge-tp/src/main/java/no/nav/registre/tp/consumer/credential/HodejegerenProperties.java +++ /dev/null @@ -1,10 +0,0 @@ -package no.nav.registre.tp.consumer.credential; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "consumers.hodejegeren") -public class HodejegerenProperties extends ServerProperties { -} diff --git a/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/Consumers.java b/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/Consumers.java new file mode 100644 index 00000000000..82615c4fc9b --- /dev/null +++ b/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.tilbakemeldingapi.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties profilApi; + +} diff --git a/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/credentials/ProfilServiceProperties.java b/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/credentials/ProfilServiceProperties.java deleted file mode 100644 index 614efdfbfa8..00000000000 --- a/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/config/credentials/ProfilServiceProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package no.nav.registre.testnorge.tilbakemeldingapi.config.credentials; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.profil-api") -public class ProfilServiceProperties extends ServerProperties { -} diff --git a/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/consumer/ProfilApiConsumer.java b/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/consumer/ProfilApiConsumer.java index abcb5c14aa2..96c77de3c7b 100644 --- a/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/consumer/ProfilApiConsumer.java +++ b/apps/tilbakemelding-api/src/main/java/no/nav/registre/testnorge/tilbakemeldingapi/consumer/ProfilApiConsumer.java @@ -1,9 +1,10 @@ package no.nav.registre.testnorge.tilbakemeldingapi.consumer; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.testnorge.tilbakemeldingapi.config.credentials.ProfilServiceProperties; +import no.nav.registre.testnorge.tilbakemeldingapi.config.Consumers; import no.nav.registre.testnorge.tilbakemeldingapi.util.WebClientFilter; import no.nav.testnav.libs.dto.profil.v1.ProfilDTO; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Component; @@ -19,22 +20,23 @@ public class ProfilApiConsumer { private final WebClient webClient; private final TokenExchange tokenExchange; - private final ProfilServiceProperties properties; + private final ServerProperties serverProperties; public ProfilApiConsumer( - ProfilServiceProperties properties, - TokenExchange tokenExchange) { - - this.properties = properties; + Consumers consumers, + TokenExchange tokenExchange + ) { + serverProperties = consumers.getProfilApi(); this.tokenExchange = tokenExchange; - this.webClient = WebClient.builder() - .baseUrl(properties.getUrl()) + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) .build(); } public ProfilDTO getBruker() { log.info("Henter bruker fra Azure."); - return tokenExchange.exchange(properties) + return tokenExchange.exchange(serverProperties) .flatMap(accessToken -> webClient.get() .uri("/api/v1/profil") .header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken.getTokenValue()) diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/Consumers.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/Consumers.java new file mode 100644 index 00000000000..cf0fa57e134 --- /dev/null +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.apps.tpsmessagingservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + * <br/><br/> + * Husk at Spring Boot bruker <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding">relaxed binding</a> + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties testmiljoerService; + +} diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/credentials/TestmiljoerServiceProperties.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/credentials/TestmiljoerServiceProperties.java deleted file mode 100644 index d55c16e1e93..00000000000 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/config/credentials/TestmiljoerServiceProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package no.nav.testnav.apps.tpsmessagingservice.config.credentials; - -import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - - -@Configuration -@ConfigurationProperties(prefix = "consumers.testmiljoer.service") -public class TestmiljoerServiceProperties extends ServerProperties { -} \ No newline at end of file diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/consumer/TestmiljoerServiceConsumer.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/consumer/TestmiljoerServiceConsumer.java index 5239416e99a..c4b6fa2bea8 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/consumer/TestmiljoerServiceConsumer.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/consumer/TestmiljoerServiceConsumer.java @@ -1,7 +1,7 @@ package no.nav.testnav.apps.tpsmessagingservice.consumer; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.apps.tpsmessagingservice.config.credentials.TestmiljoerServiceProperties; +import no.nav.testnav.apps.tpsmessagingservice.config.Consumers; import no.nav.testnav.apps.tpsmessagingservice.consumer.command.TestmiljoerServiceCommand; import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; @@ -16,23 +16,24 @@ public class TestmiljoerServiceConsumer { private final WebClient webClient; - private final ServerProperties serviceProperties; + private final ServerProperties serverProperties; private final TokenExchange tokenExchange; public TestmiljoerServiceConsumer( - TestmiljoerServiceProperties serviceProperties, - TokenExchange tokenExchange) { - - this.serviceProperties = serviceProperties; - this.webClient = WebClient.builder() - .baseUrl(serviceProperties.getUrl()) + Consumers consumers, + TokenExchange tokenExchange + ) { + serverProperties = consumers.getTestmiljoerService(); + this.webClient = WebClient + .builder() + .baseUrl(serverProperties.getUrl()) .build(); this.tokenExchange = tokenExchange; } public List<String> getMiljoer() { - return Arrays.asList(tokenExchange.exchange(serviceProperties) + return Arrays.asList(tokenExchange.exchange(serverProperties) .flatMap(token -> new TestmiljoerServiceCommand(webClient, token.getTokenValue()).call()) .block()); }