优化请求头的 tenant-id 的解析逻辑,避免前端传错类型
This commit is contained in:
parent
9832947dfa
commit
1e32aaa77e
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.framework.web.core.util;
|
package cn.iocoder.yudao.framework.web.core.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
|
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
|
||||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||||
@ -41,7 +42,7 @@ public class WebFrameworkUtils {
|
|||||||
*/
|
*/
|
||||||
public static Long getTenantId(HttpServletRequest request) {
|
public static Long getTenantId(HttpServletRequest request) {
|
||||||
String tenantId = request.getHeader(HEADER_TENANT_ID);
|
String tenantId = request.getHeader(HEADER_TENANT_ID);
|
||||||
return StrUtil.isNotEmpty(tenantId) ? Long.valueOf(tenantId) : null;
|
return NumberUtil.isNumber(tenantId) ? Long.valueOf(tenantId) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLoginUserId(ServletRequest request, Long userId) {
|
public static void setLoginUserId(ServletRequest request, Long userId) {
|
||||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.gateway.util;
|
|||||||
|
|
||||||
import cn.hutool.core.net.NetUtil;
|
import cn.hutool.core.net.NetUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -44,7 +45,7 @@ public class WebFrameworkUtils {
|
|||||||
|
|
||||||
public static Long getTenantId(ServerWebExchange exchange) {
|
public static Long getTenantId(ServerWebExchange exchange) {
|
||||||
String tenantId = exchange.getRequest().getHeaders().getFirst(HEADER_TENANT_ID);
|
String tenantId = exchange.getRequest().getHeaders().getFirst(HEADER_TENANT_ID);
|
||||||
return tenantId != null ? Long.parseLong(tenantId) : null;
|
return NumberUtil.isNumber(tenantId) ? Long.valueOf(tenantId) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user