Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yanxuan-wx-store-sharer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
wx
yanxuan-wx-store-sharer
Commits
d043ed08
Commit
d043ed08
authored
Mar 13, 2025
by
fanjiaxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
联调问题处理
parent
9e652ef7
Pipeline
#71570
passed with stages
in 1 minute 4 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
9 deletions
+48
-9
LoginUserHelper.java
...ase/yanxuan/wx/store/sharer/biz/core/LoginUserHelper.java
+12
-0
AuthInterceptor.java
...xuan/wx/store/sharer/biz/interceptor/AuthInterceptor.java
+19
-9
LoginRequired.java
...xuan/wx/store/sharer/common/annotation/LoginRequired.java
+17
-0
No files found.
yanxuan-wx-store-sharer-biz/src/main/java/com/netease/yanxuan/wx/store/sharer/biz/core/LoginUserHelper.java
View file @
d043ed08
...
...
@@ -36,4 +36,16 @@ public class LoginUserHelper {
redisClient
.
setStr
(
CoreConstant
.
REDIS_TOKEN_USER_KEY
+
token
,
JSON
.
toJSONString
(
loginUserInfo
),
CoreConstant
.
REDIS_TOKEN_EXPIRE_SECONDS
);
}
/**
* 保存用户认证信息
*/
public
void
setLoginUserInfo
(
String
token
)
{
LoginUserInfo
loginUserInfo
=
getLoginUserInfo
(
token
);
if
(
null
!=
loginUserInfo
)
{
LoginUserContextHolder
.
set
(
loginUserInfo
);
redisClient
.
setStr
(
CoreConstant
.
REDIS_TOKEN_USER_KEY
+
token
,
JSON
.
toJSONString
(
loginUserInfo
),
CoreConstant
.
REDIS_TOKEN_EXPIRE_SECONDS
);
}
}
}
yanxuan-wx-store-sharer-biz/src/main/java/com/netease/yanxuan/wx/store/sharer/biz/interceptor/AuthInterceptor.java
View file @
d043ed08
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
biz
.
interceptor
;
import
com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo
;
import
com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserContextHolder
;
import
com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserHelper
;
import
com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo
;
import
com.netease.yanxuan.wx.store.sharer.common.annotation.LoginRequired
;
import
com.netease.yanxuan.wx.store.sharer.common.constant.CoreConstant
;
import
com.netease.yanxuan.wx.store.sharer.common.exception.NoAuthException
;
import
com.netease.yanxuan.wx.store.sharer.common.handler.RedisClient
;
...
...
@@ -10,10 +11,12 @@ import lombok.RequiredArgsConstructor;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.Method
;
/**
* @Description 鉴权拦截器
...
...
@@ -31,17 +34,24 @@ public class AuthInterceptor implements HandlerInterceptor {
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
log
.
info
(
"AuthInterceptor preHandle execute, url:{}"
,
request
.
getRequestURI
());
HandlerMethod
handlerMethod
=
(
HandlerMethod
)
handler
;
Method
method
=
handlerMethod
.
getMethod
();
LoginRequired
clientMethodAnnotation
=
method
.
getAnnotation
(
LoginRequired
.
class
);
String
token
=
request
.
getHeader
(
CoreConstant
.
AUTH_HEADER_TOKEN_KEY
);
if
(
StringUtils
.
isEmpty
(
token
))
{
throw
new
NoAuthException
(
"用户认证失败,TOKEN为空"
);
if
(
clientMethodAnnotation
!=
null
)
{
if
(
StringUtils
.
isEmpty
(
token
))
{
throw
new
NoAuthException
(
"用户认证失败,TOKEN为空"
);
}
LoginUserInfo
loginUserInfo
=
jwtHelper
.
getLoginUserInfo
(
token
);
if
(
null
==
loginUserInfo
)
{
log
.
info
(
"用户登录状态过期,token缓存失效,path:{}"
,
request
.
getServletPath
());
throw
new
NoAuthException
(
"用户登录状态过期"
);
}
}
LoginUserInfo
loginUserInfo
=
jwtHelper
.
getLoginUserInfo
(
token
);
if
(
null
==
loginUserInfo
)
{
log
.
info
(
"用户登录状态过期,token缓存失效,path:{}"
,
request
.
getServletPath
());
throw
new
NoAuthException
(
"用户登录状态过期"
);
if
(
StringUtils
.
isNotBlank
(
token
)){
// 刷新缓存
jwtHelper
.
setLoginUserInfo
(
token
);
}
// 刷新缓存
jwtHelper
.
setLoginUserInfo
(
token
,
loginUserInfo
);
return
true
;
}
...
...
yanxuan-wx-store-sharer-common/src/main/java/com/netease/yanxuan/wx/store/sharer/common/annotation/LoginRequired.java
0 → 100644
View file @
d043ed08
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
common
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* des: 登录注解
* 限制只有登录才能访问的接口加此注解
* @author :XDD
* @ date : 2020/9/11 14:09
*/
@Target
({
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
LoginRequired
{
}
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