Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
b9bd798e
Commit
b9bd798e
authored
Oct 09, 2024
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交配置校验
parent
fd103eb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletion
+23
-1
base-manager/src/main/java/com/mortals/xhx/base/framework/interceptor/AuthUserInterceptor.java
...s/xhx/base/framework/interceptor/AuthUserInterceptor.java
+23
-1
No files found.
base-manager/src/main/java/com/mortals/xhx/base/framework/interceptor/AuthUserInterceptor.java
View file @
b9bd798e
package
com.mortals.xhx.base.framework.interceptor
;
package
com.mortals.xhx.base.framework.interceptor
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.http.HttpStatus
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.common.Rest
;
...
@@ -11,6 +13,7 @@ import com.mortals.framework.web.interceptor.BaseInterceptor;
...
@@ -11,6 +13,7 @@ import com.mortals.framework.web.interceptor.BaseInterceptor;
import
com.mortals.xhx.base.framework.config.InterceptorConfig
;
import
com.mortals.xhx.base.framework.config.InterceptorConfig
;
import
com.mortals.xhx.common.code.ApiRespCodeEnum
;
import
com.mortals.xhx.common.code.ApiRespCodeEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.method.HandlerMethod
;
...
@@ -19,6 +22,7 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
...
@@ -19,6 +22,7 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.*;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.*;
...
@@ -35,6 +39,9 @@ public class AuthUserInterceptor extends BaseInterceptor {
...
@@ -35,6 +39,9 @@ public class AuthUserInterceptor extends BaseInterceptor {
@Autowired
@Autowired
private
IAuthTokenService
authTokenService
;
private
IAuthTokenService
authTokenService
;
@Value
(
"${trustedReferer:''}"
)
private
String
trustedReferer
;
@Override
@Override
public
int
getOrder
()
{
public
int
getOrder
()
{
return
Integer
.
MAX_VALUE
-
9
;
return
Integer
.
MAX_VALUE
-
9
;
...
@@ -44,6 +51,21 @@ public class AuthUserInterceptor extends BaseInterceptor {
...
@@ -44,6 +51,21 @@ public class AuthUserInterceptor extends BaseInterceptor {
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
throws
Exception
{
//response.setContentType("application/json");
//response.setContentType("application/json");
String
referer
=
request
.
getHeader
(
"Referer"
);
if
(!
ObjectUtils
.
isEmpty
(
referer
))
{
referer
=
StrUtil
.
removeSuffix
(
referer
,
"/"
);
List
<
String
>
trustReferers
=
StrUtil
.
split
(
trustedReferer
,
","
);
if
(!
ObjectUtils
.
isEmpty
(
trustReferers
))
{
if
(!
trustReferers
.
contains
(
referer
))
{
response
.
setStatus
(
HttpStatus
.
HTTP_BAD_REQUEST
);
return
false
;
}
}
}
if
(
handler
instanceof
HandlerMethod
)
{
if
(
handler
instanceof
HandlerMethod
)
{
HandlerMethod
handlerMethod
=
(
HandlerMethod
)
handler
;
HandlerMethod
handlerMethod
=
(
HandlerMethod
)
handler
;
Method
method
=
handlerMethod
.
getMethod
();
Method
method
=
handlerMethod
.
getMethod
();
...
@@ -64,7 +86,7 @@ public class AuthUserInterceptor extends BaseInterceptor {
...
@@ -64,7 +86,7 @@ public class AuthUserInterceptor extends BaseInterceptor {
if
(!
auth
)
{
if
(!
auth
)
{
//校验token不正常
//校验token不正常
String
token
=
authTokenService
.
getToken
(
request
);
String
token
=
authTokenService
.
getToken
(
request
);
if
(
ObjectUtils
.
isEmpty
(
token
))
{
if
(
ObjectUtils
.
isEmpty
(
token
))
{
ServletUtils
.
renderString
(
response
,
JSONObject
.
toJSONString
(
Rest
.
fail
(
ERROR_TOKEN_UNAUTHORIZED
,
ERROR_TOKEN_UNAUTHORIZED_CONTENT
)));
ServletUtils
.
renderString
(
response
,
JSONObject
.
toJSONString
(
Rest
.
fail
(
ERROR_TOKEN_UNAUTHORIZED
,
ERROR_TOKEN_UNAUTHORIZED_CONTENT
)));
return
false
;
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