Skip to content

Commit

Permalink
config: increase connection and read timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
tronghn committed Sep 12, 2024
1 parent 93c9ba0 commit 3b5517d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class SubjectTokenIssuer(private val wellKnownUrl: String, val subjectTokenClaim
val cacheProperties = CacheProperties(
lifeSpan = 180.minutes,
refreshTime = 60.minutes,
jwksURL = URL(wellKnown.jwksUri)
jwksURL = URL(wellKnown.jwksUri),
connectionTimeout = 5_000,
readTimeOut = 5_000,
)

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.nimbusds.jose.jwk.source.JWKSourceBuilder.DEFAULT_HTTP_CONNECT_TIMEOU
import com.nimbusds.jose.jwk.source.JWKSourceBuilder.DEFAULT_HTTP_READ_TIMEOUT
import com.nimbusds.jose.jwk.source.JWKSourceBuilder.DEFAULT_HTTP_SIZE_LIMIT
import com.nimbusds.jose.proc.SecurityContext
import com.nimbusds.jose.util.DefaultResourceRetriever
import java.net.URL
import kotlin.time.Duration

Expand All @@ -17,9 +18,13 @@ data class CacheProperties(
val readTimeOut: Int = DEFAULT_HTTP_READ_TIMEOUT,
val sizeLimit: Int = DEFAULT_HTTP_SIZE_LIMIT
) {
private val foreverJwkSource = JWKSourceBuilder.create<SecurityContext>(jwksURL).cacheForever().build()
private val foreverJwkSource = JWKSourceBuilder
.create<SecurityContext>(jwksURL, DefaultResourceRetriever(connectionTimeout, readTimeOut, sizeLimit))
.cacheForever()
.build()

val jwkSource: JWKSource<SecurityContext> = JWKSourceBuilder.create<SecurityContext>(jwksURL)
val jwkSource: JWKSource<SecurityContext> = JWKSourceBuilder
.create<SecurityContext>(jwksURL, DefaultResourceRetriever(connectionTimeout, readTimeOut, sizeLimit))
.cache(lifeSpan.inWholeMilliseconds, refreshTime.inWholeMilliseconds)
.failover(foreverJwkSource)
.rateLimited(false)
Expand Down

0 comments on commit 3b5517d

Please sign in to comment.