diff --git a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt index ad09d525..4742a424 100644 --- a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt +++ b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt @@ -147,6 +147,13 @@ fun Application.ebmsProviderModule() { get("/") { call.respondText("Hello, world!") } + + get("/test/send-in-token") { + log.info("Tester send-in-token auth") + val result = sendInClient.testSecureApi() + log.info("Received result from send-in-token auth: $result") + call.respondText(result) + } registerHealthEndpoints(appMicrometerRegistry) postEbmsAsync(validator, processing) postEbmsSync(validator, processing, sendInService) diff --git a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/HttpClients.kt b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/HttpClients.kt index f160a8e0..9d9cba6f 100644 --- a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/HttpClients.kt +++ b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/HttpClients.kt @@ -5,6 +5,7 @@ import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.engine.cio.CIO import io.ktor.client.plugins.auth.providers.BearerTokens +import io.ktor.client.request.get import io.ktor.client.request.header import io.ktor.client.request.headers import io.ktor.client.request.post @@ -57,6 +58,14 @@ class SendInClient(clientProvider: () -> HttpClient) { contentType(ContentType.Application.Json) }.body() } + + // TEMP: Ivan will delete me! + suspend fun testSecureApi(): String { + return httpClient.get("http://ebms-send-in/") { + contentType(ContentType.Application.Json) + + }.bodyAsText() + } } val LENIENT_JSON_PARSER = Json { diff --git a/ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/App.kt b/ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/App.kt index 4cc88d61..e7cf5936 100644 --- a/ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/App.kt +++ b/ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/App.kt @@ -57,31 +57,31 @@ fun Application.ebmsSendInModule() { call.respondText(marshal(response)) } + post("/fagmelding/synkron") { + val request = this.call.receive(SendInRequest::class) + runCatching { + log.info(request.marker(), "Payload ${request.payloadId} videresendes") + frikortsporring(wrapMessageInEIFellesFormat(request)) + }.onSuccess { + log.info(request.marker(), "Payload ${request.payloadId} videresendt til fagsystem") + call.respond( + SendInResponse( + request.messageId, + request.conversationId, + it.eiFellesformat.addressing(request.addressing.from), + marshal(it.eiFellesformat.msgHead).toByteArray() + ) + ) + }.onFailure { + log.error(request.marker(), "Payload ${request.payloadId} videresending feilet", it) + call.respond(HttpStatusCode.BadRequest, it.localizedMessage) + } + } + authenticate(AZURE_AD_AUTH) { get("/") { call.respondText("Hello world, but securely") } - - post("/fagmelding/synkron") { - val request = this.call.receive(SendInRequest::class) - runCatching { - log.info(request.marker(), "Payload ${request.payloadId} videresendes") - frikortsporring(wrapMessageInEIFellesFormat(request)) - }.onSuccess { - log.info(request.marker(), "Payload ${request.payloadId} videresendt til fagsystem") - call.respond( - SendInResponse( - request.messageId, - request.conversationId, - it.eiFellesformat.addressing(request.addressing.from), - marshal(it.eiFellesformat.msgHead).toByteArray() - ) - ) - }.onFailure { - log.error(request.marker(), "Payload ${request.payloadId} videresending feilet", it) - call.respond(HttpStatusCode.BadRequest, it.localizedMessage) - } - } } } }