|
|
@ -20,12 +20,11 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ruoyi.common.core.constant.CacheConstants; |
|
|
|
import com.ruoyi.common.core.constant.CacheConstants; |
|
|
|
import com.ruoyi.common.core.constant.Constants; |
|
|
|
import com.ruoyi.common.core.constant.Constants; |
|
|
|
import com.ruoyi.common.core.domain.R; |
|
|
|
import com.ruoyi.common.core.domain.R; |
|
|
|
|
|
|
|
import com.ruoyi.common.core.utils.ServletUtils; |
|
|
|
import com.ruoyi.common.core.utils.StringUtils; |
|
|
|
import com.ruoyi.common.core.utils.StringUtils; |
|
|
|
import com.ruoyi.common.redis.service.RedisService; |
|
|
|
import com.ruoyi.common.redis.service.RedisService; |
|
|
|
import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties; |
|
|
|
import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 网关鉴权 |
|
|
|
* 网关鉴权 |
|
|
@ -70,7 +69,7 @@ public class AuthFilter implements GlobalFilter, Ordered |
|
|
|
} |
|
|
|
} |
|
|
|
JSONObject obj = JSONObject.parseObject(userStr); |
|
|
|
JSONObject obj = JSONObject.parseObject(userStr); |
|
|
|
String userid = obj.getString("userid"); |
|
|
|
String userid = obj.getString("userid"); |
|
|
|
String username = urlEncode(obj.getString("username")); |
|
|
|
String username = obj.getString("username"); |
|
|
|
if (StringUtils.isBlank(userid) || StringUtils.isBlank(username)) |
|
|
|
if (StringUtils.isBlank(userid) || StringUtils.isBlank(username)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return setUnauthorizedResponse(exchange, "令牌验证失败"); |
|
|
|
return setUnauthorizedResponse(exchange, "令牌验证失败"); |
|
|
@ -80,7 +79,7 @@ public class AuthFilter implements GlobalFilter, Ordered |
|
|
|
redisService.expire(getTokenKey(token), EXPIRE_TIME); |
|
|
|
redisService.expire(getTokenKey(token), EXPIRE_TIME); |
|
|
|
// 设置用户信息到请求
|
|
|
|
// 设置用户信息到请求
|
|
|
|
ServerHttpRequest mutableReq = exchange.getRequest().mutate().header(CacheConstants.DETAILS_USER_ID, userid) |
|
|
|
ServerHttpRequest mutableReq = exchange.getRequest().mutate().header(CacheConstants.DETAILS_USER_ID, userid) |
|
|
|
.header(CacheConstants.DETAILS_USERNAME, username).build(); |
|
|
|
.header(CacheConstants.DETAILS_USERNAME, ServletUtils.urlEncode(username)).build(); |
|
|
|
ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build(); |
|
|
|
ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build(); |
|
|
|
|
|
|
|
|
|
|
|
return chain.filter(mutableExchange); |
|
|
|
return chain.filter(mutableExchange); |
|
|
@ -106,18 +105,6 @@ public class AuthFilter implements GlobalFilter, Ordered |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 编码 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String urlEncode(String value) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
value = URLEncoder.encode(value, "UTF-8"); |
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取请求token |
|
|
|
* 获取请求token |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String getToken(ServerHttpRequest request) |
|
|
|
private String getToken(ServerHttpRequest request) |
|
|
|