java - 如何将用户凭据从 zuul 发送到 Spring Boot 微服务中的微服务模块
问题描述
我有三个微服务模块 auth-server、zuul-server 和 product-server。我想将 auth-server 授权的用户凭据从 zuul-server 发送到 product-server 并在proudct-server 中获取?
我试图在 zuul 服务器标头中设置令牌并从产品服务器获取它。但是我在产品服务器中获得了 null。
if (username != null) {
@SuppressWarnings("unchecked") List<String> authorities = (List<String>) claims.get("authorities");
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken( username, null, authorities.stream().map( SimpleGrantedAuthority::new ).collect(Collectors.toList()));
SecurityContextHolder.getContext().setAuthentication(auth);
}
我想要这个安全上下文到另一个微服务模块,所以我可以从中获取用户凭据。
解决方案
推荐阅读
- python - 为什么 featuretools 从我的数据框索引创建特征?
- java - onActivityResult 中的视图为空
- python - 将原始二进制转换为频谱图
- reactjs - reactjs如何从属性文件中读取数据
- python - 无限while循环内的Sleep()函数
- nginx - js路由器的Nginx配置
- mysql - 是否可以在 mysql 中插入单词和变量的组合?
- python - 从批处理文件中调用 python 行
- javascript - 我必须在 - npm run build #ReactJs 之后更改静态 /js/css 路径
- java - 是否可以在 Spring/REST 中定义具有相同映射但不同参数的多桩方法?