This repository was archived by the owner on Oct 25, 2021. It is now read-only.
This repository was archived by the owner on Oct 25, 2021. It is now read-only.
When used with webflux and spring security the current implementation will cause the SecurityContext to be lost #8
Closed
Description
Spring webflux uses Reactor for its async logic. Its made of a chain of Mono<T>
's. That chain can carry a context that can be used anywhere in your code within the scope of that single request. The SecurityContext
resides within that chain context.
That chain is broken by the underlying implementation of DataFetcher
which uses CompletableFuture
for its own async code. As a result the User is no longer authenticated at any point after the logic is delegated to GraphQL-Java.
One solution to this is to add the SecurityContext
to the ExecutionInput
's context, so that we are at least able to access it (even if its not the normal way)
Some example code written in kotlin
@Component
@Internal
class DefaultGraphQLInvocation(private val graphQL: GraphQL) : GraphQLInvocation {
override fun invoke(invocationData: GraphQLInvocationData, webRequest: ServerWebExchange): Mono<ExecutionResult> {
return ReactiveSecurityContextHolder.getContext().flatMap { securityContext ->
val executionInput = ExecutionInput.newExecutionInput()
.query(invocationData.query)
.operationName(invocationData.operationName)
.variables(invocationData.variables)
.context(securityContext)
.build()
Mono.fromCompletionStage(graphQL.executeAsync(executionInput))
}
}
}
Metadata
Metadata
Assignees
Labels
No labels