Commit 87593270 by 刘宇峰

优化代码

1 parent bbe204dc
...@@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication; ...@@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.TimeZone; import java.util.TimeZone;
...@@ -16,8 +15,7 @@ import static java.util.TimeZone.getTimeZone; ...@@ -16,8 +15,7 @@ import static java.util.TimeZone.getTimeZone;
* @author payu * @author payu
*/ */
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.com.glsx.*.api"}) @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@SpringBootApplication(scanBasePackages = {"cn.com.glsx.*"}, exclude = DataSourceAutoConfiguration.class)
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
...@@ -29,4 +27,4 @@ public class Application { ...@@ -29,4 +27,4 @@ public class Application {
TimeZone.setDefault(getTimeZone(of("Asia/Shanghai"))); TimeZone.setDefault(getTimeZone(of("Asia/Shanghai")));
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -76,9 +76,6 @@ public class OpenApiAuthCheckFilter implements GlobalFilter, Ordered { ...@@ -76,9 +76,6 @@ public class OpenApiAuthCheckFilter implements GlobalFilter, Ordered {
return chain.filter(exchange); return chain.filter(exchange);
} }
//Jwt解码器
DecodedJWT decodedJWT = null;
//从请求头中取出Authorization //从请求头中取出Authorization
String accessToken = exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION); String accessToken = exchange.getRequest().getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
...@@ -122,16 +119,14 @@ public class OpenApiAuthCheckFilter implements GlobalFilter, Ordered { ...@@ -122,16 +119,14 @@ public class OpenApiAuthCheckFilter implements GlobalFilter, Ordered {
if (StringUtils.isNullOrEmpty(accessToken)) { if (StringUtils.isNullOrEmpty(accessToken)) {
return authFailedResponse(exchange, accessToken); return authFailedResponse(exchange, accessToken);
} }
//解码获取关键信息 //解码accessToken
try { DecodedJWT decodedJWT = gatewayJwtUtils.decode(accessToken);
decodedJWT = gatewayJwtUtils.decode(accessToken); if (Objects.isNull(decodedJWT)) {
} catch (Exception e) {
log.error("解码Token失败,{}", e.toString());
return authFailedResponse(exchange, accessToken); return authFailedResponse(exchange, accessToken);
} }
//验证accessToken //验证accessToken
DecodedJWT verifyJWT = verifyAccessToken(exchange, decodedJWT, accessToken); DecodedJWT verifyJWT = verifyAccessToken(exchange, decodedJWT, accessToken);
if (verifyJWT == null) { if (Objects.isNull(verifyJWT)) {
return authFailedResponse(exchange, accessToken); return authFailedResponse(exchange, accessToken);
} }
//封装新WebExchange //封装新WebExchange
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!