|
1 | 1 | package no.nav.syfo.tilgangskontroll
|
2 | 2 |
|
3 |
| -import no.nav.syfo.auth.getVeilederTokenPayload |
4 |
| -import no.nav.syfo.isPreProd |
| 3 | +import com.fasterxml.jackson.databind.* |
| 4 | +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule |
| 5 | +import com.fasterxml.jackson.module.kotlin.readValue |
| 6 | +import com.fasterxml.jackson.module.kotlin.registerKotlinModule |
| 7 | +import no.nav.syfo.LOG |
5 | 8 | import no.nav.syfo.util.allToUpperCase
|
| 9 | +import java.nio.file.Paths |
6 | 10 |
|
7 |
| -val veilederIdenterMedTilgang = arrayListOf( |
8 |
| - "Z991598", |
9 |
| - "T152136", |
10 |
| - "S139136", |
11 |
| - "H103404", |
12 |
| - "L126710", |
13 |
| - "W126199", |
14 |
| - "F125384", |
15 |
| - "H146483", |
16 |
| - "K105407", |
17 |
| - "M152421", |
18 |
| - "H152380", |
19 |
| - "H148938", |
20 |
| - "H131999", |
21 |
| - "V134908", |
22 |
| - "H139248", |
23 |
| - "H149140", |
24 |
| - "B144544", |
25 |
| - "S113562", |
26 |
| - "V111088", |
27 |
| - "F140344", |
28 |
| - "M106428", |
29 |
| - "N149853", // - Lisa |
30 |
| - "R144807" // - Tor Halle |
31 |
| -).allToUpperCase() |
32 |
| - |
33 |
| -val utviklereMedTilgangIPreProd = arrayListOf( |
34 |
| - "Z990197", // - John Martin |
35 |
| - "Z992300", // - Erik |
36 |
| - "Z992668", // - Kristian |
37 |
| - "Z990243", // - June |
38 |
| - "G153334", // - Solveig-1 |
39 |
| - "Z990573", // - Solveig-2 |
40 |
| - "Z992668" // - Kristian |
41 |
| -).allToUpperCase() |
42 |
| - |
43 |
| -class MidlertidigTilgangsSjekk(private var tilgangListe: List<String> = veilederIdenterMedTilgang) { |
| 11 | +private val objectMapper: ObjectMapper = ObjectMapper().apply { |
| 12 | + registerKotlinModule() |
| 13 | + registerModule(JavaTimeModule()) |
| 14 | +} |
| 15 | + |
| 16 | +data class Tilganger ( |
| 17 | + val identer: List<String> |
| 18 | +) |
| 19 | + |
| 20 | +private fun lesTilgangsfil(path: String): Tilganger { |
| 21 | + LOG.info("Leser tilgangsfil fra $path") |
| 22 | + val s = Paths.get(path).toFile().readText() |
| 23 | + return objectMapper.readValue<Tilganger>(s).also { LOG.info("Leste tilgang fra fil med ${it.identer.size} identer") } |
| 24 | +} |
| 25 | + |
| 26 | +private const val vaultFile = "/var/run/secrets/nais.io/vault/tilganger.json" |
| 27 | + |
| 28 | +class MidlertidigTilgangsSjekk(pathTilTilgangsfil: String = vaultFile) { |
| 29 | + |
| 30 | + var tilgangListe = arrayListOf<String>() |
44 | 31 |
|
45 | 32 | init {
|
46 |
| - if (isPreProd()) { |
47 |
| - tilgangListe = tilgangListe.plus(utviklereMedTilgangIPreProd) |
48 |
| - } |
| 33 | + val tilgangsFil = lesTilgangsfil(pathTilTilgangsfil) |
| 34 | + tilgangListe.addAll(tilgangsFil.identer.allToUpperCase()) |
49 | 35 | }
|
50 | 36 |
|
51 |
| - fun harTilgang(token: String): Boolean = getVeilederTokenPayload(token).let { tilgangListe.contains(it.navIdent.toUpperCase()) } |
| 37 | + fun harTilgang(navIdent: String): Boolean = tilgangListe.contains(navIdent.toUpperCase()) |
52 | 38 | }
|
0 commit comments