Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-gateway
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 87593270
authored
May 05, 2023
by
刘宇峰
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化代码
1 parent
bbe204dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
13 deletions
src/main/java/cn/com/glsx/Application.java
src/main/java/cn/com/glsx/gateway/filter/OpenApiAuthCheckFilter.java
src/main/java/cn/com/glsx/Application.java
View file @
8759327
...
@@ -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
src/main/java/cn/com/glsx/gateway/filter/OpenApiAuthCheckFilter.java
View file @
8759327
...
@@ -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
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment