Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
V
volunteer_service
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
licc
volunteer_service
Commits
5e9fb667
Commit
5e9fb667
authored
Apr 11, 2021
by
xc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shiro限定并发登录人数
parent
040cf240
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
KickoutSessionControlFilter.java
...ergy/service/shir/filter/KickoutSessionControlFilter.java
+10
-7
No files found.
wisenergy-service/src/main/java/cn/wisenergy/service/shir/filter/KickoutSessionControlFilter.java
View file @
5e9fb667
...
...
@@ -71,10 +71,13 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
HttpServletRequest
httpServletRequest
=(
HttpServletRequest
)
request
;
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
response
;
// 登录超时
Integer
userId
=
getUserId
();
Object
object
=
SecurityUtils
.
getSubject
().
getPrincipal
();
Integer
userId
=
getUserId
(
object
);
Long
SessionTime
=
(
Long
)
redisTemplate
.
opsForValue
().
get
(
"shiroSessionTime:"
+
userId
);
log
.
info
(
"KickoutSessionControlFilter 账号id:{} 已登录时长:{} 秒"
,
userId
,(
new
Date
().
getTime
()-
SessionTime
)/
1000
);
if
((
new
Date
().
getTime
()-
SessionTime
)
>=
(
EXPIRE_TIME
*
1000
)){
Long
loginTime
=
new
Date
().
getTime
()-
SessionTime
;
Boolean
loginOutTime
=
(
new
Date
().
getTime
()-
SessionTime
)
>=
(
EXPIRE_TIME
*
1000
);
log
.
info
(
"KickoutSessionControlFilter 账号id:{} 已登录时长:{} 秒,是否超时:{}"
,
userId
,
loginTime
/
1000
,
loginOutTime
);
if
(
loginOutTime
){
log
.
info
(
"KickoutSessionControlFilter 登录已超时-----返回1003,账号id:{} 已登录时长:{} 分钟"
,
userId
,(
new
Date
().
getTime
()-
SessionTime
)/
1000
/
60
);
// 登录超时,抛出异常 Login timed out, please log in again
thrLogoutException
(
httpServletRequest
,
httpServletResponse
,
"1003"
,
"登录超时,请重新登录"
);
...
...
@@ -195,20 +198,20 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
}
}
private
Integer
getUserId
(){
private
Integer
getUserId
(
Object
object
){
Integer
userId
=
null
;
try
{
//客户端
User
user
=
(
User
)
SecurityUtils
.
getSubject
().
getPrincipal
()
;
User
user
=
(
User
)
object
;
userId
=
user
.
getId
();
}
catch
(
Exception
e
)
{
try
{
//管理端
AccountInfo
accountInfo
=
(
AccountInfo
)
SecurityUtils
.
getSubject
().
getPrincipal
()
;
AccountInfo
accountInfo
=
(
AccountInfo
)
object
;
userId
=
accountInfo
.
getId
();
}
catch
(
Exception
en
)
{
//员工端
Staff
staff
=
(
Staff
)
SecurityUtils
.
getSubject
().
getPrincipal
()
;
Staff
staff
=
(
Staff
)
object
;
userId
=
staff
.
getId
();
}
}
...
...
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