Commit 60984d86 by levphon

网关服务放开api接口登录验证

1 parent f96094d7
package com.glsx.plat.gateway.filter; package com.glsx.plat.gateway.filter;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.auth0.jwt.interfaces.DecodedJWT; import com.auth0.jwt.interfaces.DecodedJWT;
import com.glsx.plat.common.utils.StringUtils; import com.glsx.plat.common.utils.StringUtils;
...@@ -10,6 +9,7 @@ import com.glsx.plat.jwt.base.ComJwtUser; ...@@ -10,6 +9,7 @@ import com.glsx.plat.jwt.base.ComJwtUser;
import com.glsx.plat.jwt.config.JwtConfigProperties; import com.glsx.plat.jwt.config.JwtConfigProperties;
import com.glsx.plat.jwt.util.JwtUtils; import com.glsx.plat.jwt.util.JwtUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
...@@ -29,7 +29,9 @@ import reactor.core.publisher.Flux; ...@@ -29,7 +29,9 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
* @author payu * @author payu
...@@ -64,6 +66,15 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered { ...@@ -64,6 +66,15 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
return chain.filter(exchange); return chain.filter(exchange);
} }
//api接口不需要验证
String[] urlPaths = url.split("/");
if (!CollectionUtils.sizeIsEmpty(urlPaths)) {
List<String> list = new ArrayList<>(Arrays.asList(urlPaths));
if (list.contains("api") || list.contains("API")) {
return chain.filter(exchange);
}
}
//从请求头中取出token //从请求头中取出token
String token = exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION); String token = exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
//log.info("url {} \ntoken {} \nheaders {}", url, token, JSONUtil.toJsonStr(exchange.getRequest().getHeaders())); //log.info("url {} \ntoken {} \nheaders {}", url, token, JSONUtil.toJsonStr(exchange.getRequest().getHeaders()));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!