|
|
@@ -18,14 +18,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.buffer.DataBuffer;
|
|
|
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
|
|
-import org.springframework.http.HttpCookie;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.http.server.RequestPath;
|
|
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.cors.reactive.CorsUtils;
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
import org.springframework.web.server.WebFilter;
|
|
|
import org.springframework.web.server.WebFilterChain;
|
|
|
@@ -51,7 +50,24 @@ public class LoginWebFiter implements WebFilter {
|
|
|
@Override
|
|
|
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
|
|
ServerHttpRequest request = exchange.getRequest();
|
|
|
+ ServerHttpResponse response = exchange.getResponse();
|
|
|
RequestPath path = request.getPath();
|
|
|
+ //.跨域
|
|
|
+ if (CorsUtils.isCorsRequest(request)) {
|
|
|
+ HttpHeaders headers = response.getHeaders();
|
|
|
+ //解决跨域的问题
|
|
|
+ headers.add("Access-Control-Allow-Origin", "*");
|
|
|
+ headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
|
+ headers.add("Access-Control-Allow-Headers", "*");
|
|
|
+ headers.add("Access-Control-Max-Age", "3600");
|
|
|
+ headers.add("Access-Control-Allow-Credentials", "false");
|
|
|
+ }
|
|
|
+ //预检请求
|
|
|
+ if (request.getMethod().equals(HttpMethod.OPTIONS.name())) {
|
|
|
+ response.setStatusCode(HttpStatus.OK);
|
|
|
+ return response.setComplete();
|
|
|
+ }
|
|
|
+
|
|
|
String string = path.toString();
|
|
|
String[] split = xxlSsoExcludedPaths.split(",");
|
|
|
String[] split1 = xxlSsoExcludedstart.split(",");
|
|
|
@@ -110,7 +126,6 @@ public class LoginWebFiter implements WebFilter {
|
|
|
|
|
|
public Boolean getUser(String cookie) throws IOException {
|
|
|
if (Objects.isNull(cookie)) {
|
|
|
- log.error("111111111");
|
|
|
return false;
|
|
|
}
|
|
|
if(UserContext.cMap.containsKey(cookie)){
|
|
|
@@ -128,14 +143,10 @@ public class LoginWebFiter implements WebFilter {
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
String result = EntityUtils.toString(entity);
|
|
|
EntityUtils.consume(entity);
|
|
|
- log.error("3");
|
|
|
if (Objects.nonNull(result)) {
|
|
|
- log.error("4");
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(result);
|
|
|
if (jsonObject.containsKey("code") && jsonObject.get("code", Integer.class) == 200) {
|
|
|
- log.error("5");
|
|
|
if(jsonObject.containsKey("data")){
|
|
|
- log.error("7");
|
|
|
XxlSsoUser data = jsonObject.get("data", XxlSsoUser.class);
|
|
|
BaseContextHandler.setUserId(data.getUserid());
|
|
|
BaseContextHandler.setUserName(data.getUsername());
|
|
|
@@ -144,19 +155,16 @@ public class LoginWebFiter implements WebFilter {
|
|
|
return true;
|
|
|
}
|
|
|
}else if(jsonObject.containsKey("code") && jsonObject.get("code", Integer.class) == 501){
|
|
|
- log.error("7.1");
|
|
|
return false;
|
|
|
}else {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- log.error("8");
|
|
|
} catch (Exception e) {
|
|
|
return true;
|
|
|
} finally {
|
|
|
response.close();
|
|
|
}
|
|
|
- log.error("2222222222222");
|
|
|
return true;
|
|
|
|
|
|
}
|