diff --git a/nais-dev.yaml b/nais-dev.yaml index b418da27..09e64bf2 100644 --- a/nais-dev.yaml +++ b/nais-dev.yaml @@ -118,6 +118,10 @@ spec: value: api://dev-gcp.okonomi.sokos-kontoregister-person/.default - name: KONTOREGISTER_PERSON_V1_URL value: https://sokos-kontoregister-person.intern.dev.nav.no + - name: AIA_BACKEND_URL + value: https://www.intern.dev.nav.no/aia-backend + - name: AIA_BACKEND_SCOPE + value: api://dev-gcp.paw.paw-arbeidssoker-besvarelse/.default envFrom: - configmap: pto-config - configmap: loginservice-idporten diff --git a/nais-prod.yaml b/nais-prod.yaml index 143b2d00..6cfd71e7 100644 --- a/nais-prod.yaml +++ b/nais-prod.yaml @@ -115,6 +115,10 @@ spec: value: api://prod-gcp.okonomi.sokos-kontoregister-person/.default - name: KONTOREGISTER_PERSON_V1_URL value: https://sokos-kontoregister-person.intern.nav.no + - name: AIA_BACKEND_URL + value: https://www.nav.no/aia-backend + - name: AIA_BACKEND_SCOPE + value: api://prod-gcp.paw.paw-arbeidssoker-besvarelse/.default envFrom: - configmap: pto-config - configmap: loginservice-idporten diff --git a/src/main/java/no/nav/veilarbperson/client/aiabackend/AiaBackendClient.kt b/src/main/java/no/nav/veilarbperson/client/aiabackend/AiaBackendClient.kt new file mode 100644 index 00000000..07d67fcf --- /dev/null +++ b/src/main/java/no/nav/veilarbperson/client/aiabackend/AiaBackendClient.kt @@ -0,0 +1,8 @@ +package no.nav.veilarbperson.client.aiabackend + +import no.nav.common.health.HealthCheck +import okhttp3.Response + +interface AiaBackendClient : HealthCheck { + fun hentEndringIRegistreringsdata(endringIRegistreringsdataRequestDTO: EndringIRegistreringsdataRequestDTO) : Response +} diff --git a/src/main/java/no/nav/veilarbperson/client/aiabackend/AiaBackendClientImpl.kt b/src/main/java/no/nav/veilarbperson/client/aiabackend/AiaBackendClientImpl.kt new file mode 100644 index 00000000..b40c0eda --- /dev/null +++ b/src/main/java/no/nav/veilarbperson/client/aiabackend/AiaBackendClientImpl.kt @@ -0,0 +1,37 @@ +package no.nav.veilarbperson.client.aiabackend + +import lombok.SneakyThrows +import no.nav.common.health.HealthCheckResult +import no.nav.common.health.HealthCheckUtils +import no.nav.common.rest.client.RestClient +import no.nav.common.rest.client.RestUtils +import no.nav.common.utils.UrlUtils.joinPaths +import org.springframework.http.HttpHeaders.ACCEPT +import org.springframework.http.MediaType.APPLICATION_JSON_VALUE +import no.nav.veilarbperson.utils.toJson +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.Response +import org.springframework.http.HttpHeaders +import java.util.function.Supplier + +class AiaBackendClientImpl(private val aiaBackendUrl: String, private val userTokenSupplier: Supplier) : AiaBackendClient { + private val client: OkHttpClient = RestClient.baseClient() + + @SneakyThrows + override fun hentEndringIRegistreringsdata(endringIRegistreringsdataRequestDTO: EndringIRegistreringsdataRequestDTO) : Response { + val request = Request.Builder() + .url(joinPaths(aiaBackendUrl, "/veileder/besvarelse")) + .header(HttpHeaders.AUTHORIZATION, userTokenSupplier.get()) + .header(ACCEPT, APPLICATION_JSON_VALUE) + .post(endringIRegistreringsdataRequestDTO.toJson().toRequestBody(RestUtils.MEDIA_TYPE_JSON)) + .build() + + return client.newCall(request).execute() + } + + override fun checkHealth(): HealthCheckResult { + return HealthCheckUtils.pingUrl(joinPaths(aiaBackendUrl, "/internal/isReady"), client) + } +} diff --git a/src/main/java/no/nav/veilarbperson/client/aiabackend/EndringIRegistreringsdataRequestDTO.kt b/src/main/java/no/nav/veilarbperson/client/aiabackend/EndringIRegistreringsdataRequestDTO.kt new file mode 100644 index 00000000..591698ba --- /dev/null +++ b/src/main/java/no/nav/veilarbperson/client/aiabackend/EndringIRegistreringsdataRequestDTO.kt @@ -0,0 +1,5 @@ +package no.nav.veilarbperson.client.aiabackend + +data class EndringIRegistreringsdataRequestDTO( + val foedselsnummer: String +) diff --git a/src/main/java/no/nav/veilarbperson/client/regoppslag/RegoppslagClientImpl.kt b/src/main/java/no/nav/veilarbperson/client/regoppslag/RegoppslagClientImpl.kt index e344cd39..459bf52f 100644 --- a/src/main/java/no/nav/veilarbperson/client/regoppslag/RegoppslagClientImpl.kt +++ b/src/main/java/no/nav/veilarbperson/client/regoppslag/RegoppslagClientImpl.kt @@ -7,6 +7,8 @@ import no.nav.common.rest.client.RestUtils import no.nav.common.types.identer.Fnr import no.nav.common.utils.AuthUtils import no.nav.common.utils.UrlUtils +import no.nav.veilarbperson.utils.deserializeJsonOrThrow +import no.nav.veilarbperson.utils.toJson import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody diff --git a/src/main/java/no/nav/veilarbperson/config/ApplicationConfig.java b/src/main/java/no/nav/veilarbperson/config/ApplicationConfig.java index 6120fe9a..fbb41781 100644 --- a/src/main/java/no/nav/veilarbperson/config/ApplicationConfig.java +++ b/src/main/java/no/nav/veilarbperson/config/ApplicationConfig.java @@ -24,7 +24,7 @@ import no.nav.poao_tilgang.client.PoaoTilgangClient; import no.nav.poao_tilgang.client.PoaoTilgangHttpClient; import no.nav.poao_tilgang.client.PolicyInput; -import no.nav.veilarbperson.client.regoppslag.JsonUtils; +import no.nav.veilarbperson.utils.JsonUtils; import no.nav.veilarbperson.client.regoppslag.RegoppslagClient; import no.nav.veilarbperson.client.regoppslag.RegoppslagClientImpl; import org.springframework.boot.context.properties.EnableConfigurationProperties; diff --git a/src/main/java/no/nav/veilarbperson/config/ClientConfig.java b/src/main/java/no/nav/veilarbperson/config/ClientConfig.java index 4de9b239..935d6d8e 100644 --- a/src/main/java/no/nav/veilarbperson/config/ClientConfig.java +++ b/src/main/java/no/nav/veilarbperson/config/ClientConfig.java @@ -16,6 +16,8 @@ import no.nav.common.token_client.client.MachineToMachineTokenClient; import no.nav.common.utils.Credentials; import no.nav.common.utils.NaisUtils; +import no.nav.veilarbperson.client.aiabackend.AiaBackendClient; +import no.nav.veilarbperson.client.aiabackend.AiaBackendClientImpl; import no.nav.veilarbperson.client.difi.DifiAccessTokenProviderImpl; import no.nav.veilarbperson.client.difi.DifiClient; import no.nav.veilarbperson.client.difi.DifiClientImpl; @@ -64,6 +66,13 @@ public VeilarboppfolgingClient veilarboppfolgingClient(EnvironmentProperties pro () -> authService.getAadOboTokenForTjeneste(properties.getVeilarboppfolgingScope())); } + @Bean + public AiaBackendClient aiaBackendClient(EnvironmentProperties environmentProperties, AuthService authService) { + return new AiaBackendClientImpl( + environmentProperties.getAiaBackendUrl(), + () -> authService.getAadOboTokenForTjeneste(environmentProperties.getAiaBackendScope())); + } + @Bean public DigdirClient digdirClient(EnvironmentProperties properties, MachineToMachineTokenClient tokenClient) { return new DigdirClientImpl(properties.getKrrUrl(), diff --git a/src/main/java/no/nav/veilarbperson/config/EnvironmentProperties.java b/src/main/java/no/nav/veilarbperson/config/EnvironmentProperties.java index 8a00ae86..41641062 100644 --- a/src/main/java/no/nav/veilarbperson/config/EnvironmentProperties.java +++ b/src/main/java/no/nav/veilarbperson/config/EnvironmentProperties.java @@ -39,4 +39,6 @@ public class EnvironmentProperties { private String veilarbregistreringUrl; private String kontoregisterScope; private String kontoregisterUrl; + private String aiaBackendUrl; + private String aiaBackendScope; } diff --git a/src/main/java/no/nav/veilarbperson/controller/PersonController.java b/src/main/java/no/nav/veilarbperson/controller/PersonController.java index d08a747e..6ac0afad 100644 --- a/src/main/java/no/nav/veilarbperson/controller/PersonController.java +++ b/src/main/java/no/nav/veilarbperson/controller/PersonController.java @@ -78,6 +78,13 @@ public ResponseEntity registrering(@RequestParam(value = "fnr") Fnr fnr) return registreringService.hentRegistrering(fnr); } + @GetMapping("/registrering/endringer") + public ResponseEntity endringIRegistreringdata(@RequestParam(value = "fnr") Fnr fnr) { + authService.stoppHvisEksternBruker(); + authService.sjekkLesetilgang(fnr); + return registreringService.hentEndringIRegistreringsdata(fnr); + } + // TODO: Det er hårete å måtte skille på ekstern og intern // Lag istedenfor en egen controller for interne operasjoner og en annen for eksterne private Fnr hentIdentForEksternEllerIntern(Fnr queryParamFnr) { diff --git a/src/main/java/no/nav/veilarbperson/service/RegistreringService.java b/src/main/java/no/nav/veilarbperson/service/RegistreringService.java index dce187fc..fcebf9b7 100644 --- a/src/main/java/no/nav/veilarbperson/service/RegistreringService.java +++ b/src/main/java/no/nav/veilarbperson/service/RegistreringService.java @@ -3,6 +3,8 @@ import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import no.nav.common.types.identer.Fnr; +import no.nav.veilarbperson.client.aiabackend.AiaBackendClient; +import no.nav.veilarbperson.client.aiabackend.EndringIRegistreringsdataRequestDTO; import no.nav.veilarbperson.client.veilarbregistrering.VeilarbregistreringClient; import okhttp3.Response; import okhttp3.ResponseBody; @@ -14,6 +16,7 @@ public class RegistreringService { private final VeilarbregistreringClient client; + private final AiaBackendClient aiaBackendClient; @SneakyThrows public ResponseEntity hentRegistrering(Fnr fnr) { @@ -31,4 +34,21 @@ public ResponseEntity hentRegistrering(Fnr fnr) { .body(bodyString); } } + + @SneakyThrows + public ResponseEntity hentEndringIRegistreringsdata(Fnr fnr) { + try (Response response = aiaBackendClient.hentEndringIRegistreringsdata(new EndringIRegistreringsdataRequestDTO(fnr.get())); + ResponseBody responseBody = response.body()) { + + String bodyString = null; + + if (responseBody != null) { + bodyString = responseBody.string(); + } + + return ResponseEntity + .status(response.code()) + .body(bodyString); + } + } } diff --git a/src/main/java/no/nav/veilarbperson/client/regoppslag/JsonUtils.kt b/src/main/java/no/nav/veilarbperson/utils/JsonUtils.kt similarity index 88% rename from src/main/java/no/nav/veilarbperson/client/regoppslag/JsonUtils.kt rename to src/main/java/no/nav/veilarbperson/utils/JsonUtils.kt index 3cddd71f..835f8b90 100644 --- a/src/main/java/no/nav/veilarbperson/client/regoppslag/JsonUtils.kt +++ b/src/main/java/no/nav/veilarbperson/utils/JsonUtils.kt @@ -1,7 +1,6 @@ -package no.nav.veilarbperson.client.regoppslag +package no.nav.veilarbperson.utils import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.node.JsonNodeFactory import com.fasterxml.jackson.module.kotlin.KotlinModule import no.nav.common.rest.client.RestUtils import okhttp3.Response diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4c962539..fb1944e1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -37,6 +37,8 @@ app.env.veilarbregistreringScope=${VEILARBREGISTRERING_SCOPE} app.env.veilarbregistreringUrl=${VEILARBREGISTRERING_URL} app.env.kontoregisterScope=${KONTOREGISTER_PERSON_V1_SCOPE} app.env.kontoregisterUrl=${KONTOREGISTER_PERSON_V1_URL} +app.env.aiaBackendUrl=${AIA_BACKEND_URL} +app.env.aiaBackendScope=${AIA_BACKEND_SCOPE} # From config map "loginservice-idporten" app.env.loginserviceIdportenAudience=${LOGINSERVICE_IDPORTEN_AUDIENCE} diff --git a/src/test/java/no/nav/veilarbperson/config/ClientTestConfig.java b/src/test/java/no/nav/veilarbperson/config/ClientTestConfig.java index 1d9fafa5..f13007a7 100644 --- a/src/test/java/no/nav/veilarbperson/config/ClientTestConfig.java +++ b/src/test/java/no/nav/veilarbperson/config/ClientTestConfig.java @@ -13,6 +13,8 @@ import no.nav.common.types.identer.AktorId; import no.nav.common.types.identer.EksternBrukerId; import no.nav.common.types.identer.Fnr; +import no.nav.veilarbperson.client.aiabackend.AiaBackendClient; +import no.nav.veilarbperson.client.aiabackend.EndringIRegistreringsdataRequestDTO; import no.nav.veilarbperson.client.difi.DifiClient; import no.nav.veilarbperson.client.difi.HarLoggetInnRespons; import no.nav.veilarbperson.client.digdir.DigdirClient; @@ -30,6 +32,7 @@ import no.nav.veilarbperson.client.veilarbregistrering.VeilarbregistreringClient; import no.nav.veilarbperson.client.veilarbregistrering.VeilarbregistreringClientImpl; import okhttp3.Response; +import org.jetbrains.annotations.NotNull; import org.springframework.cloud.contract.wiremock.WireMockConfiguration; import org.springframework.cloud.contract.wiremock.WireMockConfigurationCustomizer; import org.springframework.context.annotation.Bean; @@ -201,6 +204,22 @@ public HealthCheckResult checkHealth() { }; } + @Bean + public AiaBackendClient aiaBackendClient() { + return new AiaBackendClient() { + @NotNull + @Override + public Response hentEndringIRegistreringsdata(@NotNull EndringIRegistreringsdataRequestDTO endringIRegistreringsdataRequestDTO) { + return null; + } + + @Override + public HealthCheckResult checkHealth() { + return HealthCheckResult.healthy(); + } + }; + } + @Bean public PdlClient pdlClient() { return new PdlClient() {