如何在 WebFlux 中访问用于 Spring Data 审计的 http 标头

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

我正在尝试利用http标头来审核我的Spring存储库,如此处所述https://docs.spring.io/spring-data/commons/docs/current/reference/html/#auditing.reactive-审计意识

但我面临的挑战是我不使用 Spring Security,我的 userId 在 http 标头中以纯文本形式出现。

我了解到在 WebFlux 情况下我需要使用 Reactor Context,如果我理解正确的话,已经有一个过滤器可以做到这一点:https://docs.spring.io/spring-framework/docs /current/javadoc-api/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.html,但我很难编写代码来提取它。

有人知道任何文章/博客/片段可以为我指明正确的方向吗?

spring-boot spring-data spring-webflux project-reactor
2个回答
0
投票
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// get the request
HttpServletRequest request = requestAttributes.getRequest();
// get headers
username = request.getHeader("x-username");

我不确定WebFlux是否可以工作


0
投票

所提出的解决方案对于 Spring WebFlux 不起作用

您可以在此处阅读相关内容。

© www.soinside.com 2019 - 2024. All rights reserved.