From 5f39905edc8f8adfc976fde997cf7bae6ed38185 Mon Sep 17 00:00:00 2001 From: gx_ma <1773945958@qq.com> Date: Fri, 13 Mar 2026 10:43:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(swagger=E6=8E=A5=E5=8F=A3):=20?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=96=B0=E5=A2=9E=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/config/SecurityConfig.java | 2 +- .../framework/web/service/TokenService.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/springboot/fastbee-framework/src/main/java/com/fastbee/framework/config/SecurityConfig.java b/springboot/fastbee-framework/src/main/java/com/fastbee/framework/config/SecurityConfig.java index 74f4a9a0..ed924f6b 100644 --- a/springboot/fastbee-framework/src/main/java/com/fastbee/framework/config/SecurityConfig.java +++ b/springboot/fastbee-framework/src/main/java/com/fastbee/framework/config/SecurityConfig.java @@ -121,7 +121,7 @@ public class SecurityConfig .antMatchers("/goview/sys/login","/goview/project/getData").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() - .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() + .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/druid/**").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated(); }) diff --git a/springboot/fastbee-framework/src/main/java/com/fastbee/framework/web/service/TokenService.java b/springboot/fastbee-framework/src/main/java/com/fastbee/framework/web/service/TokenService.java index 121e71bb..83f58395 100644 --- a/springboot/fastbee-framework/src/main/java/com/fastbee/framework/web/service/TokenService.java +++ b/springboot/fastbee-framework/src/main/java/com/fastbee/framework/web/service/TokenService.java @@ -22,10 +22,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.TimeUnit; @@ -334,6 +333,19 @@ public class TokenService { */ private String getToken(HttpServletRequest request) { String token = request.getHeader(header); + + if (StringUtils.isEmpty(token)) { + String uri = request.getRequestURI(); + if (uri.contains("/v2/api-docs") || uri.contains("/v3/api-docs")) { + token = Optional.ofNullable(request.getCookies()) + .flatMap(cookies -> Arrays.stream(cookies) + .filter(c -> "Admin-Token".equals(c.getName())) + .map(Cookie::getValue) + .findFirst()) + .orElse(null); + } + } + if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) { token = token.replace(Constants.TOKEN_PREFIX, ""); }