微服务改造
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -106,6 +106,12 @@
|
|||||||
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
|
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
|
||||||
<version>4.4.0</version>
|
<version>4.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-openapi3-ui</artifactId>
|
||||||
|
<version>4.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Cloud LoadBalancer -->
|
<!-- Spring Cloud LoadBalancer -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -95,12 +95,21 @@ public class GlobalAuthWebFilter implements WebFilter {
|
|||||||
// 5. 黑名单检查(仅当启用时)
|
// 5. 黑名单检查(仅当启用时)
|
||||||
if (authProperties.isBlacklistEnabled()) {
|
if (authProperties.isBlacklistEnabled()) {
|
||||||
String blacklistKey = AuthConstants.BLACKLIST_PREFIX + principal.getId();
|
String blacklistKey = AuthConstants.BLACKLIST_PREFIX + principal.getId();
|
||||||
Boolean isBlacklisted = redisTemplate.hasKey(blacklistKey).block();
|
return redisTemplate.hasKey(blacklistKey).flatMap(isBlacklisted -> {
|
||||||
if (Boolean.TRUE.equals(isBlacklisted)) {
|
if (Boolean.TRUE.equals(isBlacklisted)) {
|
||||||
return writeUnauthorized(exchange, AuthConstants.MSG_TOKEN_BLACKLISTED);
|
return writeUnauthorized(exchange, AuthConstants.MSG_TOKEN_BLACKLISTED);
|
||||||
}
|
}
|
||||||
|
return continueChain(exchange, chain, principal);
|
||||||
|
}).onErrorResume(e -> {
|
||||||
|
log.error("Redis check failed", e);
|
||||||
|
return continueChain(exchange, chain, principal);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return continueChain(exchange, chain, principal);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mono<Void> continueChain(ServerWebExchange exchange, WebFilterChain chain, AuthPrincipalVo principal) {
|
||||||
// 6. 写入下游请求头
|
// 6. 写入下游请求头
|
||||||
String userInfoJson;
|
String userInfoJson;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -9,7 +9,25 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: aida-gateway
|
name: aida-gateway
|
||||||
|
cloud:
|
||||||
|
gateway:
|
||||||
|
routes:
|
||||||
|
- id: aida-back
|
||||||
|
uri: lb://aida-back
|
||||||
|
predicates:
|
||||||
|
- Path=/aida/**
|
||||||
|
filters:
|
||||||
|
- StripPrefix=1
|
||||||
|
- id: aida-seller
|
||||||
|
uri: lb://aida-seller
|
||||||
|
predicates:
|
||||||
|
- Path=/seller/**
|
||||||
|
filters:
|
||||||
|
- StripPrefix=1
|
||||||
|
- id: aida-python
|
||||||
|
uri: http://18.167.251.121:9994
|
||||||
|
predicates:
|
||||||
|
- Path=/python/**
|
||||||
# ---------- Knife4j 网关聚合配置 ----------
|
# ---------- Knife4j 网关聚合配置 ----------
|
||||||
knife4j:
|
knife4j:
|
||||||
gateway:
|
gateway:
|
||||||
@@ -17,13 +35,13 @@ knife4j:
|
|||||||
# 手动指定下游服务的文档聚合,可以灵活应对不同服务的 API 版本或路径前缀
|
# 手动指定下游服务的文档聚合,可以灵活应对不同服务的 API 版本或路径前缀
|
||||||
strategy: manual
|
strategy: manual
|
||||||
routes:
|
routes:
|
||||||
- name: 业务服务 (Back)
|
- name: aida主服务
|
||||||
url: /api/v3/api-docs
|
url: /aida/v3/api-docs
|
||||||
service-name: aida-back
|
service-name: aida-back
|
||||||
context-path: /api
|
context-path: /aida
|
||||||
order: 1
|
order: 1
|
||||||
- name: 商家端服务 (Seller)
|
- name: 商家端服务 (Seller)
|
||||||
url: /seller/api/v3/api-docs
|
url: /seller/v3/api-docs
|
||||||
service-name: aida-seller
|
service-name: aida-seller
|
||||||
context-path: /seller
|
context-path: /seller
|
||||||
order: 2
|
order: 2
|
||||||
@@ -31,7 +49,7 @@ knife4j:
|
|||||||
# ---------- Gateway JWT 认证(gateway 独有) ----------
|
# ---------- Gateway JWT 认证(gateway 独有) ----------
|
||||||
gateway:
|
gateway:
|
||||||
auth:
|
auth:
|
||||||
jwt-secret: ${BACK_JWT_SECRET:JWTSECRET}
|
jwt-secret: JWTSECRET
|
||||||
jwt-token-header: Authorization
|
jwt-token-header: Authorization
|
||||||
jwt-token-prefix: Bearer-
|
jwt-token-prefix: Bearer-
|
||||||
blacklist-enabled: true
|
blacklist-enabled: true
|
||||||
@@ -76,6 +94,56 @@ gateway:
|
|||||||
- /api/global-award/**
|
- /api/global-award/**
|
||||||
- /api/llm/stream
|
- /api/llm/stream
|
||||||
- /notification/**
|
- /notification/**
|
||||||
|
- /aida/api/account/login
|
||||||
|
- /aida/api/account/preLogin
|
||||||
|
- /aida/api/designer/check
|
||||||
|
- /aida/api/account/sendEmail
|
||||||
|
- /aida/api/account/noLoginRequired
|
||||||
|
- /aida/api/account/resetPwd
|
||||||
|
- /aida/api/account/designWorksRegister
|
||||||
|
- /aida/api/account/questionnaire
|
||||||
|
- /aida/api/account/schoolLogin
|
||||||
|
- /aida/api/account/enterpriseLogin
|
||||||
|
- /aida/api/account/organizationNameSearch
|
||||||
|
- /aida/api/account/activateNewEmail
|
||||||
|
- /aida/api/python/saveGeneratePicture
|
||||||
|
- /aida/api/python/getLibraryByUserId
|
||||||
|
- /aida/api/python/flush
|
||||||
|
- /aida/api/account/healthy
|
||||||
|
- /aida/api/third/party/**
|
||||||
|
- /aida/api/element/initDefaultSysFile
|
||||||
|
- /aida/api/ali-pay/trade/notify
|
||||||
|
- /aida/api/paypal/ipn/back
|
||||||
|
- /aida/api/alipay-hk/trade/notify
|
||||||
|
- /aida/api/stripe/trade/notify
|
||||||
|
- /aida/api/portfolio/**
|
||||||
|
- /aida/api/global-award/**
|
||||||
|
- /aida/api/llm/stream
|
||||||
|
- /aida/account/login
|
||||||
|
- /aida/account/preLogin
|
||||||
|
- /aida/designer/check
|
||||||
|
- /aida/account/sendEmail
|
||||||
|
- /aida/account/noLoginRequired
|
||||||
|
- /aida/account/resetPwd
|
||||||
|
- /aida/account/designWorksRegister
|
||||||
|
- /aida/account/questionnaire
|
||||||
|
- /aida/account/schoolLogin
|
||||||
|
- /aida/account/enterpriseLogin
|
||||||
|
- /aida/account/organizationNameSearch
|
||||||
|
- /aida/account/activateNewEmail
|
||||||
|
- /aida/python/saveGeneratePicture
|
||||||
|
- /aida/python/getLibraryByUserId
|
||||||
|
- /aida/python/flush
|
||||||
|
- /aida/account/healthy
|
||||||
|
- /aida/third/party/**
|
||||||
|
- /aida/element/initDefaultSysFile
|
||||||
|
- /aida/ali-pay/trade/notify
|
||||||
|
- /aida/paypal/ipn/back
|
||||||
|
- /aida/alipay-hk/trade/notify
|
||||||
|
- /aida/stripe/trade/notify
|
||||||
|
- /aida/portfolio/**
|
||||||
|
- /aida/global-award/**
|
||||||
|
- /aida/llm/stream
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
|
|||||||
Reference in New Issue
Block a user