Commit 9392020c by xmh

<fix> 修复用户名传输时中文乱码

1 parent 57b9e902
......@@ -20,6 +20,8 @@ import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
......@@ -63,10 +65,16 @@ public class AuthorizationFilter implements GlobalFilter {
return unAuthorized(exchange.getResponse(), checkResult.right);
}
// 添加 username 到 header 中, 供之后的服务使用
ServerHttpRequest req = request.mutate().headers(headers -> headers.add("username", checkResult.right)).build();
ServerHttpRequest req = request.mutate().headers(headers -> {
try {
headers.add("username", URLEncoder.encode(checkResult.right, "utf8"));
} catch (UnsupportedEncodingException e) {
log.error("", e);
}
}).build();
exchange.mutate().request(req).build();
log.info("token 校验成功:{}", token);
log.info("token 校验成功:[{}][{}]", checkResult.right, token);
}
return chain.filter(exchange);
}
......
......@@ -13,6 +13,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.Date;
@Service
......@@ -33,7 +34,7 @@ public class LogServiceImpl extends BaseServiceImpl<Log> implements LogService {
String username = null;
if (requestAttributes != null) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
username = request.getHeader("username");
username = URLDecoder.decode(request.getHeader("username"), "utf8");
}
Log log = new Log();
log.setUsername(username);
......
......@@ -15,6 +15,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
......@@ -80,7 +81,7 @@ public class OpsClientService {
String username = null;
if (requestAttributes != null) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
username = request.getHeader("username");
username = URLDecoder.decode(request.getHeader("username"), "utf8");
}
LogVo logVo = new LogVo();
logVo.setUsername(username);
......
......@@ -17,6 +17,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.List;
/**
......@@ -79,7 +80,7 @@ public class OpsClientService {
String username = null;
if (requestAttributes != null) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
username = request.getHeader("username");
username = URLDecoder.decode(request.getHeader("username"), "utf8");
}
LogVo logVo = new LogVo();
logVo.setUsername(username);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!