Skip to content

ServletOAuth2AuthorizedClientExchangeFilterFunction Does Not Work For Chained Reactive Methods #6483

Closed

Description

@rwinch

Summary

The defaults for ServletOAuth2AuthorizedClientExchangeFilterFunction are performed on the main thread so that ThreadLocal's like SecurityContextHolder and RequestContextHolder can be accessed. The problem is that when chaining occurs, the thread has also chained. This means these defaults cannot be accessed.

An example would be something like this:

override fun getPermissionForDefaultLogin(repositoryRef: RepositoryRef): Mono<Permission> {
    return defaultGitHubLogin()
            // getPermissionsForLogin is deferred to another thread which means defaults cannot be found on the ThreadLocal objects
            .flatMap { login -> getPermissionForLogin(repositoryRef, login) }
}

private fun getPermissionForLogin(repositoryRef: RepositoryRef, login: String): Mono<Permission> {
    return webClient.get()
            .uri("$baseGitHubUrl/repos/${repositoryRef.fullName}/collaborators/$login/permission")
            .attributes(clientRegistrationId("github"))
            .retrieve()
            .bodyToMono<Map<String,Object>>()
            .map { body -> body.get("permission")?.toString()!! }
            .map { p -> Permission(login, p) }
}

private fun defaultGitHubLogin(): Mono<String> {
    return webClient.get()
            .uri("$baseGitHubUrl/user")
            .retrieve()
            .bodyToMono<Map<String,Object>>()
            .map { body -> body.get("login")?.toString() }
}

We should find a way to ensure that the defaults are propagated to chained methods (likely using Reactor's context)

Activity

  1. added
    in: webAn issue in web modules (web, webmvc)
    in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
    on Jan 25, 2019
  2. added this to the 5.1.4 milestone on Jan 25, 2019
  3. modified the milestones: 5.1.4, 5.2.0.M2 on Feb 13, 2019
  4. added a commit that references this issue on Feb 13, 2019
    091cbe5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)in: webAn issue in web modules (web, webmvc)type: bugA general bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions