瀏覽代碼

商品做法关联编辑完成

xujunwei 4 年之前
父節點
當前提交
ded180aa8d

+ 7 - 0
framework-boot/pom.xml

@@ -113,6 +113,13 @@
             <groupId>io.springfox</groupId>
             <artifactId>springfox-swagger2</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-core</artifactId>
+        </dependency>
+
+
     </dependencies>
 
 </project>

+ 39 - 0
framework-boot/src/main/java/com/mrxu/framework/boot/token/JwtLoginConfig.java

@@ -0,0 +1,39 @@
+package com.mrxu.framework.boot.token;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+
+@Data
+@Configuration
+public class JwtLoginConfig {
+
+    /**
+     * jwt认证加密私钥(Base64加密)
+     */
+    private String encryptJWTKey = "U0JBUElKV1RkV2FuZzkyNjQ1NA==";
+
+    /**
+     * @Author: xujunwei
+     * @Date: 2021/8/23
+     * @Description: 不需要登录的url
+     */
+    private String unLoginUrl = "";
+
+    /**
+     * @Author: xujunwei
+     * @Date: 2021/8/23
+     * @Description: session有效期默认30分钟,如果30分钟无任何操作则session过期
+     */ 
+    private long SESSION_EXPIRE_TIME = 1000l*60*30;
+
+    /**
+     * @Author: xujunwei
+     * @Date: 2021/8/23
+     * @Description: token有效时长默认20秒,操过20秒则重新生成
+     */
+    private long TOKEN_EXPIRE_TIME = 1000l*20;
+
+
+}

+ 58 - 0
framework-boot/src/main/java/com/mrxu/framework/boot/token/SecurityFilter.java

@@ -0,0 +1,58 @@
+package com.mrxu.framework.boot.token;
+
+import com.mrxu.framework.common.util.StrFunc;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.util.AntPathMatcher;
+import org.springframework.util.PathMatcher;
+import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;
+import org.springframework.web.server.ServerWebExchange;
+import org.springframework.web.server.WebFilterChain;
+import reactor.core.publisher.Mono;
+
+import javax.annotation.PostConstruct;
+import java.net.URI;
+
+public class SecurityFilter extends HiddenHttpMethodFilter {
+
+    @Autowired
+    private JwtLoginConfig jtbAuthProperties;
+
+    private String[] unLoginUrl;
+
+    private final PathMatcher pathMatcher = new AntPathMatcher();
+
+    @PostConstruct
+    private void init() {
+        if(StrFunc.isNotEmpty(jtbAuthProperties.getUnLoginUrl())) {
+            unLoginUrl = jtbAuthProperties.getUnLoginUrl().split(",");
+        }
+    }
+
+    @Override
+    public Mono filter(ServerWebExchange exchange, WebFilterChain chain) {
+        ServerHttpRequest request = exchange.getRequest();
+        URI uri = request.getURI();
+        String path = uri.getPath();
+        if(!needLogin(path)) {
+            return chain.filter(exchange);
+        }
+        // String tokenStr = request.getHeaders().getFirst(Constants.AUTH_HEADER);
+        return null;
+    }
+
+    /**
+     * @Author: xujunwei
+     * @Date: 2021/8/23
+     * @Description: 判断url是否需要登录
+     */
+    private boolean needLogin(String path) {
+        for (String url : unLoginUrl) {
+            if (pathMatcher.match(url, path)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+}