修正了common包增加cookie连接的bug
This commit is contained in:
@ -41,6 +41,7 @@ public class ModelConvertor {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Optional<AttachmentEntity> toAttachmentEntity(String json) {
|
public Optional<AttachmentEntity> toAttachmentEntity(String json) {
|
||||||
|
log.debug("toAttachmentEntity: {}", json);
|
||||||
return Optional.ofNullable(json).map(content -> {
|
return Optional.ofNullable(json).map(content -> {
|
||||||
AttachmentEntity entity = null;
|
AttachmentEntity entity = null;
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.fallback.DocumentCenterSer
|
|||||||
*
|
*
|
||||||
* @author Ajaxfan
|
* @author Ajaxfan
|
||||||
*/
|
*/
|
||||||
@FeignClient(name = "DocumentCenterService", url = "${document.center.ip-address}", fallback = DocumentCenterServiceFallback.class)
|
//@FeignClient(name = "DocumentCenterService", url = "${document.center.ip-address}", fallback = DocumentCenterServiceFallback.class)
|
||||||
//@FeignClient(value = "core-service-document-center", fallback = DocumentCenterServiceFallback.class)
|
@FeignClient(name = "${document.center.service.id}", fallback = DocumentCenterServiceFallback.class)
|
||||||
public interface DocumentCenterService {
|
public interface DocumentCenterService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +28,7 @@ public interface DocumentCenterService {
|
|||||||
* @param fileId
|
* @param fileId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/v1.0/files/downloadFileAllStream")
|
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/downloadFileAllStream")
|
||||||
String getObjectDetail(@RequestParam("fileId") String fileId);
|
String getObjectDetail(@RequestParam("fileId") String fileId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +37,7 @@ public interface DocumentCenterService {
|
|||||||
* @param bids
|
* @param bids
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/v1.0/files/queryReturn")
|
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/queryReturn")
|
||||||
String fetchDetails(@RequestBody List<String> bids);
|
String fetchDetails(@RequestBody List<String> bids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +55,7 @@ public interface DocumentCenterService {
|
|||||||
* @param fileId
|
* @param fileId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/v1.0/files/disk")
|
@RequestMapping(method = RequestMethod.POST, value = "v1.0/files/disk")
|
||||||
String deleteByOid(@RequestParam("fileId") String fileId);
|
String deleteByOid(@RequestParam("fileId") String fileId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,6 @@ public interface Constants {
|
|||||||
public static final String AUTHORIZATION_HEADER = "Authorization";
|
public static final String AUTHORIZATION_HEADER = "Authorization";
|
||||||
public static final String TOKEN_PREFIX = "Bearer ";
|
public static final String TOKEN_PREFIX = "Bearer ";
|
||||||
public static final String CURRENT_ROLE_CODE = "currentRoleCode";
|
public static final String CURRENT_ROLE_CODE = "currentRoleCode";
|
||||||
|
public static final String COOKIE_TOKEN_CODE = "mall3_token";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
package com.chinaunicom.mall.ebtp.common.config;
|
package com.chinaunicom.mall.ebtp.common.config;
|
||||||
|
|
||||||
import feign.RequestInterceptor;
|
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.AUTHORIZATION_HEADER;
|
||||||
import feign.RequestTemplate;
|
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.CURRENT_ROLE_CODE;
|
||||||
|
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.TOKEN_PREFIX;
|
||||||
|
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.COOKIE_TOKEN_CODE;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RegExUtils;
|
import org.apache.commons.lang3.RegExUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
import feign.RequestInterceptor;
|
||||||
import java.util.Arrays;
|
import feign.RequestTemplate;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过拦截器来为header注入token
|
* 通过拦截器来为header注入token
|
||||||
@ -35,13 +38,13 @@ public class FeignConfig implements RequestInterceptor {
|
|||||||
String authToken = RegExUtils.replaceAll(header, TOKEN_PREFIX, "");// 提取 token 信息
|
String authToken = RegExUtils.replaceAll(header, TOKEN_PREFIX, "");// 提取 token 信息
|
||||||
|
|
||||||
template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, authToken));
|
template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, authToken));
|
||||||
} else {
|
} else {// 检查cookie
|
||||||
//检查cookie
|
Optional.ofNullable(attributes.getRequest().getCookies()).ifPresent(cookies -> {
|
||||||
Optional<Cookie> optional = Arrays.stream(attributes.getRequest().getCookies())
|
Stream.of(cookies).filter(item -> StringUtils.equals(item.getName(), COOKIE_TOKEN_CODE)).findFirst()
|
||||||
.filter(cookie -> StringUtils.equals(cookie.getName(), "mall3_token"))
|
.ifPresent(token -> {
|
||||||
.findAny();
|
template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, token));
|
||||||
|
});
|
||||||
optional.ifPresent(o -> template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, o)));
|
});
|
||||||
}
|
}
|
||||||
final String currentRoleCode = attributes.getRequest().getHeader(CURRENT_ROLE_CODE);// 提取request头信息
|
final String currentRoleCode = attributes.getRequest().getHeader(CURRENT_ROLE_CODE);// 提取request头信息
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user