xucaiqin 2 жил өмнө
parent
commit
322af145be

+ 4 - 1
iot-framework/iot-common/pom.xml

@@ -22,7 +22,10 @@
             <groupId>cn.hutool</groupId>
             <artifactId>hutool-all</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-databind</artifactId>

+ 1 - 1
iot-gateway/src/main/java/com/middle/platform/gateway/constant/RequestConstant.java → iot-framework/iot-common/src/main/java/com/middle/platform/common/constant/RequestConstant.java

@@ -1,4 +1,4 @@
-package com.middle.platform.gateway.constant;
+package com.middle.platform.common.constant;
 
 
 public class RequestConstant {

+ 0 - 1
iot-framework/iot-common/src/main/java/com/middle/platform/common/utils/JsonUtils.java

@@ -20,7 +20,6 @@ import java.util.List;
 /**
  * JSON 工具类
  *
- * @author 芋道源码
  */
 @Slf4j
 public class JsonUtils {

+ 24 - 0
iot-framework/iot-common/src/main/java/com/middle/platform/common/utils/ResponseUtil.java

@@ -0,0 +1,24 @@
+package com.middle.platform.common.utils;
+
+import com.alibaba.fastjson.JSON;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+
+public class ResponseUtil {
+
+    /**
+     * 相应输出
+     *
+     * @param response 响应
+     */
+    public static void writer(HttpServletResponse response, Result<?> result) throws IOException {
+        response.setCharacterEncoding("utf-8");
+        PrintWriter printWriter = response.getWriter();
+        printWriter.write(JSON.toJSONString(result));
+        printWriter.flush();
+        printWriter.close();
+    }
+}

+ 0 - 1
iot-framework/iot-common/src/main/java/com/middle/platform/common/utils/ServletUtils.java

@@ -18,7 +18,6 @@ import java.util.Map;
 /**
  * 客户端工具类
  *
- * @author 芋道源码
  */
 public class ServletUtils {
 

+ 25 - 0
iot-framework/iot-starter-pagehelper/pom.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.middle.platform</groupId>
+        <artifactId>iot-framework</artifactId>
+        <version>${revision}</version>
+    </parent>
+
+    <artifactId>iot-starter-pagehelper</artifactId>
+    <packaging>jar</packaging>
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>com.github.pagehelper</groupId>
+            <artifactId>pagehelper-spring-boot-starter</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 35 - 0
iot-framework/iot-starter-satoken/pom.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.middle.platform</groupId>
+        <artifactId>iot-framework</artifactId>
+        <version>${revision}</version>
+    </parent>
+
+    <artifactId>iot-starter-satoken</artifactId>
+    <packaging>jar</packaging>
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>com.middle.platform</groupId>
+            <artifactId>iot-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>cn.dev33</groupId>
+            <artifactId>sa-token-spring-boot3-starter</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.dev33</groupId>
+            <artifactId>sa-token-redis-jackson</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 40 - 0
iot-framework/iot-starter-satoken/src/main/java/com/middle/platform/satoken/config/SaTokenConfig.java

@@ -0,0 +1,40 @@
+package com.middle.platform.satoken.config;
+
+import cn.dev33.satoken.context.SaHolder;
+import cn.dev33.satoken.filter.SaServletFilter;
+import com.middle.platform.common.utils.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Slf4j
+@Configuration
+public class SaTokenConfig {
+
+    /**
+     * 注册 [Sa-Token全局过滤器]
+     */
+    @Bean
+    public SaServletFilter getSaServletFilter() {
+        return new SaServletFilter()
+                // 指定 拦截路由 与 放行路由
+                .addInclude("/**")
+                .addExclude("/auth/login","/auth/logout")
+                // 异常处理函数:每次认证函数发生异常时执行此函数
+                .setError(e -> {
+                    SaHolder.getResponse().setHeader("Content-Type", "application/json;charset=UTF-8");
+                    return Result.failed(e.getMessage());
+                })
+
+                // 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
+                .setBeforeAuth(r -> {
+                    // ---------- 设置一些安全响应头 ----------
+                    SaHolder.getResponse()
+                            // 是否启用浏览器默认XSS防护: 0=禁用 | 1=启用 | 1; mode=block 启用, 并在检查到XSS攻击时,停止渲染页面
+                            .setHeader("X-XSS-Protection", "1; mode=block")
+                            // 禁用浏览器内容嗅探
+                            .setHeader("X-Content-Type-Options", "nosniff")
+                    ;
+                });
+    }
+}

+ 1 - 0
iot-framework/iot-starter-satoken/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -0,0 +1 @@
+com.middle.platform.satoken.config.SaTokenConfig

+ 2 - 0
iot-framework/pom.xml

@@ -25,6 +25,8 @@
         <module>iot-starter-tdengine</module>
         <module>iot-starter-rabbitmq</module>
         <module>iot-starter-log</module>
+        <module>iot-starter-satoken</module>
+        <module>iot-starter-pagehelper</module>
     </modules>
     <properties>
         <maven.compiler.source>17</maven.compiler.source>