From e21933ca3f6f66a3f0d523fe425d145ec93aed2c Mon Sep 17 00:00:00 2001 From: wulin Date: Tue, 7 Nov 2023 19:34:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes .../iot/base/constans/Log4Constans.java | 2 +- .../qiuguo/iot/base/utils/StringUtils.java | 6 ++ iot-gateway/pom.xml | 4 +- .../qiuguo/iot/gateway/filter/AuthFilter.java | 6 +- .../src/main/resources/bootstrap-dev.yml | 1 + iot-gateway/src/main/resources/bootstrap.yml | 2 +- iot-modules/.DS_Store | Bin 6148 -> 6148 bytes iot-modules/iot-box-user-api/pom.xml | 7 +-- .../iot/user/api/filter/AuthFilter.java | 58 ------------------ .../src/main/resources/logback-spring.xml | 4 +- 11 files changed, 19 insertions(+), 71 deletions(-) delete mode 100644 iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/filter/AuthFilter.java diff --git a/.DS_Store b/.DS_Store index a3719534acca7d2dd377d6c7fd522763ae5723cb..8de5a87145d526a0a2c2fd57219af9567354488c 100644 GIT binary patch delta 187 zcmZoMXfc=|#>B!ku~2NHo}wrl0|Nsi1A_nqLn=d2Qh9MfQcix-W=59f%z_{(Hii_2 ze1>F(Y>@P1Y3AdSC?aLSMR_^-dFdcSCi5_nVC%|J2NG4N>o={8tW(+n}bwr-p3ruxS5@Up9APLp!MIGC-aLq RasXY%1T>prbA-qmW&p1AD$f7_ delta 133 zcmZoMXfc=|#>B)qu~2NHo}wrV0|Nsi1A_nqLoP!;LkdGFLk>gg#=_-{j4YGyvP$tJ zl@}Kz<>V&;m2ICa%~r@EUR`aVqhM|{c|NNwW9Q@pEb@$9K$ZTJEm>A=zQ$(AxUu02 h(`I%Keh#1|n*}+(Gf(ChapVB%2ie22IYML&GXS|1A>sf4 diff --git a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/Log4Constans.java b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/Log4Constans.java index 96275be..1b9df18 100644 --- a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/Log4Constans.java +++ b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/Log4Constans.java @@ -1,6 +1,6 @@ package com.qiuguo.iot.base.constans; public class Log4Constans { - public static String PRINT_LOG_ID = "tid"; + public static String PRINT_LOG_ID = "traceId"; public static String CUSTOMER_IP = "customerIp"; } diff --git a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java index 2835476..661bd43 100644 --- a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java +++ b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java @@ -1,6 +1,7 @@ package com.qiuguo.iot.base.utils; import java.util.Random; +import java.util.UUID; public class StringUtils extends cn.hutool.core.util.StrUtil{ private static final String chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -21,4 +22,9 @@ public class StringUtils extends cn.hutool.core.util.StrUtil{ } return sb.toString(); } + + public static String getUUID(){ + UUID uuid = UUID.randomUUID(); + return uuid.toString().replace("-", ""); + } } diff --git a/iot-gateway/pom.xml b/iot-gateway/pom.xml index 1c18c53..b9074a3 100644 --- a/iot-gateway/pom.xml +++ b/iot-gateway/pom.xml @@ -75,12 +75,12 @@ org.apache.skywalking apm-toolkit-trace - 8.7.0 + 8.4.0 org.apache.skywalking apm-toolkit-logback-1.x - 8.7.0 + 8.4.0 diff --git a/iot-gateway/src/main/java/com/qiuguo/iot/gateway/filter/AuthFilter.java b/iot-gateway/src/main/java/com/qiuguo/iot/gateway/filter/AuthFilter.java index f877507..c2eb1d0 100644 --- a/iot-gateway/src/main/java/com/qiuguo/iot/gateway/filter/AuthFilter.java +++ b/iot-gateway/src/main/java/com/qiuguo/iot/gateway/filter/AuthFilter.java @@ -3,11 +3,13 @@ package com.qiuguo.iot.gateway.filter; import com.qiuguo.iot.base.constans.Log4Constans; import com.qiuguo.iot.base.constans.RedisConstans; import com.qiuguo.iot.base.constans.UserAuthContains; +import com.qiuguo.iot.base.utils.StringUtils; import com.qiuguo.iot.gateway.config.properties.XssProperties; import java.nio.charset.StandardCharsets; import java.time.Duration; import lombok.extern.slf4j.Slf4j; +import org.apache.skywalking.apm.toolkit.trace.Trace; import org.apache.skywalking.apm.toolkit.trace.TraceContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.gateway.filter.GatewayFilterChain; @@ -40,13 +42,15 @@ public class AuthFilter implements GlobalFilter, Ordered { @Autowired private XssProperties xssProperties; + @Override public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + ServerHttpRequest request = exchange.getRequest(); String url = request.getPath().toString(); String customerIp = request.getRemoteAddress().getAddress().getHostAddress(); - String tracId = TraceContext.traceId(); + String tracId = StringUtils.getUUID(); ServerWebExchange.Builder ex = exchange.mutate(); ex.request(getRequest(exchange, customerIp, tracId)); if (xssProperties.getExcludeUrls().contains(url)) { diff --git a/iot-gateway/src/main/resources/bootstrap-dev.yml b/iot-gateway/src/main/resources/bootstrap-dev.yml index c35f3f4..415f73a 100644 --- a/iot-gateway/src/main/resources/bootstrap-dev.yml +++ b/iot-gateway/src/main/resources/bootstrap-dev.yml @@ -69,6 +69,7 @@ security: exclude-urls: - /iot-user/user/login/pwd - /iot-user/music/search + - /iot-user/device/init - /iot-websocket/push/message - /iot-websocket/websocket/box - /iot-websocket/websocket/customer diff --git a/iot-gateway/src/main/resources/bootstrap.yml b/iot-gateway/src/main/resources/bootstrap.yml index ec17f21..e0b0a0e 100644 --- a/iot-gateway/src/main/resources/bootstrap.yml +++ b/iot-gateway/src/main/resources/bootstrap.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 8081 spring: application: name: qiuguo-iot-gateway diff --git a/iot-modules/.DS_Store b/iot-modules/.DS_Store index 9b5b34dc4da68218f5209876f35779a56d4a84fe..6561625243755357f1cd70c8134934fac6951483 100644 GIT binary patch delta 209 zcmZoMXfc=|#>B!ku~2NHo}wrV0|Nsi1A_nqLlQ$iLj{8_Ln%Y?W=H1b%!VK-0ftPV za0yTtNtz**p$I6F$WXwLnN(g}kd%|31XR0wvKvz&k92jlp@or-g07)~$>jY^vW&fx z?=s07_7P)PS#VKaPJUiG$W4>~GU;u$V%o&CnVo~51L$C&qrNjw<`;3~0J@h6sDxp2 Igvc6Z04Z86od5s; delta 89 zcmZoMXfc=|#>B)qu~2NHo}wrd0|Nsi1A_nqLlQ$iLj{8_Lpek0#=_-{lMO^zCQGwv qZw_VM#I&(Nnt3xj2R{c;<7PpQ@640=MI1SRT0weQHb;o8VFmzIKoXz; diff --git a/iot-modules/iot-box-user-api/pom.xml b/iot-modules/iot-box-user-api/pom.xml index a0b949b..227624e 100644 --- a/iot-modules/iot-box-user-api/pom.xml +++ b/iot-modules/iot-box-user-api/pom.xml @@ -71,15 +71,10 @@ test - - org.apache.skywalking - apm-toolkit-trace - 8.7.0 - org.apache.skywalking apm-toolkit-logback-1.x - 8.7.0 + 8.4.0 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 deleted file mode 100644 index ae8d0bd..0000000 --- a/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/filter/AuthFilter.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.qiuguo.iot.user.api.filter; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.data.redis.core.ReactiveStringRedisTemplate; -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 reactor.core.publisher.Mono; - -/** - * XXX - * - * @author weiyachao - * @since 2023/9/20 16:06 - */ -@Configuration -@Slf4j -@Order(-1) -public class AuthFilter implements WebFilter { - - // @Autowired - private ReactiveStringRedisTemplate reactiveRedisTemplate; - - @Override - public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { - // 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); - // } - // }); - // } - - return chain.filter(exchange); - } - -} diff --git a/iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml b/iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml index 44e8b12..c5702be 100644 --- a/iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml +++ b/iot-modules/iot-box-user-api/src/main/resources/logback-spring.xml @@ -5,7 +5,7 @@ - + @@ -48,7 +48,7 @@ - ${SKY_PATTERN} + ${SKY_PATTERN}