This commit is contained in:
weiyachao 2023-09-22 10:17:59 +08:00
parent 6f1a085a76
commit 2df97baa3a
3 changed files with 45 additions and 28 deletions

View File

@ -36,29 +36,30 @@ public class AuthFilter implements GlobalFilter, Ordered {
@Override @Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest(); ServerHttpRequest request = exchange.getRequest();
String url = request.getURI().toString(); String url = request.getPath().toString();
if (xssProperties.getExcludeUrls().contains(url)) {
return chain.filter(exchange); return chain.filter(exchange);
} // if (xssProperties.getExcludeUrls().contains(url)) {
// return chain.filter(exchange);
String api_token = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TOKEN); // }
String api_type = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TYPE); //
if (ObjectUtils.isEmpty(api_token) || ObjectUtils.isEmpty(api_type)) { // String api_token = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TOKEN);
return Mono.error(new RuntimeException("未登录")); // String api_type = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TYPE);
} // if (ObjectUtils.isEmpty(api_token) || ObjectUtils.isEmpty(api_type)) {
String key = RedisConstans.IOT_TOKEN.concat(api_token); // return Mono.error(new RuntimeException("未登录"));
return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> { // }
if (ttl == -1) { // String key = RedisConstans.IOT_TOKEN.concat(api_token);
// 用户没登陆 // return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> {
return Mono.error(new RuntimeException("未登录")); // if (ttl == -1) {
} else if (ttl <= 3600) { // // 用户没登陆
// token 将要失效 // return Mono.error(new RuntimeException("未登录"));
return reactiveRedisTemplate.expire(key, Duration.ofDays(7)).then(chain.filter(exchange)); // } else if (ttl <= 3600) {
} else { // // token 将要失效
// 正常登录 // return reactiveRedisTemplate.expire(key, Duration.ofDays(7)).then(chain.filter(exchange));
return chain.filter(exchange); // } else {
} // // 正常登录
}); // return chain.filter(exchange);
// }
// });
} }

View File

@ -1,5 +1,5 @@
server: server:
port: 8080 port: 8081
spring: spring:
profiles: profiles:
# 环境配置 # 环境配置
@ -38,6 +38,20 @@ spring:
# 允许跨域请求里的head字段设置*为全部 # 允许跨域请求里的head字段设置*为全部
allowedHeaders: "*" allowedHeaders: "*"
routes: routes:
# # 系统服务
# - id: qiuguo-iot-box-user-api
# # 匹配后路由地址
# uri: lb://qiuguo-iot-box-user-api
# # 断言,路径相匹配的进行路由
# predicates:
# - Path=/qiuguo-iot-box-user-api/**
# filters:
# # 转发时去掉一层路径
# - StripPrefix=1
- id: qiuguo-iot-box-user-api
uri: http://192.168.8.199:8080
predicates:
- Path=/iot-user/**
# 安全配置 # 安全配置
security: security:
@ -46,8 +60,9 @@ security:
enabled: true enabled: true
# 排除的路径 # 排除的路径
exclude-urls: exclude-urls:
- /ehs-audit/web/audit-content - /iot-user/user/user/login/pwd
application: #application:
cors: # cors:
allowed-crigin-patterns: # allowed-crigin-patterns:
# - /iot-user/user/user/login/pwd

View File

@ -1,5 +1,6 @@
server: server:
port: 8080 port: 8080
spring: spring:
profiles: profiles:
# 环境配置 # 环境配置