Skip to content

Commit

Permalink
fjern fallback til altinn-rettigheter-proxy
Browse files Browse the repository at this point in the history
første steg i forenkling av kontrakt mellom backend og frontend
  • Loading branch information
kenglxn committed Oct 4, 2024
1 parent e1c8346 commit f3e764d
Show file tree
Hide file tree
Showing 32 changed files with 264 additions and 577 deletions.
2 changes: 0 additions & 2 deletions nais/dev-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ spec:
- application: min-side-arbeidsgiver
outbound:
rules:
- application: altinn-rettigheter-proxy
namespace: arbeidsgiver
- application: arbeidsgiver-altinn-tilganger
external:
- host: tt02.altinn.no
Expand Down
2 changes: 0 additions & 2 deletions nais/prod-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ spec:
- application: min-side-arbeidsgiver
outbound:
rules:
- application: altinn-rettigheter-proxy
namespace: arbeidsgiver
- application: arbeidsgiver-altinn-tilganger
external:
- host: www.altinn.no
Expand Down
11 changes: 4 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -81,12 +84,6 @@
<artifactId>caffeine</artifactId>
</dependency>

<dependency>
<groupId>no.nav.arbeidsgiver</groupId>
<artifactId>altinn-rettigheter-proxy-klient</artifactId>
<version>4.0.0</version>
</dependency>

<!-- JSON-logging -->
<dependency>
<groupId>net.logstash.logback</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class AltinnTilgangssøknadClient(
retryInterceptor(
maxAttempts = 3,
backoffPeriod = 250L,
org.apache.http.NoHttpResponseException::class.java,
java.net.SocketException::class.java,
javax.net.ssl.SSLHandshakeException::class.java,
org.springframework.web.client.ResourceAccessException::class.java,
Expand All @@ -39,7 +38,7 @@ class AltinnTilgangssøknadClient(
.build()

private val delegationRequestApiPath = UriComponentsBuilder
.fromUriString(altinnConfig.proxyFallbackUrl)
.fromUriString(altinnConfig.APIGwUrl)
.path("/ekstern/altinn/api/serviceowner/delegationRequests")
.build()
.toUriString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.arbeidsgiver.min_side.clients.azuread

import com.fasterxml.jackson.annotation.JsonProperty
import no.nav.arbeidsgiver.min_side.clients.retryInterceptor
import org.apache.http.NoHttpResponseException
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
Expand All @@ -24,7 +23,6 @@ class AzureClient(
retryInterceptor(
maxAttempts = 3,
backoffPeriod = 250L,
NoHttpResponseException::class.java,
SocketException::class.java,
SSLHandshakeException::class.java,
ResourceAccessException::class.java,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.springframework.web.client.HttpClientErrorException

@RestController
@RequestMapping("/api/altinn-tilgangssoknad")
class AltinnTilgangController(
class AltinnTilgangSoknadController(
private val altinnTilgangssøknadClient: AltinnTilgangssøknadClient,
private val altinnService: AltinnService,
private val authenticatedUserHolder: AuthenticatedUserHolder
Expand All @@ -27,25 +27,23 @@ class AltinnTilgangController(

@PostMapping
fun sendSøknadOmTilgang(@RequestBody søknadsskjema: AltinnTilgangssøknadsskjema): ResponseEntity<AltinnTilgangssøknad> {
val fødselsnummer = authenticatedUserHolder.fnr
val brukerErIOrg = altinnService.hentOrganisasjoner(fødselsnummer)
.any { it.organizationNumber == søknadsskjema.orgnr }
val brukerErIOrg = altinnService.harOrganisasjon(søknadsskjema.orgnr)

if (!brukerErIOrg) {
log.warn("Bruker forsøker å be om tilgang til org de ikke er med i.")
log.error("Bruker forsøker å be om tilgang til org de ikke er med i.")
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build()
}

if (!våreTjenester.contains(søknadsskjema.serviceCode to søknadsskjema.serviceEdition)) {
log.warn(
if (!tjenester.contains(søknadsskjema.serviceCode to søknadsskjema.serviceEdition)) {
log.error(
"Bruker forsøker å be om tilgang til tjeneste ({}, {})) vi ikke støtter.",
søknadsskjema.serviceCode,
søknadsskjema.serviceEdition
)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build()
}
val body = try {
altinnTilgangssøknadClient.sendSøknad(fødselsnummer, søknadsskjema)
altinnTilgangssøknadClient.sendSøknad(authenticatedUserHolder.fnr, søknadsskjema)
} catch (e: HttpClientErrorException) {
if (e.responseBodyAsString.contains("40318")) {
// Bruker forsøker å sende en søknad som allerede er sendt.
Expand All @@ -58,7 +56,7 @@ class AltinnTilgangController(
}

companion object {
val våreTjenester = setOf(
val tjenester = setOf(
"3403" to 2,
"4936" to 1,
"5078" to 1,
Expand All @@ -76,6 +74,7 @@ class AltinnTilgangController(
"5516" to 4,
"5516" to 5,
"5902" to 1,
"5934" to 1,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package no.nav.arbeidsgiver.min_side.controller

import io.ktor.client.plugins.*
import io.ktor.http.HttpStatusCode.Companion.BadGateway
import io.ktor.http.HttpStatusCode.Companion.GatewayTimeout
import io.ktor.http.HttpStatusCode.Companion.ServiceUnavailable
import no.nav.arbeidsgiver.altinnrettigheter.proxy.klient.error.exceptions.AltinnrettigheterProxyKlientFallbackException
import no.nav.arbeidsgiver.min_side.config.logger
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
Expand All @@ -17,7 +12,6 @@ import org.springframework.web.client.HttpClientErrorException.Unauthorized
import org.springframework.web.client.HttpServerErrorException
import org.springframework.web.context.request.WebRequest
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
import java.net.SocketTimeoutException

@ControllerAdvice
class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() {
Expand All @@ -30,23 +24,6 @@ class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() {
return getResponseEntity(e, "Internal error", HttpStatus.INTERNAL_SERVER_ERROR)
}

@ExceptionHandler(AltinnrettigheterProxyKlientFallbackException::class)
@ResponseBody
fun handleAltinnFallbackFeil(
e: AltinnrettigheterProxyKlientFallbackException,
ignored: WebRequest?
): ResponseEntity<Any> {
if (e.cause is SocketTimeoutException) {
return getResponseEntity(e, "Fallback til Altinn feilet pga timeout", HttpStatus.GATEWAY_TIMEOUT)
}
val httpStatus = hentDriftsforstyrrelse(e)
return if (httpStatus != null) {
getResponseEntity(e, "Fallback til Altinn feilet pga driftsforstyrrelse", httpStatus)
} else {
handleInternalError(e, ignored)
}
}

@ExceptionHandler(Forbidden::class)
@ResponseBody
fun handleForbidden(e: RuntimeException, ignored: WebRequest?) =
Expand All @@ -69,24 +46,6 @@ class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() {
)
fun handleDriftsforstyrrelse(ex: HttpServerErrorException) = ResponseEntity.status(ex.statusCode)


private fun hentDriftsforstyrrelse(e: AltinnrettigheterProxyKlientFallbackException): HttpStatus? {
return when (e.cause) {
is ServerResponseException -> {
val serverResponseException = e.cause as ServerResponseException
val status = serverResponseException.response.status
val erDriftsforstyrrelse = listOf(
BadGateway,
ServiceUnavailable,
GatewayTimeout
).contains(status)
if (erDriftsforstyrrelse) HttpStatus.valueOf(status.value) else null
}

else -> null
}
}

private fun getResponseEntity(
t: Throwable,
melding: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import no.nav.arbeidsgiver.min_side.clients.retryInterceptor
import no.nav.arbeidsgiver.min_side.maskinporten.MaskinportenTokenService
import org.apache.http.NoHttpResponseException
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.core.ParameterizedTypeReference
Expand All @@ -29,7 +28,6 @@ class KontaktinfoClient(
retryInterceptor(
3,
250L,
NoHttpResponseException::class.java,
SocketException::class.java,
SSLHandshakeException::class.java,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class KontoregisterClient(
retryInterceptor(
3,
250L,
org.apache.http.NoHttpResponseException::class.java,
java.net.SocketException::class.java,
javax.net.ssl.SSLHandshakeException::class.java,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.arbeidsgiver.min_side.models

data class AltinnTilgangssøknadsskjema(
var orgnr: String? = null,
var redirectUrl: String? = null,
var serviceCode: String? = null,
var serviceEdition: Int? = null,
val orgnr: String,
val redirectUrl: String,
val serviceCode: String,
val serviceEdition: Int,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ data class AltinnConfig(
var altinnHeader: String = "",
var altinnurl: String = "",
var APIGwHeader: String = "",
var proxyUrl: String = "",
var proxyFallbackUrl: String = "",
var proxyAudience: String = "",
var APIGwUrl: String = "",
)
Loading

0 comments on commit f3e764d

Please sign in to comment.