From 3dead37e05d87513980ca1c6cc82e372b9302d01 Mon Sep 17 00:00:00 2001 From: ajaxfan <909938737@qq.com> Date: Tue, 20 Apr 2021 10:53:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0feign=20config=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/chinaunicom/mall/ebtp/common/config/FeignConfig.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java index 6a5bf4e..c1b537f 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java @@ -21,11 +21,13 @@ import org.springframework.web.context.request.ServletRequestAttributes; import feign.RequestInterceptor; import feign.RequestTemplate; import lombok.Setter; +import lombok.extern.slf4j.Slf4j; /** * 通过拦截器来为header注入token */ @Configuration +@Slf4j @ConfigurationProperties(prefix = "ebtp.cloud") @ConditionalOnProperty(name = "ebtp.universal.feign.token.interceptor", havingValue = "true", matchIfMissing = true) public class FeignConfig implements RequestInterceptor { @@ -80,11 +82,13 @@ public class FeignConfig implements RequestInterceptor { if (StringUtils.startsWith(header, TOKEN_PREFIX)) { String authToken = RegExUtils.replaceAll(header, TOKEN_PREFIX, "");// 提取 token 信息 + log.info("FeignConfig extract token {} from header", authToken); template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, authToken)); } else {// 检查cookie Optional.ofNullable(attributes.getRequest().getCookies()).ifPresent(cookies -> { Stream.of(cookies).filter(item -> StringUtils.equals(item.getName(), COOKIE_TOKEN_CODE)).findFirst() .ifPresent(token -> { + log.info("FeignConfig extract token {} from cookie", token); template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, token.getValue())); });