如何从 DataFetcher(WebFlux + DGS GraphQL)中获取 SecurityContext

问题描述 投票:0回答:0

我想知道是否有可能从

Authentication
中包含的
onField
函数中获得
SchemaDirectiveWiring

我研究过使用

ReactiveSecurityContextHolder
SecurityContextHolder.getContext().getAuthentication()
ReactiveSecurityContextHolder.getContext().block().getAuthentication()
,但两者都返回 null(这确实有意义,因为它是从异步线程中调用的)。

因此,我研究了使用

[ReactiveDgsContext][1]
,这在调试代码时看起来很有前途,我可以在 reactorContext 中看到有一个 SecurityContext 键/值,但我不知道如何访问它/正确检索它。

目前,我的代码如下所示:

DataFetcher<?> authDataFetcher = DataFetcherFactories
                .wrapDataFetcher(originalFetcher, ((dataFetchingEnvironment, value) -> {
                    ReactiveDgsContext context = ReactiveDgsContext.from(dataFetchingEnvironment);
                    if(context != null){
                        ContextView reactiveContext = context.getReactorContext();
...
                    }

任何帮助将不胜感激!

spring-security netflix-dgs spring-graphql
© www.soinside.com 2019 - 2024. All rights reserved.