Skip to content

Commit e79b705

Browse files
committed
added API endpoint to provider for testing secure auth
1 parent 56bc16d commit e79b705

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt

+7
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ fun Application.ebmsProviderModule() {
147147
get("/") {
148148
call.respondText("Hello, world!")
149149
}
150+
151+
get("/test/send-in-token") {
152+
log.info("Tester send-in-token auth")
153+
val result = sendInClient.testSecureApi()
154+
log.info("Received result from send-in-token auth: $result")
155+
call.respondText(result)
156+
}
150157
registerHealthEndpoints(appMicrometerRegistry)
151158
postEbmsAsync(validator, processing)
152159
postEbmsSync(validator, processing, sendInService)

ebms-provider/src/main/kotlin/no/nav/emottak/ebms/HttpClients.kt

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.ktor.client.HttpClient
55
import io.ktor.client.call.body
66
import io.ktor.client.engine.cio.CIO
77
import io.ktor.client.plugins.auth.providers.BearerTokens
8+
import io.ktor.client.request.get
89
import io.ktor.client.request.header
910
import io.ktor.client.request.headers
1011
import io.ktor.client.request.post
@@ -57,6 +58,14 @@ class SendInClient(clientProvider: () -> HttpClient) {
5758
contentType(ContentType.Application.Json)
5859
}.body()
5960
}
61+
62+
// TEMP: Ivan will delete me!
63+
suspend fun testSecureApi(): String {
64+
return httpClient.get("http://ebms-send-in/") {
65+
contentType(ContentType.Application.Json)
66+
67+
}.bodyAsText()
68+
}
6069
}
6170

6271
val LENIENT_JSON_PARSER = Json {

ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/App.kt

+21-21
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,31 @@ fun Application.ebmsSendInModule() {
5757
call.respondText(marshal(response))
5858
}
5959

60+
post("/fagmelding/synkron") {
61+
val request = this.call.receive(SendInRequest::class)
62+
runCatching {
63+
log.info(request.marker(), "Payload ${request.payloadId} videresendes")
64+
frikortsporring(wrapMessageInEIFellesFormat(request))
65+
}.onSuccess {
66+
log.info(request.marker(), "Payload ${request.payloadId} videresendt til fagsystem")
67+
call.respond(
68+
SendInResponse(
69+
request.messageId,
70+
request.conversationId,
71+
it.eiFellesformat.addressing(request.addressing.from),
72+
marshal(it.eiFellesformat.msgHead).toByteArray()
73+
)
74+
)
75+
}.onFailure {
76+
log.error(request.marker(), "Payload ${request.payloadId} videresending feilet", it)
77+
call.respond(HttpStatusCode.BadRequest, it.localizedMessage)
78+
}
79+
}
80+
6081
authenticate(AZURE_AD_AUTH) {
6182
get("/") {
6283
call.respondText("Hello world, but securely")
6384
}
64-
65-
post("/fagmelding/synkron") {
66-
val request = this.call.receive(SendInRequest::class)
67-
runCatching {
68-
log.info(request.marker(), "Payload ${request.payloadId} videresendes")
69-
frikortsporring(wrapMessageInEIFellesFormat(request))
70-
}.onSuccess {
71-
log.info(request.marker(), "Payload ${request.payloadId} videresendt til fagsystem")
72-
call.respond(
73-
SendInResponse(
74-
request.messageId,
75-
request.conversationId,
76-
it.eiFellesformat.addressing(request.addressing.from),
77-
marshal(it.eiFellesformat.msgHead).toByteArray()
78-
)
79-
)
80-
}.onFailure {
81-
log.error(request.marker(), "Payload ${request.payloadId} videresending feilet", it)
82-
call.respond(HttpStatusCode.BadRequest, it.localizedMessage)
83-
}
84-
}
8585
}
8686
}
8787
}

0 commit comments

Comments
 (0)