【发布时间】:2019-05-10 19:26:09
【问题描述】:
有 2 个微服务,一个是 rest 服务,一个是 websocket 服务。 Websocket 服务有 feign 客户端与其余服务对话。
从浏览器工具(例如邮递员)调用 rest 服务时,调用正常。我们只传递带有值Bearer XXXXX 的标头Authorization
在没有拦截器的情况下从 feign 调用时,我们会得到 401:未授权,这是正确的行为。
当将此拦截器添加到代码库时,因为 XXXXX 是真正的令牌,当然,我们会收到 403
@Component
public class FeignOauth2Interceptor implements RequestInterceptor {
private static final String AUTHORIZATION_HEADER = "Authorization";
@Override
public void apply(RequestTemplate template) {
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication =
securityContext.getAuthentication();
template.header(AUTHORIZATION_HEADER, "Bearer XXXXX");
}
}
拦截器被调用,因为我们在添加后看到了不同的错误代码,我们从 401 变为 403。
我们在这里缺少什么??
提前致谢
【问题讨论】:
标签: spring spring-boot oauth-2.0 access-denied feign