Skip to content

Commit

Permalink
chore: fixing excess param
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas <[email protected]>
  • Loading branch information
jaflaten and andreasDev committed Dec 2, 2024
1 parent c2aa1af commit 847a1ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class NasjonalSykmeldingService(
): ResponseEntity<Any> {
if (validationResult.status == Status.OK || validationResult.status == Status.MANUAL_PROCESSING) {
// val veileder = oppgaveSecurityService.getNavIdent()
val veileder = Veileder(oppgaveSecurityService.getNavEmailAsync())
val veileder = Veileder(oppgaveSecurityService.getNavEmail())
if (ferdigstillRegistrering.oppgaveId != null) {
journalpostService.ferdigstillNasjonalJournalpost(
ferdigstillRegistrering = ferdigstillRegistrering,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import no.nav.sykdig.digitalisering.papirsykmelding.db.model.NasjonalManuellOppg
import no.nav.sykdig.digitalisering.pdl.Navn
import no.nav.sykdig.digitalisering.pdl.PersonService
import no.nav.sykdig.securelog
import org.springframework.http.HttpStatus
import org.springframework.http.HttpStatusCode
import org.springframework.http.ResponseEntity
import org.springframework.security.access.prepost.PreAuthorize
Expand Down Expand Up @@ -50,16 +49,16 @@ class NasjonalOppgaveController(
return nasjonalOppgaveService.avvisOppgave(oppgaveId.toInt(), avvisSykmeldingRequest, authorization, navEnhet)
}

@GetMapping("/oppgave/{oppgaveid}")
@GetMapping("/oppgave/{oppgaveId}")
@PreAuthorize("@oppgaveSecurityService.hasAccessToNasjonalOppgave(#oppgaveId)")
@ResponseBody
fun getPapirsykmeldingManuellOppgave(
@PathVariable oppgaveid: String,
@PathVariable oppgaveId: String,
@RequestHeader("Authorization") authorization: String,
): ResponseEntity<PapirManuellOppgave> {
log.info("Current thread: ${Thread.currentThread().name}")
log.info("papirsykmelding: henter oppgave med id $oppgaveid gjennom syk-dig proxy")
val oppgave = smregistreringClient.getOppgaveRequest(authorization, oppgaveid)
log.info("papirsykmelding: henter oppgave med id $oppgaveId gjennom syk-dig proxy")
val oppgave = smregistreringClient.getOppgaveRequest(authorization, oppgaveId)
val papirManuellOppgave = oppgave.body
if (papirManuellOppgave != null) {
securelog.info("lagrer nasjonalOppgave i db $papirManuellOppgave")
Expand Down Expand Up @@ -103,7 +102,7 @@ class NasjonalOppgaveController(
@PreAuthorize("@oppgaveSecurityService.hasAccessToNasjonalOppgave(#oppgaveId)")
@ResponseBody
suspend fun sendOppgave(
@PathVariable oppgaveId: Int,
@PathVariable oppgaveId: String,
@RequestHeader("Authorization") authorization: String,
@RequestHeader("X-Nav-Enhet") navEnhet: String,
@RequestBody papirSykmelding: SmRegistreringManuell,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,17 @@ class OppgaveSecurityService(
return tilgang
}

suspend fun hasAccessToNasjonalOppgave(oppgaveId: String): Boolean = withContext(
Dispatchers.IO) {
fun hasAccessToNasjonalOppgave(oppgaveId: String): Boolean {
securelog.info("sjekker om bruker har tilgang på oppgave $oppgaveId")
val oppgave = nasjonalOppgaveRepository.findByOppgaveId(oppgaveId.toInt())
val navEmail = getNavEmailAsync()
val navEmail = getNavEmail()
val fnr = oppgave?.fnr
if (oppgave != null && fnr != null) {
val tilgang = hasAccess(fnr, navEmail)
securelog.info("Innlogget bruker: $navEmail har${if (!tilgang) " ikke" else ""} tilgang til oppgave med id $oppgaveId")
tilgang
return tilgang
}
false
return false
}

fun hasAccessToSykmelding(sykmeldingId: String): Boolean {
Expand Down Expand Up @@ -129,13 +128,6 @@ class OppgaveSecurityService(
val authentication = SecurityContextHolder.getContext().authentication as JwtAuthenticationToken
return authentication.token.claims["preferred_username"].toString()
}

suspend fun getNavEmailAsync(): String {
return ReactiveSecurityContextHolder.getContext().map { context ->
val auth = context.authentication as JwtAuthenticationToken
auth.token.claims["preferred_username"].toString()
}.awaitSingle()
}
}


0 comments on commit 847a1ca

Please sign in to comment.