diff --git a/gateway/src/main/java/com/bonus/gateway/config/AuthWriteUtils.java b/gateway/src/main/java/com/bonus/gateway/config/AuthWriteUtils.java new file mode 100644 index 0000000..ef131b8 --- /dev/null +++ b/gateway/src/main/java/com/bonus/gateway/config/AuthWriteUtils.java @@ -0,0 +1,31 @@ +package com.bonus.gateway.config; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author 黑子 + */ +public class AuthWriteUtils { + + public static List getBlackUrl(){ + List whiteUrl=new ArrayList<>(); + whiteUrl.add("/bmw/**"); + return whiteUrl; + } + + public static List getWriteUrl(){ + List whiteUrl=new ArrayList<>(); + whiteUrl.add("js"); + whiteUrl.add("ttf"); + whiteUrl.add("woff2"); + whiteUrl.add("woff"); + whiteUrl.add("ico"); + whiteUrl.add("css"); + whiteUrl.add("png"); + whiteUrl.add("jpg"); + whiteUrl.add("html"); + return whiteUrl; + + } +} diff --git a/gateway/src/main/java/com/bonus/gateway/config/CorsConfig.java b/gateway/src/main/java/com/bonus/gateway/config/CorsConfig.java new file mode 100644 index 0000000..3ba7a12 --- /dev/null +++ b/gateway/src/main/java/com/bonus/gateway/config/CorsConfig.java @@ -0,0 +1,26 @@ +package com.bonus.gateway.config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; +import org.springframework.web.util.pattern.PathPatternParser; + +/** + * description: + * java项目fhadmin.cn + */ +@Configuration +public class CorsConfig { + @Bean + public CorsWebFilter corsFilter() { + CorsConfiguration config = new CorsConfiguration(); + config.addAllowedMethod("*"); // 是什么请求方法,比如GET POST PUT DELATE ... + config.addAllowedOrigin("*"); // 来自哪个域名的请求,*号表示所有 + config.addAllowedOriginPattern("*"); // 来自哪个域名的请求,*号表示所有 + config.addAllowedHeader("*"); // 是什么请求头部 + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); + source.registerCorsConfiguration("/**", config); + return new CorsWebFilter(source); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java b/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java index f1027af..688e832 100644 --- a/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java +++ b/gateway/src/main/java/com/bonus/gateway/filter/AuthFilter.java @@ -1,5 +1,6 @@ package com.bonus.gateway.filter; +import com.bonus.gateway.config.AuthWriteUtils; import com.bonus.gateway.config.properties.IgnoreWhiteProperties; import com.bonus.common.core.constant.CacheConstants; import com.bonus.common.core.constant.HttpStatus; @@ -44,8 +45,18 @@ public class AuthFilter implements GlobalFilter, Ordered { ServerHttpRequest request = exchange.getRequest(); ServerHttpRequest.Builder mutate = request.mutate(); - String url = request.getURI().getPath(); + if (StringUtils.matches(url, AuthWriteUtils.getBlackUrl())) + { + if(url.contains(".")){ + String type=url.substring(url.lastIndexOf(".")+1).toLowerCase().trim(); + if(AuthWriteUtils.getWriteUrl().contains(type)){ + return chain.filter(exchange); + } + } + + } + // 跳过不需要验证的路径 if (StringUtils.matches(url, ignoreWhite.getWhites())) { diff --git a/modules/bmw/src/main/resources/bootstrap.yml b/modules/bmw/src/main/resources/bootstrap.yml index 2986207..643e6d4 100644 --- a/modules/bmw/src/main/resources/bootstrap.yml +++ b/modules/bmw/src/main/resources/bootstrap.yml @@ -13,8 +13,8 @@ server: buffered: true requestAttributesEnabled: true port: 1911 - servlet: - context-path: /bmw +# servlet: +# context-path: /bmw environment: @profiles.active@ diff --git a/modules/bmw/src/main/resources/static/js/main.js b/modules/bmw/src/main/resources/static/js/main.js index 3053712..1371a30 100644 --- a/modules/bmw/src/main/resources/static/js/main.js +++ b/modules/bmw/src/main/resources/static/js/main.js @@ -125,7 +125,7 @@ function logout() { $.ajax({ type: 'delete', - url: loginPath + '/logout', + url: DATA_URL + '/auth/logout', headers: { "Authorization": token }, diff --git a/modules/bmw/src/main/resources/static/js/publicJs.js b/modules/bmw/src/main/resources/static/js/publicJs.js index 684df03..1eb01e6 100644 --- a/modules/bmw/src/main/resources/static/js/publicJs.js +++ b/modules/bmw/src/main/resources/static/js/publicJs.js @@ -1,16 +1,19 @@ -var ctxPath = getContextPath(); +let DATA_URL="http://127.0.0.1:9100" + + +var ctxPath = "http://127.0.0.1:9100/bmw" var currentHostname = window.location.hostname; // //测试 // var loginPath = "http://" + currentHostname + ":9200"; // var systemPath = "http://" + currentHostname + ":1910"; -var loginPath = "http://" + currentHostname + ":1616/auth"; -var systemPath = "http://" + currentHostname + ":1616/system"; -var filePath = "http://" + currentHostname + ":1909/file"; -var fileUrl = "http://" + currentHostname + ":1909/file"; -var planUrl = "http://" + currentHostname + ":1918/ynPlan"; -var oiPlanUrl = "http://" + currentHostname + ":1914/oiPlan"; + +var systemPath = "http://" + currentHostname + ":9100/system"; +var filePath = "http://" + currentHostname + ":9100/file"; +var fileUrl = "http://" + currentHostname + ":9100/file"; +var planUrl = "http://" + currentHostname + ":9100/ynPlan"; +var oiPlanUrl = "http://" + currentHostname + ":9100/oiPlan"; //112.29.103.165:1616 //正式环境 diff --git a/modules/bmw/src/main/resources/static/login.html b/modules/bmw/src/main/resources/static/login.html index 1063385..7c60ecd 100644 --- a/modules/bmw/src/main/resources/static/login.html +++ b/modules/bmw/src/main/resources/static/login.html @@ -72,7 +72,7 @@ if (token != null && token.trim().length != 0) { $.ajax({ type : 'get', - url : ctxPath + '/users/current?token=' + token, + url : DATA_URL + '/users/current?token=' + token, success : function(data) { if(data != ''){ location.href = ctxPath + '/index.html'; @@ -107,7 +107,7 @@ $.ajax({ type : 'post', contentType : "application/json; charset=utf-8", - url : loginPath + '/login', + url : DATA_URL + '/auth/login', data : JSON.stringify({ // "username" : username, // "password" : password, @@ -209,7 +209,7 @@ time:5000 }); } - var url = loginPath+"/getTokenKey?jwtToken="+jwtToken; + var url = ctxPath+"/auth/getTokenKey?jwtToken="+jwtToken; $.ajax({ type : "GET", contentType: "application/json;charset=UTF-8",