Skip to content

Commit

Permalink
Endrer sertifikatendepunkt til request objekt
Browse files Browse the repository at this point in the history
  • Loading branch information
thburnett committed Oct 23, 2023
1 parent 3aad5ac commit c831733
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
17 changes: 7 additions & 10 deletions cpa-repo/src/main/kotlin/no/nav/emottak/cpa/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.ktor.server.routing.get
import no.nav.emottak.cpa.config.DatabaseConfig
import no.nav.emottak.cpa.config.mapHikariConfig
import no.nav.emottak.melding.model.Header
import no.nav.emottak.melding.model.SignatureDetailsRequest
import no.nav.emottak.melding.model.ValidationResult

fun main() {
Expand Down Expand Up @@ -47,17 +48,13 @@ fun Application.myApplicationModule() {
call.respond(partyInfo.getCertificateForEncryption())
}

get("/cpa/{$CPA_ID}/party/{$PARTY_TYPE}/{$PARTY_ID}/signing/certificate/{$ROLE}/{$SERVICE}/{$ACTION}") {
val cpaId = call.parameters[CPA_ID] ?: throw BadRequestException("Mangler $CPA_ID")
val partyType = call.parameters[PARTY_TYPE] ?: throw BadRequestException("Mangler $PARTY_TYPE")
val partyId = call.parameters[PARTY_ID] ?: throw BadRequestException("Mangler $PARTY_ID")
val role = call.parameters[ROLE] ?: throw BadRequestException("Mangler $ROLE")
val service = call.parameters[SERVICE] ?: throw BadRequestException("Mangler $SERVICE")
val action = call.parameters[ACTION] ?: throw BadRequestException("Mangler $ACTION")
val cpa = getCpa(cpaId) ?: throw NotFoundException("Ingen CPA med ID $cpaId funnet")
val partyInfo = cpa.getPartyInfoByTypeAndID(partyType, partyId)
post("/signing/certificate") {
val signatureDetailsRequest = call.receive(SignatureDetailsRequest::class)
val cpa = getCpa(signatureDetailsRequest.cpaId) ?: throw NotFoundException("Ingen CPA med ID ${signatureDetailsRequest.cpaId} funnet")
val partyInfo = cpa.getPartyInfoByTypeAndID(signatureDetailsRequest.partyType, signatureDetailsRequest.partyId)

call.respond(partyInfo.getCertificateForSignatureValidation(role, service, action))
call.respond(partyInfo.getCertificateForSignatureValidation(
signatureDetailsRequest.role, signatureDetailsRequest.service, signatureDetailsRequest.action))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import no.nav.emottak.melding.model.Header
import no.nav.emottak.melding.model.PayloadRequest
import no.nav.emottak.melding.model.PayloadResponse
import no.nav.emottak.melding.model.SignatureDetails
import no.nav.emottak.melding.model.SignatureDetailsRequest
import no.nav.emottak.melding.model.ValidationResult
import org.oasis_open.committees.ebxml_msg.schema.msg_header_2_0.MessageHeader

Expand All @@ -32,7 +33,15 @@ fun getPublicSigningDetails(messageHeader: MessageHeader): SignatureDetails = ru
}

suspend fun getPublicSigningDetails(cpaId: String, partyType: String, partyId: String, service: String, action: String, role: String): SignatureDetails {
return httpClientUtil.makeHttpRequest("$cpaRepoEndpoint/cpa/$cpaId/party/$partyType/$partyId/signing/certificate/$role/$service/$action").body<SignatureDetails>()
val request = SignatureDetailsRequest(
cpaId = cpaId,
partyType = partyType,
partyId = partyId,
role = role,
service = service,
action = action
)
return httpClientUtil.postSignatureDetailsRequest("$cpaRepoEndpoint/signing/certificate", request)
}

class HttpClientUtil {
Expand All @@ -56,6 +65,13 @@ class HttpClientUtil {
}.body()
}

suspend fun postSignatureDetailsRequest(urlString: String, request: SignatureDetailsRequest): SignatureDetails {
return client.post(urlString) {
setBody(request)
contentType(Json)
}.body()
}

suspend fun makeHttpRequest(urlString: String): HttpResponse {
val response: HttpResponse = client.request(urlString) {
method = HttpMethod.Get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ data class SignatureDetails(
val signatureAlgorithm: String,
val hashFunction: String
)


data class SignatureDetailsRequest(
val cpaId: String,
val partyType: String,
val partyId: String,
val role: String,
val service: String,
val action: String
)

0 comments on commit c831733

Please sign in to comment.