-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fjern bruk av apigw til fordel for maskinporten og direkte kall"
- Loading branch information
Showing
29 changed files
with
301 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...giver/min_side/config/RetryInterceptor.kt → ...iver/min_side/clients/RetryInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/kotlin/no/nav/arbeidsgiver/min_side/clients/altinn/AltinnTilgangssøknadClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package no.nav.arbeidsgiver.min_side.clients.altinn | ||
|
||
import no.nav.arbeidsgiver.min_side.clients.altinn.dto.DelegationRequest | ||
import no.nav.arbeidsgiver.min_side.clients.altinn.dto.DelegationRequest.RequestResource | ||
import no.nav.arbeidsgiver.min_side.clients.altinn.dto.Søknadsstatus | ||
import no.nav.arbeidsgiver.min_side.clients.retryInterceptor | ||
import no.nav.arbeidsgiver.min_side.config.logger | ||
import no.nav.arbeidsgiver.min_side.models.AltinnTilgangssøknad | ||
import no.nav.arbeidsgiver.min_side.models.AltinnTilgangssøknadsskjema | ||
import no.nav.arbeidsgiver.min_side.services.altinn.AltinnConfig | ||
import org.springframework.boot.web.client.RestTemplateBuilder | ||
import org.springframework.core.ParameterizedTypeReference | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.RequestEntity | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.client.HttpServerErrorException.BadGateway | ||
import org.springframework.web.util.UriComponentsBuilder | ||
import java.util.function.Consumer | ||
|
||
@Component | ||
class AltinnTilgangssøknadClient( | ||
restTemplateBuilder: RestTemplateBuilder, | ||
altinnConfig: AltinnConfig | ||
) { | ||
private val log = logger() | ||
|
||
private val restTemplate = restTemplateBuilder | ||
.additionalInterceptors( | ||
retryInterceptor( | ||
maxAttempts = 3, | ||
backoffPeriod = 250L, | ||
java.net.SocketException::class.java, | ||
javax.net.ssl.SSLHandshakeException::class.java, | ||
org.springframework.web.client.ResourceAccessException::class.java, | ||
) | ||
) | ||
.build() | ||
|
||
private val delegationRequestApiPath = UriComponentsBuilder | ||
.fromUriString(altinnConfig.APIGwUrl) | ||
.path("/ekstern/altinn/api/serviceowner/delegationRequests") | ||
.build() | ||
.toUriString() | ||
private val altinnHeaders = Consumer { httpHeaders: HttpHeaders -> | ||
httpHeaders.putAll( | ||
mapOf( | ||
"accept" to listOf("application/hal+json"), | ||
"apikey" to listOf(altinnConfig.altinnHeader), | ||
"x-nav-apikey" to listOf(altinnConfig.APIGwHeader) | ||
) | ||
) | ||
} | ||
|
||
fun hentSøknader(fødselsnummer: String): List<AltinnTilgangssøknad> { | ||
val resultat = ArrayList<AltinnTilgangssøknad>() | ||
val filter = String.format("CoveredBy eq '%s'", fødselsnummer) | ||
var continuationtoken: String? = null | ||
var shouldContinue = true | ||
while (shouldContinue) { | ||
val uri = | ||
delegationRequestApiPath + "?ForceEIAuthentication&" + if (continuationtoken == null) "\$filter={filter}" else "\$filter={filter}&continuation={continuation}" | ||
val request = RequestEntity.get(uri, filter, continuationtoken).headers(altinnHeaders).build() | ||
val response: ResponseEntity<Søknadsstatus?> = try { | ||
restTemplate.exchange(request, object : ParameterizedTypeReference<Søknadsstatus?>() {}) | ||
} catch (e: BadGateway) { | ||
log.info("retry pga bad gateway mot altinn {}", e.message) | ||
restTemplate.exchange(request, object : ParameterizedTypeReference<Søknadsstatus?>() {}) | ||
} | ||
val body = response.body | ||
if (body == null) { | ||
log.warn("Altinn delegation requests: body missing") | ||
break | ||
} | ||
if (body.embedded!!.delegationRequests!!.isEmpty()) { | ||
shouldContinue = false | ||
} else { | ||
continuationtoken = body.continuationtoken | ||
} | ||
body.embedded!!.delegationRequests!! | ||
.map { søknadDTO: DelegationRequest -> | ||
val søknad = AltinnTilgangssøknad() | ||
søknad.orgnr = søknadDTO.OfferedBy | ||
søknad.status = søknadDTO.RequestStatus | ||
søknad.createdDateTime = søknadDTO.Created | ||
søknad.lastChangedDateTime = søknadDTO.LastChanged | ||
søknad.serviceCode = søknadDTO.RequestResources!![0].ServiceCode | ||
søknad.serviceEdition = søknadDTO.RequestResources!![0].ServiceEditionCode | ||
søknad.submitUrl = søknadDTO.links!!.sendRequest!!.href | ||
søknad | ||
}.toCollection(resultat) | ||
} | ||
return resultat | ||
} | ||
|
||
fun sendSøknad(fødselsnummer: String?, søknadsskjema: AltinnTilgangssøknadsskjema): AltinnTilgangssøknad { | ||
val requestResource = RequestResource() | ||
requestResource.ServiceCode = søknadsskjema.serviceCode | ||
requestResource.ServiceEditionCode = søknadsskjema.serviceEdition | ||
val delegationRequest = DelegationRequest() | ||
delegationRequest.CoveredBy = fødselsnummer | ||
delegationRequest.OfferedBy = søknadsskjema.orgnr | ||
delegationRequest.RedirectUrl = søknadsskjema.redirectUrl | ||
delegationRequest.RequestResources = listOf(requestResource) | ||
val request = RequestEntity | ||
.post("$delegationRequestApiPath?ForceEIAuthentication") | ||
.headers(altinnHeaders) | ||
.body(delegationRequest) | ||
val response = restTemplate.exchange(request, object : ParameterizedTypeReference<DelegationRequest?>() {}) | ||
val body = response.body | ||
val svar = AltinnTilgangssøknad() | ||
svar.status = body!!.RequestStatus | ||
svar.submitUrl = body.links!!.sendRequest!!.href | ||
return svar | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/no/nav/arbeidsgiver/min_side/clients/altinn/dto/DelegationRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package no.nav.arbeidsgiver.min_side.clients.altinn.dto | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class DelegationRequest( | ||
var RequestStatus: String? = null, | ||
var OfferedBy: String? = null, | ||
var CoveredBy: String? = null, | ||
var RedirectUrl: String? = null, | ||
var Created: String? = null, | ||
var LastChanged: String? = null, | ||
val KeepSessionAlive: Boolean = true, | ||
var RequestResources: List<RequestResource>? = null, | ||
@field:JsonProperty("_links") var links: Links? = null | ||
) { | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class RequestResource( | ||
var ServiceCode: String? = null, | ||
var ServiceEditionCode: Int? = null | ||
) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Links(var sendRequest: Link? = null) | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Link(var href: String? = null) | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/no/nav/arbeidsgiver/min_side/clients/altinn/dto/Søknadsstatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package no.nav.arbeidsgiver.min_side.clients.altinn.dto | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Søknadsstatus( | ||
@field:JsonProperty("_embedded") | ||
var embedded: Embedded? = null, | ||
var continuationtoken: String? = null, | ||
) { | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Embedded( | ||
var delegationRequests: List<DelegationRequest>? = null | ||
) | ||
} |
4 changes: 2 additions & 2 deletions
4
...eidsgiver/min_side/azuread/AzureClient.kt → ...r/min_side/clients/azuread/AzureClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...idsgiver/min_side/azuread/AzureService.kt → .../min_side/clients/azuread/AzureService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
...gssoknad/AltinnTilgangSoknadController.kt → ...ntroller/AltinnTilgangSoknadController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/no/nav/arbeidsgiver/min_side/models/Altinn2Organisasjon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package no.nav.arbeidsgiver.min_side.models | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class Altinn2Organisasjon( | ||
@field:JsonProperty("Name") var name: String? = null, | ||
@field:JsonProperty("Type") var type: String? = null, | ||
@field:JsonProperty("ParentOrganizationNumber") var parentOrganizationNumber: String? = null, | ||
@field:JsonProperty("OrganizationNumber") var organizationNumber: String? = null, | ||
@field:JsonProperty("OrganizationForm") var organizationForm: String? = null, | ||
@field:JsonProperty("Status") var status: String? = null | ||
) |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/no/nav/arbeidsgiver/min_side/models/AltinnTilgangssøknad.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package no.nav.arbeidsgiver.min_side.models | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import com.fasterxml.jackson.annotation.JsonInclude | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
data class AltinnTilgangssøknad( | ||
var orgnr: String? = null, | ||
var serviceCode: String? = null, | ||
var serviceEdition: Int? = null, | ||
var status: String? = null, | ||
var createdDateTime: String? = null, | ||
var lastChangedDateTime: String? = null, | ||
var submitUrl: String? = null | ||
) |
2 changes: 1 addition & 1 deletion
2
...angssoknad/AltinnTilgangssøknadsskjema.kt → ...ide/models/AltinnTilgangssøknadsskjema.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/no/nav/arbeidsgiver/min_side/services/altinn/AltinnConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package no.nav.arbeidsgiver.min_side.services.altinn | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties(prefix = "altinn") | ||
data class AltinnConfig( | ||
var altinnHeader: String = "", | ||
var altinnurl: String = "", | ||
var APIGwHeader: String = "", | ||
var APIGwUrl: String = "", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.