Skip to content

Commit

Permalink
PartyType og partyId for party
Browse files Browse the repository at this point in the history
  • Loading branch information
thburnett committed Oct 23, 2023
1 parent d6d143d commit 90337f0
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class Header(

@Serializable
data class Party(
val herID: String,
val partyType: String,
val partyId: String,
val role: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<PartyId>.herID(): String {
return this.firstOrNull() { partyId -> partyId.type == "HER" }?.value ?: throw BadRequestException("Melding mangler HER-ID for en eller flere parter")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ data class Header(

@Serializable
data class Party(
val herID: String,
val partyType: String,
val partyId: String,
val role: String
)

Expand Down
12 changes: 6 additions & 6 deletions felles/src/main/kotlin/no/nav/emottak/util/LoggingUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions payload-processor/src/main/kotlin/no/nav/emottak/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 90337f0

Please sign in to comment.