-
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.
- Loading branch information
1 parent
b69efe6
commit 6895b14
Showing
40 changed files
with
1,137 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Deploy Redis | ||
on: | ||
push: | ||
paths: ['nais/redis-dev.yaml', 'nais/redis-prod.yaml'] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy-redis-dev: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: nais/deploy/actions/deploy@v1 | ||
env: | ||
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | ||
CLUSTER: dev-gcp | ||
RESOURCE: nais/redis-dev.yaml | ||
|
||
deploy-redis-prod: | ||
if: github.ref == 'refs/heads/main' | ||
needs: deploy-redis-dev | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: nais/deploy/actions/deploy@v1 | ||
env: | ||
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | ||
CLUSTER: prod-gcp | ||
RESOURCE: nais/redis-prod.yaml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options="-Xmx2048M" -Dfile.encoding=UTF-8 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: aiven.io/v1alpha1 | ||
kind: Redis | ||
metadata: | ||
labels: | ||
app: oppfolgingsplan-redis | ||
team: team-esyfo | ||
name: redis-team-esyfo-oppfolgingsplan | ||
namespace: team-esyfo | ||
spec: | ||
plan: startup-4 | ||
project: nav-dev |
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 @@ | ||
apiVersion: aiven.io/v1alpha1 | ||
kind: Redis | ||
metadata: | ||
labels: | ||
app: oppfolgingsplan-redis | ||
team: team-esyfo | ||
name: redis-team-esyfo-oppfolgingsplan | ||
namespace: team-esyfo | ||
spec: | ||
plan: startup-4 | ||
project: nav-prod |
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,8 @@ | ||
package no.nav.syfo | ||
|
||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
inline fun <reified T> T.logger(): Logger { | ||
return LoggerFactory.getLogger(T::class.java) | ||
} |
4 changes: 3 additions & 1 deletion
4
...kend/OppfolgingsplanBackendApplication.kt → ...syfo/OppfolgingsplanBackendApplication.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package no.nav.syfo.auth.azure | ||
|
||
import java.io.Serializable | ||
import java.time.LocalDateTime | ||
|
||
@SuppressWarnings("SerialVersionUIDInSerializableClass") | ||
data class AzureAdToken( | ||
val accessToken: String, | ||
val expires: LocalDateTime | ||
) : Serializable |
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/no/nav/syfo/auth/azure/AzureAdTokenClient.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,62 @@ | ||
package no.nav.syfo.auth.azure | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.http.HttpEntity | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.MediaType | ||
import org.springframework.stereotype.Component | ||
import org.springframework.util.LinkedMultiValueMap | ||
import org.springframework.util.MultiValueMap | ||
import org.springframework.web.client.RestClientResponseException | ||
import org.springframework.web.client.RestTemplate | ||
import java.nio.charset.Charset | ||
|
||
@Component | ||
class AzureAdTokenClient @Autowired constructor( | ||
@Value("\${azure.app.client.id}") private val azureAppClientId: String, | ||
@Value("\${azure.app.client.secret}") private val azureAppClientSecret: String, | ||
@Value("\${azure.openid.config.token.endpoint}") private val azureTokenEndpoint: String | ||
) { | ||
fun getOnBehalfOfToken(scopeClientId: String, token: String): String { | ||
return getToken(requestEntity(scopeClientId, token)) | ||
} | ||
|
||
fun getSystemToken(scopeClientId: String): String { | ||
return getToken(systemTokenRequestEntity(scopeClientId)) | ||
} | ||
|
||
private fun getToken(requestEntity: HttpEntity<MultiValueMap<String, String>>): String { | ||
val response = RestTemplate().postForEntity(azureTokenEndpoint, requestEntity, AzureAdTokenResponse::class.java) | ||
return response.body?.toAzureAdToken()?.accessToken ?: throw RestClientResponseException( | ||
"Failed to get token", | ||
HttpStatus.INTERNAL_SERVER_ERROR.value(), | ||
"", | ||
HttpHeaders(), | ||
ByteArray(0), | ||
Charset.defaultCharset() | ||
) | ||
} | ||
|
||
private fun requestEntity(scopeClientId: String, token: String): HttpEntity<MultiValueMap<String, String>> { | ||
val body = LinkedMultiValueMap<String, String>() | ||
body.add("client_id", azureAppClientId) | ||
body.add("client_secret", azureAppClientSecret) | ||
body.add("client_assertion_type", "urn:ietf:params:oauth:grant-type:jwt-bearer") | ||
body.add("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer") | ||
body.add("assertion", token) | ||
body.add("scope", "api://$scopeClientId/.default") | ||
body.add("requested_token_use", "on_behalf_of") | ||
return HttpEntity(body, HttpHeaders().apply { contentType = MediaType.MULTIPART_FORM_DATA }) | ||
} | ||
|
||
private fun systemTokenRequestEntity(scopeClientId: String): HttpEntity<MultiValueMap<String, String>> { | ||
val body = LinkedMultiValueMap<String, String>() | ||
body.add("client_id", azureAppClientId) | ||
body.add("scope", "api://$scopeClientId/.default") | ||
body.add("grant_type", "client_credentials") | ||
body.add("client_secret", azureAppClientSecret) | ||
return HttpEntity(body, HttpHeaders().apply { contentType = MediaType.MULTIPART_FORM_DATA }) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/no/nav/syfo/auth/azure/AzureAdTokenResponse.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,20 @@ | ||
package no.nav.syfo.auth.azure | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import java.io.Serializable | ||
import java.time.LocalDateTime | ||
|
||
@SuppressWarnings("SerialVersionUIDInSerializableClass", "ConstructorParameterNaming") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class AzureAdTokenResponse( | ||
val access_token: String, | ||
val expires_in: Long | ||
) : Serializable | ||
|
||
fun AzureAdTokenResponse.toAzureAdToken(): AzureAdToken { | ||
val expiresOn = LocalDateTime.now().plusSeconds(this.expires_in) | ||
return AzureAdToken( | ||
accessToken = this.access_token, | ||
expires = expiresOn | ||
) | ||
} |
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,5 @@ | ||
package no.nav.syfo.auth.oidc | ||
|
||
object OIDCIssuer { | ||
const val INTERN_AZUREAD_V2 = "internazureadv2" | ||
} |
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,15 @@ | ||
package no.nav.syfo.auth.oidc | ||
|
||
import no.nav.security.token.support.core.context.TokenValidationContextHolder | ||
|
||
object TokenUtil { | ||
|
||
@JvmStatic | ||
fun getIssuerToken(contextHolder: TokenValidationContextHolder, issuer: String): String { | ||
val context = contextHolder.tokenValidationContext | ||
return context.getJwtToken(issuer)?.tokenAsString | ||
?: throw TokenValidationException("Klarte ikke hente token fra issuer: $issuer") | ||
} | ||
|
||
class TokenValidationException(message: String) : RuntimeException(message) | ||
} |
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,22 @@ | ||
package no.nav.syfo.auth.tokenx | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
import java.io.Serializable | ||
import java.time.LocalDateTime | ||
|
||
@SuppressWarnings("SerialVersionUIDInSerializableClass", "ConstructorParameterNaming") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
data class TokenXResponse( | ||
val access_token: String, | ||
val issued_token_type: String, | ||
val token_type: String, | ||
val expires_in: Long | ||
) : Serializable | ||
|
||
fun TokenXResponse.toTokenXToken(): TokenXToken { | ||
val expiresOn = LocalDateTime.now().plusSeconds(this.expires_in) | ||
return TokenXToken( | ||
accessToken = this.access_token, | ||
expires = expiresOn | ||
) | ||
} |
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,10 @@ | ||
package no.nav.syfo.auth.tokenx | ||
|
||
import java.io.Serializable | ||
import java.time.LocalDateTime | ||
|
||
@SuppressWarnings("SerialVersionUIDInSerializableClass") | ||
data class TokenXToken( | ||
val accessToken: String, | ||
val expires: LocalDateTime | ||
) : Serializable |
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,38 @@ | ||
package no.nav.syfo.auth.tokenx | ||
|
||
import no.nav.security.token.support.core.context.TokenValidationContextHolder | ||
import no.nav.security.token.support.core.jwt.JwtTokenClaims | ||
import no.nav.syfo.domain.Fodselsnummer | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.server.ResponseStatusException | ||
|
||
object TokenXUtil { | ||
@Throws(ResponseStatusException::class) | ||
fun validateTokenXClaims( | ||
contextHolder: TokenValidationContextHolder, | ||
vararg requestedClientId: String, | ||
): JwtTokenClaims { | ||
val context = contextHolder.tokenValidationContext | ||
val claims = context.getClaims(TokenXIssuer.TOKENX) | ||
val clientId = claims.getStringClaim("client_id") | ||
|
||
if (!requestedClientId.toList().contains(clientId)) { | ||
throw ResponseStatusException(HttpStatus.FORBIDDEN, "Uventet client id $clientId") | ||
} | ||
return claims | ||
} | ||
|
||
fun JwtTokenClaims.fnrFromIdportenTokenX(): Fodselsnummer { | ||
return Fodselsnummer(this.getStringClaim("pid")) | ||
} | ||
|
||
fun fnrFromIdportenTokenX(contextHolder: TokenValidationContextHolder): Fodselsnummer { | ||
val context = contextHolder.tokenValidationContext | ||
val claims = context.getClaims(TokenXIssuer.TOKENX) | ||
return Fodselsnummer(claims.getStringClaim("pid")) | ||
} | ||
|
||
object TokenXIssuer { | ||
const val TOKENX = "tokenx" | ||
} | ||
} |
Oops, something went wrong.