Skip to content

Commit

Permalink
gir lesetilgang til dagpenger med en egendefinert rolle
Browse files Browse the repository at this point in the history
Co-authored-by: Håkon Arneng Holmstedt <hakon.arneng.holmstedt@nav.no>
Co-authored-by: Erik Maximilian Forsman <erik.maximilian.forsman@nav.no>
  • Loading branch information
3 people committed Nov 13, 2024
1 parent bd32658 commit f9f986f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions deploy/dev-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ spec:
- application: dp-oppslag-ytelser
namespace: teamdagpenger
cluster: dev-gcp
permissions:
roles:
- "dagpenger-les"
outbound:
external:
- host: sykepengeperioder-api.dev-fss-pub.nais.io
Expand Down
3 changes: 3 additions & 0 deletions deploy/prod-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ spec:
- application: dp-oppslag-ytelser
namespace: teamdagpenger
cluster: prod-gcp
permissions:
roles:
- "dagpenger-les"
outbound:
external:
- host: sykepengeperioder-api.prod-fss-pub.nais.io
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/no/nav/helse/spokelse/ApiTilgangsstyring.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package no.nav.helse.spokelse
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.auth.jwt.*
import no.nav.helse.spokelse.ApplicationIdAllowlist.applicationId
import org.slf4j.LoggerFactory

interface ApiTilgangsstyring {
fun utbetaltePerioder(call: ApplicationCall)
fun utbetaltePerioderAap(call: ApplicationCall)
fun utbetaltePerioderDagpenger(call: ApplicationCall)
fun grunnlag(call: ApplicationCall)
}

Expand All @@ -18,6 +20,11 @@ internal object ApplicationIdAllowlist: ApiTilgangsstyring {
override fun utbetaltePerioderAap(call: ApplicationCall) {
call.håndhevTilgangTil("utbetalte-perioder-aap", AllowlistUtbetaltePerioderAap)
}

override fun utbetaltePerioderDagpenger(call: ApplicationCall) {
call.håndhevTilgangTil("utbetalte-perioder-dagpenger", "dagpenger-les")
}

override fun grunnlag(call: ApplicationCall) {
call.håndhevTilgangTil("grunnlag", AllowlistGrunnlag)
}
Expand Down Expand Up @@ -58,4 +65,17 @@ internal object ApplicationIdAllowlist: ApiTilgangsstyring {
}
sikkerlogg.info("Håndterer request til /$endepunkt fra $app ($applicationId)")
}

private val ApplicationCall.roles get() = this
.principal<JWTPrincipal>()?.getListClaim("roles", String::class)
?: emptyList()

private fun ApplicationCall.håndhevTilgangTil(endepunkt: String, påkrevdRolle: String) {
if (!roles.contains(påkrevdRolle)) {
"Applikasjonen $applicationId har ikke tilgang til /$endepunkt".let {
sikkerlogg.error(it)
throw IllegalStateException(it)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ internal fun Route.utbetaltePerioderApi(utbetaltePerioder: UtbetaltePerioder, ti
val response = utbetaltePerioder.hent(request, groupBy = setOf(GroupBy.grad), tagsFilter = IngenTags)
call.respondText(response, Json)
}
post("/utbetalte-perioder-dagpenger") {
tilgangsstyrings.utbetaltePerioderDagpenger(call)
val request = objectMapper.readTree(call.receiveText())
val response = utbetaltePerioder.hent(request, groupBy = setOf(GroupBy.grad), tagsFilter = IngenTags)
call.respondText(response, Json)
}
}
2 changes: 2 additions & 0 deletions src/test/kotlin/no/nav/helse/spokelse/AbstractE2ETest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.awaitility.Awaitility
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.TestInstance
import org.skyscreamer.jsonassert.JSONAssert
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -87,6 +88,7 @@ internal abstract class AbstractE2ETest {
spokelse(env, auth, gamleUtbetalingerDao, TbdUtbetalingApi(tbdUtbetalingDao), object: ApiTilgangsstyring {
override fun utbetaltePerioder(call: ApplicationCall) { check(call.applicationId == "fp_object_id") }
override fun utbetaltePerioderAap(call: ApplicationCall) { check(call.applicationId == "fp_object_id") }
override fun utbetaltePerioderDagpenger(call: ApplicationCall) { check(call.applicationId == "fp_object_id") }
override fun grunnlag(call: ApplicationCall) { check(call.applicationId == "fp_object_id") }
})
},
Expand Down

0 comments on commit f9f986f

Please sign in to comment.