Skip to content

Commit

Permalink
Mer validering på orgnr og fnr
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikMeyer committed Feb 25, 2025
1 parent 7ad66d0 commit e331884
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
4 changes: 1 addition & 3 deletions app/main/api/afp/VedtakRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ data class VedtakRequest(
val personidentifikator: String,
val fraOgMedDato: LocalDate,
val tilOgMedDato: LocalDate
) {
fun toVedtakRequest() = VedtakRequest(personidentifikator, fraOgMedDato, tilOgMedDato)
}
)
7 changes: 6 additions & 1 deletion app/main/api/auth/MaskinportenAuth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const val MASKINPORTEN_TP_ORDNINGEN = "tp-ordningen"
fun ApplicationCall.hentConsumerId(): String {
val principal = requireNotNull(this.principal<JWTPrincipal>())
val consumer = requireNotNull(principal.payload.getClaim("consumer"))
return consumer.asMap()["ID"].toString().split(":").last()
val id = consumer.asMap()["ID"]
requireNotNull(id) { "ID-feltet må være satt i JWT i consumer-claimen." }

val res = (id as String).split(":").last()
require(res.isNotBlank())
return res
}

fun AuthenticationConfig.maskinporten(name: String, scope: List<String>, config: Config) {
Expand Down
11 changes: 7 additions & 4 deletions app/main/api/tp/TpRegisterClient.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package api.tp

import no.nav.aap.komponenter.httpklient.httpclient.ClientConfig
import no.nav.aap.komponenter.httpklient.httpclient.RestClient
import no.nav.aap.komponenter.config.requiredConfigForKey
import no.nav.aap.komponenter.httpklient.httpclient.request.PostRequest
import no.nav.aap.komponenter.httpklient.httpclient.ClientConfig
import no.nav.aap.komponenter.httpklient.httpclient.Header
import no.nav.aap.komponenter.httpklient.httpclient.RestClient
import no.nav.aap.komponenter.httpklient.httpclient.error.IkkeFunnetException
import no.nav.aap.komponenter.httpklient.httpclient.post
import no.nav.aap.komponenter.httpklient.httpclient.request.PostRequest
import no.nav.aap.komponenter.httpklient.httpclient.tokenprovider.azurecc.ClientCredentialsTokenProvider
import org.slf4j.LoggerFactory
import java.net.URI
Expand Down Expand Up @@ -35,13 +35,16 @@ object TpRegisterClient : ITpRegisterClient {
orgnr: String,
requestId: String
): Boolean? {
require(orgnr.isNotBlank())
require(fnr.isNotBlank())

val uri = baseUri.resolve("/api/tjenestepensjon/hasYtelse?orgnr=$orgnr")
val httpRestClient = PostRequest(
body = fnr,
additionalHeaders = listOf(
Header("Content-Type", "text/plain"),
Header("Nav-Consumer-Id", "aap-api"),
Header("Nav-Call-Id", requestId)
Header("X-Request-Id", requestId)
)
)
return try {
Expand Down
2 changes: 1 addition & 1 deletion app/test/AfpOffentligServerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class AfpOffentligServerTest {
issuerId = "default",
claims = mapOf(
"scope" to scope,
"consumer" to mapOf("authority" to "123")
"consumer" to mapOf("authority" to "123", "ID" to "0192:889640782")
),
)
}
10 changes: 0 additions & 10 deletions app/test/api/VedtakTest.kt

This file was deleted.

0 comments on commit e331884

Please sign in to comment.