Browse Source

fix: 修复管理后台授权问题

Walker 1 năm trước cách đây
mục cha
commit
19674eddfd

+ 5 - 4
src/main/java/com/ywt/gateway/filter/AuthGatewayFilterFactory.java

@@ -22,6 +22,7 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
 import org.springframework.stereotype.Component;
 import org.springframework.util.MultiValueMap;
 import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
@@ -100,9 +101,9 @@ public class AuthGatewayFilterFactory extends AbstractGatewayFilterFactory<HostL
                 String protocol = config.getProtocol();
                 if (auth == null || auth.isEmpty()) {
                     // 不需要授权
-
-                    proxyPass(config, null, headers, response);
-                    return chain.filter(exchange);
+                    return chain.filter(exchange).then(Mono.fromRunnable(() -> {
+                        proxyPass(config, null, exchange.getResponse().getHeaders(), exchange.getResponse());
+                    }));
                 } else {
                     AuthInfo authInfo = bizCfg.getAuths().stream().filter(i -> auth.equals(i.getName())).findFirst().orElse(null);
                     if (authInfo == null)
@@ -246,7 +247,7 @@ public class AuthGatewayFilterFactory extends AbstractGatewayFilterFactory<HostL
         };
     }
 
-    private void proxyPass(HostLocationInfo locationInfo, AuthInfo authInfo, HttpHeaders headers, ServerHttpResponse response) throws HttpMsgException {
+    private void proxyPass(HostLocationInfo locationInfo, AuthInfo authInfo, HttpHeaders headers, ServerHttpResponse response) {
         // 原网关的“选择后端服务”、“解析协议”部分代码不需要重编码实现,直接使用 Spring Cloud Gateway 的 uri 实现转发
 //        if (locationInfo.getServers() == null || locationInfo.getServers().isEmpty())
 //            throw new HttpMsgException(HttpStatus.BAD_GATEWAY, HttpStatus.BAD_GATEWAY.value(),