Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
涂亚平
/
subsidy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9347a3c5
authored
Mar 22, 2022
by
邓敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
单设备登录
1 parent
b1448565
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletions
src/main/java/com/subsidy/common/configure/WebConfig.java
src/main/java/com/subsidy/common/interceptor/AuthenticationInterceptor.java
src/main/java/com/subsidy/common/configure/WebConfig.java
View file @
9347a3c
package
com
.
subsidy
.
common
.
configure
;
package
com
.
subsidy
.
common
.
configure
;
import
com.subsidy.common.interceptor.AuthenticationInterceptor
;
import
com.subsidy.common.interceptor.AuthenticationInterceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
...
@@ -59,5 +64,15 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -59,5 +64,15 @@ public class WebConfig implements WebMvcConfigurer {
.
addPathPatterns
(
"/**"
);
.
addPathPatterns
(
"/**"
);
}
}
@Bean
public
CorsFilter
corsFilter
()
{
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
setMaxAge
(
3600L
);
config
.
addAllowedOrigin
(
"*"
);
config
.
addAllowedMethod
(
"*"
);
config
.
addAllowedHeader
(
"*"
);
UrlBasedCorsConfigurationSource
configSource
=
new
UrlBasedCorsConfigurationSource
();
configSource
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
configSource
);
}
}
}
\ No newline at end of file
src/main/java/com/subsidy/common/interceptor/AuthenticationInterceptor.java
View file @
9347a3c
package
com
.
subsidy
.
common
.
interceptor
;
package
com
.
subsidy
.
common
.
interceptor
;
import
com.alibaba.fastjson.JSON
;
import
com.auth0.jwt.interfaces.Claim
;
import
com.auth0.jwt.interfaces.Claim
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.subsidy.common.ResponseData
;
import
com.subsidy.common.ResponseData
;
...
@@ -13,7 +14,9 @@ import com.subsidy.util.JwtUtil;
...
@@ -13,7 +14,9 @@ import com.subsidy.util.JwtUtil;
import
com.subsidy.util.Localstorage
;
import
com.subsidy.util.Localstorage
;
import
com.subsidy.util.RedisUtil
;
import
com.subsidy.util.RedisUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.HandlerInterceptor
;
...
@@ -43,6 +46,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
...
@@ -43,6 +46,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
private
RedisUtil
redisUtil
;
private
RedisUtil
redisUtil
;
@Override
@Override
@CrossOrigin
()
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
// 不需要进行拦截
// 不需要进行拦截
if
(!(
handler
instanceof
HandlerMethod
))
{
if
(!(
handler
instanceof
HandlerMethod
))
{
...
@@ -83,6 +87,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
...
@@ -83,6 +87,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
if
(
tk
.
equals
(
token
))
{
if
(
tk
.
equals
(
token
))
{
return
true
;
return
true
;
}
}
throw
new
HttpException
(
1011
);
throw
new
HttpException
(
1011
);
}
else
{
}
else
{
throw
new
HttpException
(
1010
);
throw
new
HttpException
(
1010
);
...
...
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