Skip to content

ServletOAuth2AuthorizedClientExchangeFilterFunction Does Not Work For Chained Reactive Methods #6483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rwinch opened this issue Jan 25, 2019 · 0 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) in: web An issue in web modules (web, webmvc) type: bug A general bug
Milestone

Comments

@rwinch
Copy link
Member

rwinch commented Jan 25, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) in: web An issue in web modules (web, webmvc) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants