|
@@ -50,6 +50,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -136,6 +137,22 @@ public class LoginController {
|
|
|
|
|
|
//登录成功,生成token
|
|
//登录成功,生成token
|
|
UserDTO userDTO = userApi.getByLoginName ( username, tenantApi.getCurrentTenantId ( ) );
|
|
UserDTO userDTO = userApi.getByLoginName ( username, tenantApi.getCurrentTenantId ( ) );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if("樊莉".equals(userDTO.getName())){
|
|
|
|
+
|
|
|
|
+ List<UserDTO> onLineUserList = SpringUtil.getBean(IUserApi.class).getOnLineUserList("黄玮", "10002");
|
|
|
|
+ if(!onLineUserList.isEmpty()){
|
|
|
|
+ throw new DisabledException ( "当前黄玮已登录系统," + ErrorConstants.LOGIN_ERROR );
|
|
|
|
+ }
|
|
|
|
+ }else if("黄玮".equals(userDTO.getName())){
|
|
|
|
+ List<UserDTO> onLineUserList = SpringUtil.getBean(IUserApi.class).getOnLineUserList("樊莉", "10002");
|
|
|
|
+ if(!onLineUserList.isEmpty()){
|
|
|
|
+ throw new DisabledException ( "当前樊莉已登录系统," + ErrorConstants.LOGIN_ERROR );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
String token = TokenProvider.createAccessToken ( username );
|
|
String token = TokenProvider.createAccessToken ( username );
|
|
responseUtil.add ( TokenProvider.TOKEN, token );
|
|
responseUtil.add ( TokenProvider.TOKEN, token );
|
|
//更新登录信息
|
|
//更新登录信息
|
|
@@ -273,6 +290,7 @@ public class LoginController {
|
|
@GetMapping("/logout")
|
|
@GetMapping("/logout")
|
|
public ResponseEntity logout(HttpServletRequest request, HttpServletResponse response) {
|
|
public ResponseEntity logout(HttpServletRequest request, HttpServletResponse response) {
|
|
Authentication auth = SecurityUtils.getAuthentication ( );
|
|
Authentication auth = SecurityUtils.getAuthentication ( );
|
|
|
|
+ UserDTO currentUserDTO = SecurityUtils.getCurrentUserDTO();
|
|
if ( auth != null ) {
|
|
if ( auth != null ) {
|
|
userApi.clearCache ( SecurityUtils.getCurrentUserDTO ( ) );
|
|
userApi.clearCache ( SecurityUtils.getCurrentUserDTO ( ) );
|
|
String token = TokenProvider.resolveToken ( request );
|
|
String token = TokenProvider.resolveToken ( request );
|
|
@@ -280,6 +298,13 @@ public class LoginController {
|
|
redisUtils.delete ( CacheNames.USER_CACHE_ONLINE_USERS, token );
|
|
redisUtils.delete ( CacheNames.USER_CACHE_ONLINE_USERS, token );
|
|
new SecurityContextLogoutHandler ( ).logout ( request, response, auth );
|
|
new SecurityContextLogoutHandler ( ).logout ( request, response, auth );
|
|
}
|
|
}
|
|
|
|
+ //查询系统中是否存在相同登录名的其他登录信息。若存在,则将其他信息同时进行下线处理
|
|
|
|
+ List<UserDTO> onLineUserList = SpringUtil.getBean(IUserApi.class).getOnLineUserList(currentUserDTO.getLoginName(), "");
|
|
|
|
+ for (UserDTO userDTO : onLineUserList) {
|
|
|
|
+ userApi.clearCache ( userDTO );
|
|
|
|
+ redisUtils.delete ( CacheNames.USER_CACHE_TOKEN, userDTO.getToken() );
|
|
|
|
+ redisUtils.delete ( CacheNames.USER_CACHE_ONLINE_USERS, userDTO.getToken() );
|
|
|
|
+ }
|
|
return ResponseEntity.ok ( "退出成功" );
|
|
return ResponseEntity.ok ( "退出成功" );
|
|
}
|
|
}
|
|
|
|
|