feat: OpenAPI 接口支持读取 Spring Security 白名单路径并跳过 Authorization 头,优化 Ant 风格路径匹配
This commit is contained in:
@@ -16,6 +16,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -82,10 +83,12 @@ public class OpenApiConfig {
|
|||||||
if (openApi.getPaths() != null) {
|
if (openApi.getPaths() != null) {
|
||||||
openApi.getPaths().forEach((path, pathItem) -> {
|
openApi.getPaths().forEach((path, pathItem) -> {
|
||||||
|
|
||||||
// 忽略认证的请求无需携带Authorization
|
// 忽略认证的请求无需携带 Authorization
|
||||||
String[] ignoreUrls = securityProperties.getIgnoreUrls();
|
String[] ignoreUrls = securityProperties.getIgnoreUrls();
|
||||||
if (ArrayUtil.isNotEmpty(ignoreUrls)) {
|
if (ArrayUtil.isNotEmpty(ignoreUrls)) {
|
||||||
if (Stream.of(ignoreUrls).anyMatch(path::equals)) {
|
// Ant 匹配忽略的路径,不添加Authorization
|
||||||
|
AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||||
|
if (Stream.of(ignoreUrls).anyMatch(ignoreUrl -> antPathMatcher.match(ignoreUrl, path))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
url: jdbc:mysql://www.youlai.tech:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
||||||
username: root
|
username: youlai
|
||||||
password: 123456
|
password: 123456
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
@@ -87,8 +87,7 @@ security:
|
|||||||
refresh-token-time-to-live: 604800
|
refresh-token-time-to-live: 604800
|
||||||
# 无需认证的请求路径
|
# 无需认证的请求路径
|
||||||
ignore-urls:
|
ignore-urls:
|
||||||
- /api/v1/auth/login # 用户登录接口
|
- /api/v1/auth/login/** # 登录接口(账号密码登录、手机验证码登录和微信登录)
|
||||||
- /api/v1/auth/wechat-login # 微信登录接口
|
|
||||||
- /api/v1/auth/captcha # 验证码获取接口
|
- /api/v1/auth/captcha # 验证码获取接口
|
||||||
- /api/v1/auth/refresh-token # 刷新令牌接口
|
- /api/v1/auth/refresh-token # 刷新令牌接口
|
||||||
- /ws/** # WebSocket接口
|
- /ws/** # WebSocket接口
|
||||||
@@ -141,18 +140,18 @@ sms:
|
|||||||
regionId: cn-shanghai
|
regionId: cn-shanghai
|
||||||
signName: 有来技术
|
signName: 有来技术
|
||||||
templates:
|
templates:
|
||||||
# 注册短信验证码模板
|
# 注册短信验证码模板
|
||||||
register: SMS_22xxx771
|
register: SMS_22xxx771
|
||||||
# 登录短信验证码模板
|
# 登录短信验证码模板
|
||||||
login: SMS_22xxx772
|
login: SMS_22xxx772
|
||||||
# 修改密码短信验证码模板
|
# 修改手机号短信验证码模板
|
||||||
reset-password: SMS_22xxx773
|
change-mobile: SMS_22xxx773
|
||||||
|
|
||||||
# springdoc配置: https://springdoc.org/properties.html
|
# springdoc配置: https://springdoc.org/properties.html
|
||||||
springdoc:
|
springdoc:
|
||||||
swagger-ui:
|
swagger-ui:
|
||||||
path: /swagger-ui.html
|
path: /swagger-ui.html
|
||||||
operationsSorter: alpha
|
operations-sorter: alpha
|
||||||
tags-sorter: alpha
|
tags-sorter: alpha
|
||||||
api-docs:
|
api-docs:
|
||||||
path: /v3/api-docs
|
path: /v3/api-docs
|
||||||
@@ -195,32 +194,32 @@ xxl:
|
|||||||
|
|
||||||
# 验证码配置
|
# 验证码配置
|
||||||
captcha:
|
captcha:
|
||||||
# 验证码类型 circle-圆圈干扰验证码|gif-Gif验证码|line-干扰线验证码|shear-扭曲干扰验证码
|
# 验证码类型 circle-圆圈干扰验证码|gif-Gif验证码|line-干扰线验证码|shear-扭曲干扰验证码
|
||||||
type: circle
|
type: circle
|
||||||
# 验证码宽度
|
# 验证码宽度
|
||||||
width: 120
|
width: 120
|
||||||
# 验证码高度
|
# 验证码高度
|
||||||
height: 40
|
height: 40
|
||||||
# 验证码干扰元素个数
|
# 验证码干扰元素个数
|
||||||
interfere-count: 2
|
interfere-count: 2
|
||||||
# 文本透明度(0.0-1.0)
|
# 文本透明度(0.0-1.0)
|
||||||
text-alpha: 0.8
|
text-alpha: 0.8
|
||||||
# 验证码字符配置
|
# 验证码字符配置
|
||||||
code:
|
code:
|
||||||
# 验证码字符类型 math-算术|random-随机字符
|
# 验证码字符类型 math-算术|random-随机字符
|
||||||
type: math
|
type: math
|
||||||
# 验证码字符长度,type=算术时,表示运算位数(1:个位数运算 2:十位数运算);type=随机字符时,表示字符个数
|
# 验证码字符长度,type=算术时,表示运算位数(1:个位数运算 2:十位数运算);type=随机字符时,表示字符个数
|
||||||
length: 1
|
length: 1
|
||||||
# 验证码字体
|
# 验证码字体
|
||||||
font:
|
font:
|
||||||
# 字体名称 Dialog|DialogInput|Monospaced|Serif|SansSerif
|
# 字体名称 Dialog|DialogInput|Monospaced|Serif|SansSerif
|
||||||
name: SansSerif
|
name: SansSerif
|
||||||
# 字体样式 0-普通|1-粗体|2-斜体
|
# 字体样式 0-普通|1-粗体|2-斜体
|
||||||
weight: 1
|
weight: 1
|
||||||
# 字体大小
|
# 字体大小
|
||||||
size: 24
|
size: 24
|
||||||
# 验证码有效期(秒)
|
# 验证码有效期(秒)
|
||||||
expire-seconds: 120
|
expire-seconds: 120
|
||||||
|
|
||||||
# 微信小程配置
|
# 微信小程配置
|
||||||
wx:
|
wx:
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ security:
|
|||||||
refresh-token-time-to-live: 604800
|
refresh-token-time-to-live: 604800
|
||||||
# 无需认证的请求路径
|
# 无需认证的请求路径
|
||||||
ignore-urls:
|
ignore-urls:
|
||||||
- /api/v1/auth/login # 用户登录接口
|
- /api/v1/auth/login/** # 登录接口(账号密码登录、手机验证码登录和微信登录)
|
||||||
- /api/v1/auth/wechat-login # 微信登录接口
|
|
||||||
- /api/v1/auth/captcha # 验证码获取接口
|
- /api/v1/auth/captcha # 验证码获取接口
|
||||||
- /api/v1/auth/refresh-token # 刷新令牌接口
|
- /api/v1/auth/refresh-token # 刷新令牌接口
|
||||||
- /ws/** # WebSocket接口
|
- /ws/** # WebSocket接口
|
||||||
@@ -138,13 +137,13 @@ sms:
|
|||||||
domain: dysmsapi.aliyuncs.com
|
domain: dysmsapi.aliyuncs.com
|
||||||
regionId: cn-shanghai
|
regionId: cn-shanghai
|
||||||
signName: 有来技术
|
signName: 有来技术
|
||||||
templateCodes:
|
templates:
|
||||||
# 注册(预留)
|
# 注册短信验证码模板
|
||||||
register: SMS_22xxx771
|
register: SMS_22xxx771
|
||||||
# 登录(预留)
|
# 登录短信验证码模板
|
||||||
login: SMS_22xxx772
|
login: SMS_22xxx772
|
||||||
# 修改密码
|
# 修改手机号短信验证码模板
|
||||||
changePassword: SMS_22xxx773
|
change-mobile: SMS_22xxx773
|
||||||
|
|
||||||
# springdoc配置: https://springdoc.org/properties.html
|
# springdoc配置: https://springdoc.org/properties.html
|
||||||
springdoc:
|
springdoc:
|
||||||
|
|||||||
Reference in New Issue
Block a user