Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-cloud-core
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-cloud-core
Commits
7302fd93
Commit
7302fd93
authored
Sep 03, 2025
by
jianan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
knife4j
parent
243a95c0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
yd-auth-core/src/main/java/com/yd/auth/core/config/SecurityConfig.java
+7
-1
yd-gateway/pom.xml
+7
-0
yd-gateway/src/main/java/com/yd/gateway/config/GatewayJwtAuthFilterConfig.java
+29
-1
No files found.
yd-auth-core/src/main/java/com/yd/auth/core/config/SecurityConfig.java
View file @
7302fd93
...
@@ -66,7 +66,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -66,7 +66,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/auth/register"
,
"/auth/register"
,
"/swagger-ui/**"
,
"/swagger-ui/**"
,
"/v3/api-docs/**"
,
"/v3/api-docs/**"
,
"/scrm/test"
"/scrm/test"
,
"/doc.html"
,
"/webjars/**"
,
"/favicon.ico"
,
"/user/api/v3/api-docs"
,
"/insurance/base/api/v3/api-docs"
,
"/csf/api/v3/api-docs"
).
permitAll
()
).
permitAll
()
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
.
and
()
.
and
()
...
...
yd-gateway/pom.xml
View file @
7302fd93
...
@@ -14,6 +14,13 @@
...
@@ -14,6 +14,13 @@
<description>
网关模块
</description>
<description>
网关模块
</description>
<dependencies>
<dependencies>
<!-- knife4j 网关依赖 -->
<dependency>
<groupId>
com.github.xiaoymin
</groupId>
<artifactId>
knife4j-gateway-spring-boot-starter
</artifactId>
<version>
4.3.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-gateway
</artifactId>
<artifactId>
spring-cloud-starter-gateway
</artifactId>
...
...
yd-gateway/src/main/java/com/yd/gateway/config/GatewayJwtAuthFilterConfig.java
View file @
7302fd93
...
@@ -2,6 +2,7 @@ package com.yd.gateway.config;
...
@@ -2,6 +2,7 @@ package com.yd.gateway.config;
import
com.yd.gateway.exception.JwtAuthException
;
import
com.yd.gateway.exception.JwtAuthException
;
import
com.yd.gateway.utils.JwtTokenUtil
;
import
com.yd.gateway.utils.JwtTokenUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -9,6 +10,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -9,6 +10,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.util.AntPathMatcher
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
...
@@ -16,11 +18,27 @@ import reactor.core.publisher.Mono;
...
@@ -16,11 +18,27 @@ import reactor.core.publisher.Mono;
* 网关JWT认证过滤器:只做轻量校验(验证token有效性),不查询业务数据
* 网关JWT认证过滤器:只做轻量校验(验证token有效性),不查询业务数据
*/
*/
@Configuration
@Configuration
@Slf4j
public
class
GatewayJwtAuthFilterConfig
{
public
class
GatewayJwtAuthFilterConfig
{
@Autowired
@Autowired
private
JwtTokenUtil
jwtTokenUtil
;
private
JwtTokenUtil
jwtTokenUtil
;
private
AntPathMatcher
matcher
=
new
AntPathMatcher
();
private
static
final
String
[]
KNIFE4J_WHITELIST
=
{
"/doc.html"
,
"/webjars/**"
,
"/v3/api-docs/*"
,
"/swagger-resources/*"
,
"/swagger-ui/*"
,
"/auth/v2/api-docs/*"
,
"/favicon.ico"
,
"/user/api/v3/api-docs/**"
,
"/insurance/base/api/v3/api-docs/**"
,
"/csf/api/v3/api-docs/**"
};
/**
/**
* 注册全局过滤器,优先级高于路由过滤器(确保先校验再路由)
* 注册全局过滤器,优先级高于路由过滤器(确保先校验再路由)
*/
*/
...
@@ -65,6 +83,15 @@ public class GatewayJwtAuthFilterConfig {
...
@@ -65,6 +83,15 @@ public class GatewayJwtAuthFilterConfig {
return
null
;
return
null
;
}
}
private
boolean
isKnife4jWhitelist
(
String
requestPath
)
{
for
(
String
pattern
:
KNIFE4J_WHITELIST
)
{
if
(
matcher
.
match
(
pattern
,
requestPath
))
{
return
true
;
}
}
return
false
;
}
/**
/**
* 判断路径是否在白名单中(无需认证)
* 判断路径是否在白名单中(无需认证)
*/
*/
...
@@ -72,7 +99,8 @@ public class GatewayJwtAuthFilterConfig {
...
@@ -72,7 +99,8 @@ public class GatewayJwtAuthFilterConfig {
// 白名单路径:与SecurityWebFilterChain中的配置保持一致
// 白名单路径:与SecurityWebFilterChain中的配置保持一致
return
path
.
startsWith
(
"/auth/"
)
return
path
.
startsWith
(
"/auth/"
)
||
path
.
startsWith
(
"/swagger-ui/"
)
||
path
.
startsWith
(
"/swagger-ui/"
)
||
path
.
startsWith
(
"/v3/api-docs/"
);
||
path
.
startsWith
(
"/v3/api-docs/"
)
||
isKnife4jWhitelist
(
path
);
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment