From a39378d26613429c2d9d80756e062fe013651c85 Mon Sep 17 00:00:00 2001
From: weiyachao <13526234727@126.com>
Date: Thu, 21 Sep 2023 13:38:12 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9D=E8=B5=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
iot-common/iot-base/pom.xml | 4 ++
.../com/qiuguo/iot/base/nlp/lac/LacNlp.java | 3 ++
iot-modules/iot-box-user-api/pom.xml | 21 +++++++-
.../iot/user/api/filter/AuthFilter.java | 48 +++++++++----------
4 files changed, 51 insertions(+), 25 deletions(-)
diff --git a/iot-common/iot-base/pom.xml b/iot-common/iot-base/pom.xml
index e17052a..570cf9b 100644
--- a/iot-common/iot-base/pom.xml
+++ b/iot-common/iot-base/pom.xml
@@ -41,6 +41,10 @@
org.projectlombok
lombok
+
+ org.slf4j
+ slf4j-api
+
${project.artifactId}
diff --git a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/nlp/lac/LacNlp.java b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/nlp/lac/LacNlp.java
index 984860a..fa1095b 100644
--- a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/nlp/lac/LacNlp.java
+++ b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/nlp/lac/LacNlp.java
@@ -6,6 +6,9 @@ import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.nlp.INlp;
import com.qiuguo.iot.base.nlp.Nlp;
import com.qiuguo.iot.base.nlp.NlpKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.WebClient;
diff --git a/iot-modules/iot-box-user-api/pom.xml b/iot-modules/iot-box-user-api/pom.xml
index 648f8f8..74f7d3b 100644
--- a/iot-modules/iot-box-user-api/pom.xml
+++ b/iot-modules/iot-box-user-api/pom.xml
@@ -83,7 +83,26 @@
reactor-test
test
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.springframework
+ spring-webmvc
+
+
com.qiuguo.iot
iot-data
diff --git a/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/filter/AuthFilter.java b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/filter/AuthFilter.java
index 50014c2..82e29df 100644
--- a/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/filter/AuthFilter.java
+++ b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/filter/AuthFilter.java
@@ -19,7 +19,7 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
-import org.springframework.web.servlet.HandlerMapping;
+// import org.springframework.web.servlet.HandlerMapping;
import reactor.core.publisher.Mono;
/**
@@ -38,31 +38,31 @@ public class AuthFilter implements WebFilter {
@Override
public Mono filter(ServerWebExchange exchange, WebFilterChain chain) {
- HandlerMethod handlerMethod = exchange.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
+ // HandlerMethod handlerMethod = exchange.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
Object attribute = exchange.getAttribute("org.springframework.web.server.ServerWebExchange.LOG_ID");
System.out.println("attribute = " + attribute);
- if (handlerMethod != null && handlerMethod.getMethod().isAnnotationPresent(Auth.class)) {
- // 如果请求方法上有 Auth 注解,执行登录验证逻辑
- 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)) {
- return Mono.error(new RuntimeException("未登录"));
- }
- String key = RedisConstans.IOT_TOKEN.concat(api_token);
- return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> {
- if (ttl == -1) {
- // 用户没登陆
- return Mono.error(new RuntimeException("未登录"));
- } else if (ttl <= 3600) {
- // token 将要失效
- return reactiveRedisTemplate.expire(key, Duration.ofDays(7))
- .then(chain.filter(exchange));
- } else {
- // 正常登录
- return chain.filter(exchange);
- }
- });
- }
+ // if (handlerMethod != null && handlerMethod.getMethod().isAnnotationPresent(Auth.class)) {
+ // // 如果请求方法上有 Auth 注解,执行登录验证逻辑
+ // 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)) {
+ // return Mono.error(new RuntimeException("未登录"));
+ // }
+ // String key = RedisConstans.IOT_TOKEN.concat(api_token);
+ // return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> {
+ // if (ttl == -1) {
+ // // 用户没登陆
+ // return Mono.error(new RuntimeException("未登录"));
+ // } else if (ttl <= 3600) {
+ // // token 将要失效
+ // return reactiveRedisTemplate.expire(key, Duration.ofDays(7))
+ // .then(chain.filter(exchange));
+ // } else {
+ // // 正常登录
+ // return chain.filter(exchange);
+ // }
+ // });
+ // }
return chain.filter(exchange);
}