fix: 修复omada接口feign问题
This commit is contained in:
@@ -9,47 +9,44 @@ import org.wfc.common.core.utils.StringUtils;
|
||||
import org.wfc.common.core.utils.ip.IpUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* feign 请求拦截器
|
||||
*
|
||||
*
|
||||
* @author wfc
|
||||
*/
|
||||
@Component
|
||||
public class FeignRequestInterceptor implements RequestInterceptor
|
||||
{
|
||||
public class FeignRequestInterceptor implements RequestInterceptor {
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate)
|
||||
{
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
HttpServletRequest httpServletRequest = ServletUtils.getRequest();
|
||||
if (StringUtils.isNotNull(httpServletRequest))
|
||||
{
|
||||
if (StringUtils.isNotNull(httpServletRequest)) {
|
||||
Map<String, String> headers = ServletUtils.getHeaders(httpServletRequest);
|
||||
// 传递用户信息请求头,防止丢失
|
||||
String userId = headers.get(SecurityConstants.DETAILS_USER_ID);
|
||||
if (StringUtils.isNotEmpty(userId))
|
||||
{
|
||||
if (StringUtils.isNotEmpty(userId)) {
|
||||
requestTemplate.header(SecurityConstants.DETAILS_USER_ID, userId);
|
||||
}
|
||||
String userKey = headers.get(SecurityConstants.USER_KEY);
|
||||
if (StringUtils.isNotEmpty(userKey))
|
||||
{
|
||||
if (StringUtils.isNotEmpty(userKey)) {
|
||||
requestTemplate.header(SecurityConstants.USER_KEY, userKey);
|
||||
}
|
||||
String userName = headers.get(SecurityConstants.DETAILS_USERNAME);
|
||||
if (StringUtils.isNotEmpty(userName))
|
||||
{
|
||||
if (StringUtils.isNotEmpty(userName)) {
|
||||
requestTemplate.header(SecurityConstants.DETAILS_USERNAME, userName);
|
||||
}
|
||||
String authentication = headers.get(SecurityConstants.AUTHORIZATION_HEADER);
|
||||
if (StringUtils.isNotEmpty(authentication))
|
||||
{
|
||||
requestTemplate.header(SecurityConstants.AUTHORIZATION_HEADER, authentication);
|
||||
if (StringUtils.isNotEmpty(authentication)) {
|
||||
Collection<String> headerValues = requestTemplate.headers().get(SecurityConstants.AUTHORIZATION_HEADER);
|
||||
boolean hasToken = headerValues.stream().anyMatch(c -> c.startsWith(SecurityConstants.PRE_ACCESS_TOKEN));
|
||||
if (!hasToken) {
|
||||
requestTemplate.header(SecurityConstants.AUTHORIZATION_HEADER, authentication);
|
||||
}
|
||||
}
|
||||
String language = headers.get(SecurityConstants.CONTENT_LANGUAGE);
|
||||
if (StringUtils.isNotEmpty(language))
|
||||
{
|
||||
if (StringUtils.isNotEmpty(language)) {
|
||||
requestTemplate.header(SecurityConstants.CONTENT_LANGUAGE, language);
|
||||
}
|
||||
String platform = headers.get(SecurityConstants.DETAILS_PLATFORM);
|
||||
|
||||
Reference in New Issue
Block a user