Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
liyeyun-user-web
Project
Project
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
cfld-backend
liyeyun-user-web
Commits
15494106
Commit
15494106
authored
Dec 01, 2023
by
zhouxudong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
9202d753
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
3 deletions
+6
-3
CurrentUserInterceptor.java
...java/com/lyy/user/config/auth/CurrentUserInterceptor.java
+2
-2
WebConfig.java
src/main/java/com/lyy/user/config/auth/WebConfig.java
+1
-0
TokenConstants.java
src/main/java/com/lyy/user/constant/TokenConstants.java
+1
-0
JwtTokenUtil.java
src/main/java/com/lyy/user/util/jwt/JwtTokenUtil.java
+2
-1
No files found.
src/main/java/com/lyy/user/config/auth/CurrentUserInterceptor.java
View file @
15494106
...
...
@@ -24,14 +24,14 @@ public class CurrentUserInterceptor implements AsyncHandlerInterceptor {
// 从header中获取权限请求头
String
authToken
=
request
.
getHeader
(
Constants
.
TOKEN_HEADER
);
if
(
StringUtils
.
isBlank
(
authToken
)){
throw
new
ServiceException
(
"未授权,
登录失败
"
);
throw
new
ServiceException
(
"未授权,
请重新登录
"
);
}
String
token
=
authToken
.
substring
(
"Bearer"
.
length
()
+
1
).
trim
();
JwtInfo
jwtUser
=
JwtTokenUtil
.
getJwtUser
(
token
);
Object
redisToken
=
RedisUtil
.
get
(
RedisConstants
.
token
+
jwtUser
.
getPhone
());
if
(
ObjectUtils
.
isEmpty
(
redisToken
)){
throw
new
ServiceException
(
"请重新登录"
);
throw
new
ServiceException
(
"
当前会话失效,
请重新登录"
);
}
//判断是否续期
Long
expire
=
RedisUtil
.
getExpire
(
RedisConstants
.
token
+
jwtUser
.
getPhone
());
...
...
src/main/java/com/lyy/user/config/auth/WebConfig.java
View file @
15494106
...
...
@@ -59,6 +59,7 @@ public class WebConfig implements WebMvcConfigurer {
"/webjars/**"
,
"/v3/**"
,
"/v2/**"
,
"/error"
,
"/swagger**/**"
,
"/swagger-ui/index.html"
,
"/swagger-ui/index.html/**"
,
...
...
src/main/java/com/lyy/user/constant/TokenConstants.java
View file @
15494106
...
...
@@ -12,6 +12,7 @@ public class TokenConstants {
public
static
final
String
DETAILS
=
"details"
;
public
static
final
String
AUTHORITIES
=
"authorities"
;
public
static
final
String
EXPIRE_TIME
=
"expire_time"
;
public
static
final
String
CREATE_TIME
=
"create_time"
;
public
static
final
String
RESULT
=
"message"
;
public
static
final
String
SUCCESS
=
"success"
;
...
...
src/main/java/com/lyy/user/util/jwt/JwtTokenUtil.java
View file @
15494106
package
com
.
lyy
.
user
.
util
.
jwt
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.date.DateUtil
;
import
com.lyy.user.config.exception.ServiceException
;
import
com.lyy.user.constant.TokenConstants
;
import
com.lyy.user.domain.JwtInfo
;
...
...
@@ -43,7 +44,7 @@ public class JwtTokenUtil {
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
appendField
(
TokenConstants
.
DETAILS
,
jwtUser
);
jsonObject
.
appendField
(
TokenConstants
.
AUTHORITIES
,
authorities
);
jsonObject
.
appendField
(
TokenConstants
.
CREATE_TIME
,
System
.
currentTimeMillis
());
Payload
payload
=
new
Payload
(
jsonObject
);
JWSObject
jwsObject
=
new
JWSObject
(
jwsHeader
,
payload
);
JWSSigner
jwsSigner
;
...
...
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