Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
hphy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
向怀芳
hphy
Commits
adad9945
Commit
adad9945
authored
Sep 11, 2023
by
gaozhaochen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update: ws问诊接口添加token权限校验
parent
8da2e797
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
GptServerFilter.java
...stc/sict/cloud/common/gateway/filter/GptServerFilter.java
+18
-14
No files found.
cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/GptServerFilter.java
View file @
adad9945
package
cn
.
sh
.
stc
.
sict
.
cloud
.
common
.
gateway
.
filter
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.sh.stc.sict.cloud.common.core.util.R
;
import
cn.sh.stc.sict.cloud.common.gateway.feign.RemoteAuthService
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.cloud.gateway.filter.GatewayFilter
;
import
org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
...
...
@@ -24,14 +23,14 @@ public class GptServerFilter extends AbstractGatewayFilterFactory {
public
final
RemoteAuthService
remoteAuthService
;
public
static
final
String
SEC_WEBSOCKET_PROTOCOL
=
"Sec-WebSocket-Protocol
"
;
public
static
final
String
WEB_TOKEN
=
"ws-token
"
;
@Override
public
GatewayFilter
apply
(
Object
config
)
{
return
(
exchange
,
chain
)
->
{
ServerHttpRequest
request
=
exchange
.
getRequest
();
String
token
=
request
.
get
Headers
().
getFirst
(
SEC_WEBSOCKET_PROTOCOL
);
log
.
info
(
"ws-token
{}"
,
token
);
String
token
=
request
.
get
QueryParams
().
getFirst
(
WEB_TOKEN
);
log
.
error
(
"ws-token =
{}"
,
token
);
// 权限校验
if
(
checkToken
(
token
))
{
return
chain
.
filter
(
exchange
);
...
...
@@ -48,15 +47,20 @@ public class GptServerFilter extends AbstractGatewayFilterFactory {
* @return
*/
private
boolean
checkToken
(
String
token
)
{
// if (StringUtils.isEmpty(token)) {
// return false;
// }
return
true
;
// R<Boolean> valid = remoteAuthService.isValid(token);
// if (ObjectUtil.isNull(valid) || ObjectUtil.isNull(valid.getData())) {
// return false;
// }
// return valid.getData();
try
{
if
(
StrUtil
.
isBlank
(
token
))
{
return
false
;
}
R
<
Boolean
>
valid
=
remoteAuthService
.
isValid
(
token
);
if
(
ObjectUtil
.
isNull
(
valid
)
||
ObjectUtil
.
isNull
(
valid
.
getData
()))
{
return
false
;
}
return
valid
.
getData
();
}
catch
(
Exception
e
)
{
log
.
error
(
"权限校验失败"
,
e
);
return
false
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment