java - 为什么缺少授权标头?
问题描述
我有 Eureka 和连接的服务Zuul:8090,AuthService:[any_port]。
我向 Zuul 发送../login请求,他发送给 AuthSercice。然后 AuthSerice 放入 Header JWT Authentication。
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
String token = Jwts.builder()
.setSubject( ((User) authResult.getPrincipal()).getUsername())
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
.signWith(SignatureAlgorithm.HS512, SECRET)
.compact();
response.addHeader("Authorization", "Bearer "+ token); // this is missing
response.addHeader("Authorization2", "Bearer " + token); // ok
}
我确实要求邮递员。请求结果
首先,我尝试在 Monoliths 中使用 JWT。没有任何问题,可以添加授权令牌。
为什么缺少授权标头?
解决方案
这是因为 Zuul 中内置的机制——它会自动过滤掉敏感的标头,例如Authorization
和Cookies
,以保护敏感信息不被转发到下游服务。这就是为什么您无法获得带有名称的标题Authorization
。
如果您希望您的下游服务无论如何都接收它们,只需在您的 Zuul 配置文件中自己定义过滤器,而不是使用默认值。
zuul:
routes:
users:
path: your url pattern
sensitiveHeaders: //put nothing here!! leave it blank, the filter will be off
url: downstream url
这是spring官方对敏感标题的解释:document
推荐阅读
- python - “等到关键字成功”不会执行整个关键字
- css - 在 CSS 中编辑跨度 - Wordpress
- typescript - TypeScript 重载:以枚举参数为条件的返回类型
- regex - Google表格根据行中单元格的内容格式化一行
- ios13 - 飞溅iOS 13的动态图片
- list - 从选项类型中获取价值的最佳和安全做法?
- database - 从列表中的字符串中修剪前 4 个字符
- r - 如何将函数参数粘合到 dplyr 的跨函数中的 .names?
- c# - 将 AppMetrics 集成到仅限 xUnit 的项目中
- javascript - 如何使用客户端验证在 c# 中处理您的 asp.net mvc?