Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
bf541e87
Commit
bf541e87
authored
Aug 01, 2020
by
ZhengJie
Browse files
[代码完善](v2.5): 修复禁用用户后用户还可以操作的Bug
close
https://github.com/elunez/eladmin/issues/443
parent
fca64042
Changes
3
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/security/service/OnlineUserService.java
View file @
bf541e87
...
@@ -21,6 +21,7 @@ import me.zhengjie.modules.security.service.dto.JwtUserDto;
...
@@ -21,6 +21,7 @@ import me.zhengjie.modules.security.service.dto.JwtUserDto;
import
me.zhengjie.modules.security.service.dto.OnlineUserDto
;
import
me.zhengjie.modules.security.service.dto.OnlineUserDto
;
import
me.zhengjie.utils.*
;
import
me.zhengjie.utils.*
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -173,4 +174,17 @@ public class OnlineUserService {
...
@@ -173,4 +174,17 @@ public class OnlineUserService {
}
}
}
}
/**
* 根据用户名强退用户
* @param username /
*/
@Async
public
void
kickOutForUsername
(
String
username
)
{
List
<
OnlineUserDto
>
onlineUsers
=
getAll
(
username
);
for
(
OnlineUserDto
onlineUser
:
onlineUsers
)
{
if
(
onlineUser
.
getUserName
().
equals
(
username
))
{
kickOut
(
onlineUser
.
getKey
());
}
}
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java
View file @
bf541e87
...
@@ -24,6 +24,7 @@ import me.zhengjie.modules.system.service.DataService;
...
@@ -24,6 +24,7 @@ import me.zhengjie.modules.system.service.DataService;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.dto.UserDto
;
import
me.zhengjie.modules.system.service.dto.UserDto
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -72,7 +73,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
...
@@ -72,7 +73,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
throw
new
UsernameNotFoundException
(
""
);
throw
new
UsernameNotFoundException
(
""
);
}
else
{
}
else
{
if
(!
user
.
getEnabled
())
{
if
(!
user
.
getEnabled
())
{
throw
new
BadRequestException
(
"账号未激活"
);
throw
new
BadRequestException
(
"账号未激活
!
"
);
}
}
jwtUserDto
=
new
JwtUserDto
(
jwtUserDto
=
new
JwtUserDto
(
user
,
user
,
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
View file @
bf541e87
...
@@ -17,6 +17,7 @@ package me.zhengjie.modules.system.service.impl;
...
@@ -17,6 +17,7 @@ package me.zhengjie.modules.system.service.impl;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
me.zhengjie.config.FileProperties
;
import
me.zhengjie.config.FileProperties
;
import
me.zhengjie.modules.security.service.OnlineUserService
;
import
me.zhengjie.modules.security.service.UserCacheClean
;
import
me.zhengjie.modules.security.service.UserCacheClean
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.exception.EntityExistException
;
import
me.zhengjie.exception.EntityExistException
;
...
@@ -58,6 +59,7 @@ public class UserServiceImpl implements UserService {
...
@@ -58,6 +59,7 @@ public class UserServiceImpl implements UserService {
private
final
FileProperties
properties
;
private
final
FileProperties
properties
;
private
final
RedisUtils
redisUtils
;
private
final
RedisUtils
redisUtils
;
private
final
UserCacheClean
userCacheClean
;
private
final
UserCacheClean
userCacheClean
;
private
final
OnlineUserService
onlineUserService
;
@Override
@Override
public
Object
queryAll
(
UserQueryCriteria
criteria
,
Pageable
pageable
)
{
public
Object
queryAll
(
UserQueryCriteria
criteria
,
Pageable
pageable
)
{
...
@@ -117,6 +119,10 @@ public class UserServiceImpl implements UserService {
...
@@ -117,6 +119,10 @@ public class UserServiceImpl implements UserService {
if
(!
resources
.
getUsername
().
equals
(
user
.
getUsername
())){
if
(!
resources
.
getUsername
().
equals
(
user
.
getUsername
())){
redisUtils
.
del
(
"user::username:"
+
user
.
getUsername
());
redisUtils
.
del
(
"user::username:"
+
user
.
getUsername
());
}
}
// 如果用户被禁用,则清除用户登录信息
if
(!
resources
.
getEnabled
()){
onlineUserService
.
kickOutForUsername
(
resources
.
getUsername
());
}
user
.
setUsername
(
resources
.
getUsername
());
user
.
setUsername
(
resources
.
getUsername
());
user
.
setEmail
(
resources
.
getEmail
());
user
.
setEmail
(
resources
.
getEmail
());
user
.
setEnabled
(
resources
.
getEnabled
());
user
.
setEnabled
(
resources
.
getEnabled
());
...
...
Write
Preview
Supports
Markdown
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