Commit 87593270 by 刘宇峰

优化代码

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