Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fzm-joying
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
lei
fzm-joying
Commits
13907747
Commit
13907747
authored
Aug 03, 2021
by
tangtuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改jwt登录过期的报错信息
parent
f0f2c7f3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
JwtUtil.java
...ng-common/src/main/java/com/fzm/common/utils/JwtUtil.java
+19
-1
No files found.
joying-common/src/main/java/com/fzm/common/utils/JwtUtil.java
View file @
13907747
...
...
@@ -7,6 +7,7 @@ import com.fzm.common.entity.AbstractUser;
import
com.fzm.common.enums.ResultCode
;
import
com.fzm.common.exception.GlobalException
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.ExpiredJwtException
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -53,8 +54,9 @@ public class JwtUtil {
.
setSigningKey
(
SECRET
)
.
parseClaimsJws
(
token
)
.
getBody
();
}
catch
(
ExpiredJwtException
e
)
{
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
"登录已过期"
);
}
catch
(
Exception
e
)
{
log
.
info
(
"JWT格式验证失败:{}"
,
token
);
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
e
.
getMessage
());
}
return
claims
;
...
...
@@ -197,4 +199,20 @@ public class JwtUtil {
return
false
;
}
public
static
void
main
(
String
[]
args
)
{
HashMap
<
String
,
Object
>
claims
=
new
HashMap
<>();
claims
.
put
(
CLAIM_KEY_CREATED
,
new
Date
(
System
.
currentTimeMillis
()
-
1000L
*
60
*
60
*
48
));
claims
.
put
(
CLAIM_KEY_APP_ID
,
"portal"
);
claims
.
put
(
CLAIM_KEY_USERID
,
1
);
String
token
=
Jwts
.
builder
()
.
setClaims
(
claims
)
.
setExpiration
(
new
Date
(
System
.
currentTimeMillis
()
-
1000L
*
60
*
60
*
24
))
.
signWith
(
SignatureAlgorithm
.
HS512
,
SECRET
)
.
compact
();
System
.
out
.
println
(
token
);
boolean
expired
=
isTokenExpired
(
token
);
System
.
out
.
println
(
expired
);
/*Integer userId = getUserIdFromToken("eyJhbGciOiJIUzUxMiJ9.eyJjcmVhdGVkIjoxNjI3ODAxMzIzMDE5LCJhcHBJZCI6InBvcnRhbCIsImV4cCI6MTYyNzg4NzcyMywidXNlcklkIjoxfQ.xch9RdpHupq64l3I2RvU09E2giCYfn2lfHmv1OYQhVpEVqe9NcjZ2mxcm4_2XapC1AHNGP6TRQI3BB3G4ZB-FA");
System.out.println(userId);*/
}
}
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