@@ -4,30 +4,44 @@ import no.nav.security.token.support.core.api.ProtectedWithClaims
4
4
import no.nav.security.token.support.core.api.RequiredIssuers
5
5
import no.nav.sifinnsynapi.common.AktørId
6
6
import no.nav.sifinnsynapi.config.Issuers
7
+ import no.nav.sifinnsynapi.sikkerhet.AuthorizationService
8
+ import no.nav.sifinnsynapi.sikkerhet.ContextHolder
7
9
import no.nav.sifinnsynapi.soknad.SøknadService
10
+ import org.springframework.http.HttpStatus
8
11
import org.springframework.http.MediaType
12
+ import org.springframework.http.ProblemDetail
9
13
import org.springframework.http.ResponseEntity
14
+ import org.springframework.web.ErrorResponseException
10
15
import org.springframework.web.bind.annotation.PostMapping
11
16
import org.springframework.web.bind.annotation.RequestBody
12
17
import org.springframework.web.bind.annotation.RestController
13
18
14
19
@RestController
15
20
@RequiredIssuers(
16
- ProtectedWithClaims (issuer = Issuers .TOKEN_X , claimMap = [ " acr=Level4 " ] )
21
+ ProtectedWithClaims (issuer = Issuers .AZURE )
17
22
)
18
23
class Akt ørBytteController(
19
- private val søknadService : S øknadService
24
+ private val søknadService : S øknadService,
25
+ private val authorizationService : AuthorizationService
20
26
) {
21
27
22
- @PostMapping(" forvaltning/oppdaterAktoerId" ,
23
- produces = [MediaType .APPLICATION_JSON_VALUE ])
28
+ @PostMapping(
29
+ " /forvaltning/oppdaterAktoerId" ,
30
+ consumes = [MediaType .APPLICATION_JSON_VALUE ],
31
+ produces = [MediaType .APPLICATION_JSON_VALUE ]
32
+ )
33
+ @ProtectedWithClaims(issuer = ContextHolder .AZURE_AD , claimMap = [" NAVident=*" ])
24
34
fun oppdaterAktoerId (@RequestBody aktørBytteRequest : Akt ørBytteRequest): ResponseEntity <Akt ørBytteRespons> {
35
+ if (! authorizationService.harTilgangTilDriftRolle()) {
36
+ val problemDetail = ProblemDetail .forStatus(HttpStatus .FORBIDDEN )
37
+ problemDetail.detail = " Mangler driftsrolle"
38
+ throw ErrorResponseException (HttpStatus .FORBIDDEN , problemDetail, null )
39
+ }
25
40
val antallOppdaterte = søknadService.oppdaterAktørId(
26
41
Akt ørId(aktørBytteRequest.gyldigAktør),
27
42
Akt ørId(aktørBytteRequest.utgåttAktør)
28
43
)
29
44
return ResponseEntity .ok(Akt ørBytteRespons(antallOppdaterte))
30
45
}
31
46
32
-
33
47
}
0 commit comments