Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
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
zengtianlai3
ioc_sixiang_license
Commits
104db084
Commit
104db084
authored
Aug 04, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决注销会话标识未失效
parent
3b9ea1aa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
5 deletions
+39
-5
LoginController.java
.../java/iot/sixiang/license/controller/LoginController.java
+4
-0
JwtFilter.java
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
+10
-5
UserUtils.java
license/src/main/java/iot/sixiang/license/jwt/UserUtils.java
+25
-0
No files found.
license/src/main/java/iot/sixiang/license/controller/LoginController.java
View file @
104db084
...
@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiImplicitParams;
...
@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiImplicitParams;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.jwt.JwtUtil
;
import
iot.sixiang.license.jwt.JwtUtil
;
import
iot.sixiang.license.jwt.LoginUser
;
import
iot.sixiang.license.jwt.LoginUser
;
import
iot.sixiang.license.jwt.UserUtils
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.MyLog
;
import
iot.sixiang.license.log.MyLog
;
import
iot.sixiang.license.model.BaseResult
;
import
iot.sixiang.license.model.BaseResult
;
...
@@ -53,6 +54,7 @@ public class LoginController {
...
@@ -53,6 +54,7 @@ public class LoginController {
String
token
=
JwtUtil
.
createToken
(
dbUser
);
String
token
=
JwtUtil
.
createToken
(
dbUser
);
LoginVo
loginVo
=
new
LoginVo
();
LoginVo
loginVo
=
new
LoginVo
();
loginVo
.
setAuthorization
(
token
);
loginVo
.
setAuthorization
(
token
);
UserUtils
.
setToken
(
dbUser
.
getUserId
(),
token
);
return
ResResult
.
success
().
goRecord
(
loginVo
);
return
ResResult
.
success
().
goRecord
(
loginVo
);
}
}
}
}
...
@@ -63,6 +65,8 @@ public class LoginController {
...
@@ -63,6 +65,8 @@ public class LoginController {
@GetMapping
(
"logout"
)
@GetMapping
(
"logout"
)
@MyLog
(
title
=
"注销"
,
businessType
=
BusinessType
.
OTHER
)
@MyLog
(
title
=
"注销"
,
businessType
=
BusinessType
.
OTHER
)
public
BaseResult
logout
()
{
public
BaseResult
logout
()
{
String
loginUserId
=
UserUtils
.
getLoginUserId
();
UserUtils
.
removeToken
(
loginUserId
);
return
BaseResult
.
success
();
return
BaseResult
.
success
();
}
}
...
...
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
View file @
104db084
...
@@ -4,6 +4,7 @@ import com.auth0.jwt.interfaces.Claim;
...
@@ -4,6 +4,7 @@ import com.auth0.jwt.interfaces.Claim;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
com.auth0.jwt.interfaces.DecodedJWT
;
import
iot.sixiang.license.xss.XssUtil
;
import
iot.sixiang.license.xss.XssUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.StringUtils
;
import
javax.servlet.*
;
import
javax.servlet.*
;
import
javax.servlet.annotation.WebFilter
;
import
javax.servlet.annotation.WebFilter
;
...
@@ -54,7 +55,7 @@ public class JwtFilter implements Filter {
...
@@ -54,7 +55,7 @@ public class JwtFilter implements Filter {
return
;
return
;
}
}
if
(
token
==
null
)
{
if
(
StringUtils
.
isEmpty
(
token
)
)
{
request
.
setAttribute
(
"msg"
,
"认证信息不能为空"
);
request
.
setAttribute
(
"msg"
,
"认证信息不能为空"
);
request
.
getRequestDispatcher
(
"/fail"
).
forward
(
request
,
response
);
request
.
getRequestDispatcher
(
"/fail"
).
forward
(
request
,
response
);
return
;
return
;
...
@@ -74,11 +75,15 @@ public class JwtFilter implements Filter {
...
@@ -74,11 +75,15 @@ public class JwtFilter implements Filter {
String
userId
=
userData
.
get
(
"userId"
).
asString
();
String
userId
=
userData
.
get
(
"userId"
).
asString
();
String
userName
=
userData
.
get
(
"userName"
).
asString
();
String
userName
=
userData
.
get
(
"userName"
).
asString
();
String
password
=
userData
.
get
(
"password"
).
asString
();
String
password
=
userData
.
get
(
"password"
).
asString
();
LoginUser
loginUser
=
new
LoginUser
(
userId
,
userName
,
password
);
LoginUser
loginUser
=
new
LoginUser
(
userId
,
userName
,
password
);
if
(
token
.
equals
(
UserUtils
.
getToken
(
userId
)))
{
UserUtils
.
setLoginUser
(
loginUser
);
UserUtils
.
setLoginUser
(
loginUser
);
UserUtils
.
setUri
(
uri
);
UserUtils
.
setUri
(
uri
);
filterChain
.
doFilter
(
request
,
response
);
filterChain
.
doFilter
(
request
,
response
);
}
else
{
request
.
setAttribute
(
"msg"
,
"token已失效"
);
request
.
getRequestDispatcher
(
"/fail"
).
forward
(
request
,
response
);
}
}
}
}
}
}
}
...
...
license/src/main/java/iot/sixiang/license/jwt/UserUtils.java
View file @
104db084
package
iot
.
sixiang
.
license
.
jwt
;
package
iot
.
sixiang
.
license
.
jwt
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* 存储/获取当前线程的用户信息工具类
* 存储/获取当前线程的用户信息工具类
*/
*/
public
abstract
class
UserUtils
{
public
abstract
class
UserUtils
{
static
Map
<
String
,
String
>
tokenMap
=
new
HashMap
<>();
//线程变量,存放user实体类信息,即使是静态的与其他线程也是隔离的
//线程变量,存放user实体类信息,即使是静态的与其他线程也是隔离的
private
static
ThreadLocal
<
LoginUser
>
userThreadLocal
=
new
ThreadLocal
<>();
private
static
ThreadLocal
<
LoginUser
>
userThreadLocal
=
new
ThreadLocal
<>();
//线程变量,存放uri,即使是静态的与其他线程也是隔离的
//线程变量,存放uri,即使是静态的与其他线程也是隔离的
...
@@ -36,6 +40,27 @@ public abstract class UserUtils {
...
@@ -36,6 +40,27 @@ public abstract class UserUtils {
userThreadLocal
.
set
(
user
);
userThreadLocal
.
set
(
user
);
}
}
//为当前的线程变量赋值上token信息
public
static
void
setToken
(
String
uId
,
String
token
)
{
tokenMap
.
put
(
uId
,
token
);
}
/**
* 获取当前访问方法的token
* @return
*/
public
static
String
getToken
(
String
uId
)
{
System
.
out
.
println
(
"---"
);
String
s
=
tokenMap
.
get
(
uId
);
System
.
out
.
println
(
s
);
return
tokenMap
.
get
(
uId
);
}
//清除tokenThreadLocal线程变量
public
static
void
removeToken
(
String
uId
)
{
tokenMap
.
remove
(
uId
);
}
//清除userThreadLocal线程变量
//清除userThreadLocal线程变量
public
static
void
removeUser
()
{
public
static
void
removeUser
()
{
userThreadLocal
.
remove
();
userThreadLocal
.
remove
();
...
...
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