From 90337f0cf7b07e5e16eef9f84736bd4c24bb10db Mon Sep 17 00:00:00 2001 From: Thomas Burnett Date: Mon, 23 Oct 2023 15:11:11 +0200 Subject: [PATCH] PartyType og partyId for party --- .../no/nav/emottak/cpa/model/ValidateRequest.kt | 3 ++- .../nav/emottak/ebms/processing/PayloadProcessor.kt | 10 ++++------ .../nav/emottak/ebms/validation/DokumentValidator.kt | 5 +++-- .../kotlin/no/nav/emottak/melding/model/Payload.kt | 3 ++- .../main/kotlin/no/nav/emottak/util/LoggingUtil.kt | 12 ++++++------ .../src/main/kotlin/no/nav/emottak/App.kt | 6 ++++-- .../main/kotlin/no/nav/emottak/melding/Processor.kt | 2 +- .../kotlin/no/nav/emottak/util/HttpClientUtil.kt | 4 ++-- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/model/ValidateRequest.kt b/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/model/ValidateRequest.kt index 4f9bce3f..92cb9db4 100644 --- a/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/model/ValidateRequest.kt +++ b/cpa-repo/src/main/kotlin/no/nav/emottak/cpa/model/ValidateRequest.kt @@ -16,6 +16,7 @@ data class Header( @Serializable data class Party( - val herID: String, + val partyType: String, + val partyId: String, val role: String ) \ No newline at end of file diff --git a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/processing/PayloadProcessor.kt b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/processing/PayloadProcessor.kt index ca64e19e..026c450f 100644 --- a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/processing/PayloadProcessor.kt +++ b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/processing/PayloadProcessor.kt @@ -30,18 +30,16 @@ fun MessageHeader.payloadRequestHeader(): Header { cpaId = this.cpaId ?: throw BadRequestException("CPAID mangler fra header"), conversationId = this.conversationId, to = Party( - herID = this.to.partyId.herID(), + partyType = this.to.partyId.firstOrNull()?.type ?: throw BadRequestException("Melding mangler to partyId"), + partyId = this.to.partyId.firstOrNull()?.type ?: throw BadRequestException("Melding mangler to partyId"), role = this.to.role ?: throw BadRequestException("Melding mangler role for en eller flere parter") ), from = Party( - herID = this.from.partyId.herID(), + partyType = this.from.partyId.firstOrNull()?.type ?: throw BadRequestException("Melding mangler from partyId"), + partyId = this.from.partyId.firstOrNull()?.type ?: throw BadRequestException("Melding mangler from partyId"), role = this.from.role ?: throw BadRequestException("Melding mangler role for en eller flere parter") ), service = this.service.value ?: throw BadRequestException("Service mangler fra header"), action = this.action ) } - -fun List.herID(): String { - return this.firstOrNull() { partyId -> partyId.type == "HER" }?.value ?: throw BadRequestException("Melding mangler HER-ID for en eller flere parter") -} diff --git a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/validation/DokumentValidator.kt b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/validation/DokumentValidator.kt index ca046957..81af5e51 100644 --- a/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/validation/DokumentValidator.kt +++ b/ebms-provider/src/main/kotlin/no/nav/emottak/ebms/validation/DokumentValidator.kt @@ -21,8 +21,9 @@ class DokumentValidator { val header = Header(messageHeader.messageData.messageId, messageHeader.conversationId, messageHeader.cpaId, - Party(messageHeader.to.partyId.first().value!!,messageHeader.to.role!!), - Party(messageHeader.from.partyId.first().value!!,messageHeader.from.role!!), + //TODO select specific partyID? + Party(messageHeader.to.partyId.first().type!!, messageHeader.to.partyId.first().value!!,messageHeader.to.role!!), + Party(messageHeader.from.partyId.first().type!!, messageHeader.from.partyId.first().value!!,messageHeader.from.role!!), messageHeader.service.value!!, messageHeader.action) runBlocking { diff --git a/felles/src/main/kotlin/no/nav/emottak/melding/model/Payload.kt b/felles/src/main/kotlin/no/nav/emottak/melding/model/Payload.kt index bb6f48ba..2e931387 100644 --- a/felles/src/main/kotlin/no/nav/emottak/melding/model/Payload.kt +++ b/felles/src/main/kotlin/no/nav/emottak/melding/model/Payload.kt @@ -32,7 +32,8 @@ data class Header( @Serializable data class Party( - val herID: String, + val partyType: String, + val partyId: String, val role: String ) diff --git a/felles/src/main/kotlin/no/nav/emottak/util/LoggingUtil.kt b/felles/src/main/kotlin/no/nav/emottak/util/LoggingUtil.kt index 1aeed4e0..35239c45 100644 --- a/felles/src/main/kotlin/no/nav/emottak/util/LoggingUtil.kt +++ b/felles/src/main/kotlin/no/nav/emottak/util/LoggingUtil.kt @@ -14,8 +14,8 @@ fun Header.marker(): LogstashMarker { map[ACTION] = this.action map[TO_ROLE] = this.to.role map[FROM_ROLE] = this.from.role - map[TO_HER_ID] = this.to.herID - map[FROM_HER_ID] = this.from.herID + map[TO_PARTY] = this.to.partyType + ":" + this.to.partyId + map[FROM_PARTY] = this.from.partyType + ":" + this.from.partyId return Markers.appendEntries(map) } @@ -28,8 +28,8 @@ fun MessageHeader.marker(): LogstashMarker { map[ACTION] = this.action map[TO_ROLE] = this.to.role ?: UKJENT_VERDI map[FROM_ROLE] = this.from.role ?: UKJENT_VERDI - map[TO_HER_ID] = this.to.partyId.firstOrNull{ it.type == PARTY_TYPE_HER }?.value ?: UKJENT_VERDI - map[FROM_HER_ID] = this.from.partyId.firstOrNull{ it.type == PARTY_TYPE_HER }?.value ?: UKJENT_VERDI + map[TO_PARTY] = (this.to.partyId.firstOrNull()?.type + ":" + this.to.partyId.firstOrNull()?.value) + map[FROM_PARTY] = (this.from.partyId.firstOrNull()?.type + ":" + this.from.partyId.firstOrNull()?.value) return Markers.appendEntries(map) } @@ -39,8 +39,8 @@ private const val UKJENT_VERDI = "Ukjent" //Kibana log indekser private const val MARKER_MOTTAK_ID = "mottakId" private const val MARKER_CONVERSATION_ID = "ebConversationId" -private const val FROM_HER_ID = "ebAvsenderId" -private const val TO_HER_ID = "ebMottakerId" +private const val FROM_PARTY = "ebAvsenderId" +private const val TO_PARTY = "ebMottakerId" private const val TO_ROLE = "toRole" private const val FROM_ROLE = "fromRole" private const val SERVICE = "ebxmlService" diff --git a/payload-processor/src/main/kotlin/no/nav/emottak/App.kt b/payload-processor/src/main/kotlin/no/nav/emottak/App.kt index 231e93df..023809fa 100644 --- a/payload-processor/src/main/kotlin/no/nav/emottak/App.kt +++ b/payload-processor/src/main/kotlin/no/nav/emottak/App.kt @@ -53,11 +53,13 @@ private fun Application.serverSetup() { conversationId = UUID.randomUUID().toString(), cpaId = UUID.randomUUID().toString(), to = Party( - herID = "8141253", + partyType = "HER", + partyId = "8141253", role = "mottaker" ), from = Party( - herID = "54321", + partyType = "HER", + partyId = "54321", role = "sender" ), service = "melding", diff --git a/payload-processor/src/main/kotlin/no/nav/emottak/melding/Processor.kt b/payload-processor/src/main/kotlin/no/nav/emottak/melding/Processor.kt index 8b650c09..5af136e2 100644 --- a/payload-processor/src/main/kotlin/no/nav/emottak/melding/Processor.kt +++ b/payload-processor/src/main/kotlin/no/nav/emottak/melding/Processor.kt @@ -106,7 +106,7 @@ fun Melding.verifiserSignatur(): Melding { fun Melding.krypter(): Melding { log.info(this.header.marker(), "Krypterer melding") - val krypteringSertifikat = hentKrypteringssertifikat(header.cpaId, header.to.herID) + val krypteringSertifikat = hentKrypteringssertifikat(header.cpaId, header.to.partyType, header.to.partyId) return this.copy( processedPayload = kryptering.krypter(this.processedPayload, krypteringSertifikat), kryptert = true diff --git a/payload-processor/src/main/kotlin/no/nav/emottak/util/HttpClientUtil.kt b/payload-processor/src/main/kotlin/no/nav/emottak/util/HttpClientUtil.kt index 085b12c5..9ce0c3b1 100644 --- a/payload-processor/src/main/kotlin/no/nav/emottak/util/HttpClientUtil.kt +++ b/payload-processor/src/main/kotlin/no/nav/emottak/util/HttpClientUtil.kt @@ -14,8 +14,8 @@ import kotlinx.coroutines.runBlocking private val httpClientUtil = HttpClientUtil() private val cpaRepoUrl = "http://cpa-repo" -fun hentKrypteringssertifikat(cpaId: String, herId: String): ByteArray = runBlocking { - httpClientUtil.makeHttpRequest("$cpaRepoUrl/cpa/$cpaId/$herId/certificate/encryption").readBytes() +fun hentKrypteringssertifikat(cpaId: String, partyType: String, partyId: String): ByteArray = runBlocking { + httpClientUtil.makeHttpRequest("$cpaRepoUrl/cpa/$cpaId/party/$partyType/$partyId/encryption/certificate").readBytes() } class HttpClientUtil {