Skip to content

Commit 6c39d98

Browse files
authored
Merge pull request #61 from gooddata/working
fix(oauth): handle empty accessToken properly
2 parents 5298fdb + 82ed5ff commit 6c39d98

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Diff for: gooddata-server-oauth2-autoconfigure/src/main/kotlin/OidcAuthenticationProcessor.kt

+11-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import org.springframework.web.server.ResponseStatusException
2929
import org.springframework.web.server.ServerWebExchange
3030
import org.springframework.web.server.WebFilterChain
3131
import reactor.core.publisher.Mono
32+
import java.util.Optional
33+
import kotlin.jvm.optionals.getOrNull
3234

3335
/**
3436
* If `SecurityContext` contains [OAuth2AuthenticationToken] the [OidcAuthenticationProcessor] handles the
@@ -56,14 +58,16 @@ class OidcAuthenticationProcessor(
5658
exchange: ServerWebExchange,
5759
chain: WebFilterChain,
5860
): Mono<Void> {
59-
val authorizedClientMono = oauth2ClientRepository.loadAuthorizedClient<OAuth2AuthorizedClient>(
60-
authenticationToken.authorizedClientRegistrationId,
61-
authenticationToken,
62-
exchange,
63-
)
61+
val authorizedClientMono: Mono<Optional<OAuth2AuthorizedClient>> =
62+
oauth2ClientRepository.loadAuthorizedClient<OAuth2AuthorizedClient?>(
63+
authenticationToken.authorizedClientRegistrationId,
64+
authenticationToken,
65+
exchange,
66+
).map { Optional.of(it) }.defaultIfEmpty(Optional.empty<OAuth2AuthorizedClient>())
67+
6468
val userContextMono = getUserContextForAuthenticationToken(authenticationToken)
6569
return Mono.zip(authorizedClientMono, userContextMono).flatMap { tuple ->
66-
val authorizedClient = tuple.t1
70+
val authorizedClient = tuple.t1.getOrNull()
6771
val userContext = tuple.t2
6872
if (userContext.user == null) {
6973
logger.info { "Session was logged out" }
@@ -81,7 +85,7 @@ class OidcAuthenticationProcessor(
8185
authenticationToken.name,
8286
AuthMethod.OIDC,
8387
authenticationToken.getClaim(userContext.organization.oauthSubjectIdClaim),
84-
authorizedClient.accessToken.tokenValue,
88+
authorizedClient?.accessToken?.tokenValue, // Handle null authorizedClient
8589
) {
8690
chain.filter(exchange)
8791
}

0 commit comments

Comments
 (0)