| | |
| | | import com.iailab.module.shasteel.util.token.IailabClient; |
| | | import feign.RequestInterceptor; |
| | | import feign.RequestTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | |
| | | @Configuration |
| | | public class FeignTokenInterceptor implements RequestInterceptor { |
| | | |
| | | @Autowired |
| | | private IailabClient iailabClient; |
| | | |
| | | @Override |
| | | public void apply(RequestTemplate requestTemplate) { |
| | | // 从当前请求上下文中获取Token |
| | |
| | | |
| | | if (token == null) { |
| | | // 如果没有获取到Token,从system-server中获取token |
| | | token = IailabClient.getToken(); |
| | | token = iailabClient.getToken(); |
| | | if (token!= null) { |
| | | requestTemplate.header(HttpHeaders.AUTHORIZATION, token); |
| | | } |
| | | Long tenantId = IailabClient.getTenantId(); |
| | | Long tenantId = iailabClient.getTenantId(); |
| | | if (tenantId != null) { |
| | | requestTemplate.header("tenant-id", String.valueOf(tenantId)); |
| | | } |