|
@@ -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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|