|
@@ -4,7 +4,6 @@ import cn.com.goldenwater.service.AuditService;
|
|
|
import cn.com.goldenwater.service.PermissionService;
|
|
import cn.com.goldenwater.service.PermissionService;
|
|
|
import cn.com.goldenwater.service.PtAppService;
|
|
import cn.com.goldenwater.service.PtAppService;
|
|
|
import cn.com.goldenwater.utils.JsonUtils;
|
|
import cn.com.goldenwater.utils.JsonUtils;
|
|
|
-import cn.com.goldenwater.utils.TokenUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
|
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
|
@@ -19,6 +18,7 @@ import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
|
public class ApiAuthFilter implements GlobalFilter, Ordered {
|
|
public class ApiAuthFilter implements GlobalFilter, Ordered {
|
|
@@ -38,24 +38,15 @@ public class ApiAuthFilter implements GlobalFilter, Ordered {
|
|
|
String path = request.getPath().value();
|
|
String path = request.getPath().value();
|
|
|
String method = request.getMethodValue();
|
|
String method = request.getMethodValue();
|
|
|
|
|
|
|
|
- // 从exchange属性中获取已经在AuthFilter中解析的token
|
|
|
|
|
- String token = (String) exchange.getAttribute("AUTH_TOKEN");
|
|
|
|
|
- if (token == null) {
|
|
|
|
|
- // 如果没有获取到token,则从请求头中获取
|
|
|
|
|
- token = TokenUtils.getTokenFromRequest(request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 获取第三方服务ID
|
|
|
|
|
-// String thirdPartyId = jwtTokenProvider.getAppId(token);
|
|
|
|
|
- String thirdPartyId = ptAppService.getAppIdByAppToken(token);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // 获取 第三方服务ID
|
|
|
|
|
+ String token = exchange.getAttribute("AUTH_TOKEN");
|
|
|
|
|
+ String thirdPartyId = Optional.ofNullable(token).map(t -> ptAppService.getAppIdByAppToken(token)).orElse(null);
|
|
|
if (thirdPartyId == null) {
|
|
if (thirdPartyId == null) {
|
|
|
- return forbidden(exchange, "Invalid third-party identity");
|
|
|
|
|
|
|
+// return forbidden(exchange, "Invalid third-party identity");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ exchange.getAttributes().put("THIRD_PARTY_ID", thirdPartyId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 将 thirdPartyId 存储到exchange属性中
|
|
|
|
|
- exchange.getAttributes().put("THIRD_PARTY_ID", thirdPartyId);
|
|
|
|
|
-
|
|
|
|
|
// 检查权限
|
|
// 检查权限
|
|
|
return permissionService.checkPermission(thirdPartyId, path, method)
|
|
return permissionService.checkPermission(thirdPartyId, path, method)
|
|
|
.flatMap(hasPermission -> {
|
|
.flatMap(hasPermission -> {
|