|
@@ -1,8 +1,10 @@
|
|
package com.lantone.security.facade;
|
|
package com.lantone.security.facade;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.crypto.digest.BCrypt;
|
|
import cn.hutool.crypto.digest.BCrypt;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.auth0.jwt.interfaces.Claim;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -16,7 +18,9 @@ import com.lantone.common.dto.GetUserDTO;
|
|
import com.lantone.common.dto.GetUserHospitalDeptDTO;
|
|
import com.lantone.common.dto.GetUserHospitalDeptDTO;
|
|
import com.lantone.common.dto.GetUserHospitalsDTO;
|
|
import com.lantone.common.dto.GetUserHospitalsDTO;
|
|
import com.lantone.common.dto.GetUserPageDTO;
|
|
import com.lantone.common.dto.GetUserPageDTO;
|
|
|
|
+import com.lantone.common.dto.JwtStore;
|
|
import com.lantone.common.dto.LoginLogDTO;
|
|
import com.lantone.common.dto.LoginLogDTO;
|
|
|
|
+import com.lantone.common.dto.SendToTopicDTO;
|
|
import com.lantone.common.dto.SoftwareDTO;
|
|
import com.lantone.common.dto.SoftwareDTO;
|
|
import com.lantone.common.dto.UserInfoDTO;
|
|
import com.lantone.common.dto.UserInfoDTO;
|
|
import com.lantone.common.dto.UserRoleDTO;
|
|
import com.lantone.common.dto.UserRoleDTO;
|
|
@@ -25,6 +29,8 @@ import com.lantone.common.enums.DataAuthDataTypeEnum;
|
|
import com.lantone.common.enums.IsDeleteEnum;
|
|
import com.lantone.common.enums.IsDeleteEnum;
|
|
import com.lantone.common.enums.StatusEnum;
|
|
import com.lantone.common.enums.StatusEnum;
|
|
import com.lantone.common.exception.Asserts;
|
|
import com.lantone.common.exception.Asserts;
|
|
|
|
+import com.lantone.common.service.RedisService;
|
|
|
|
+import com.lantone.common.service.SysTokenService;
|
|
import com.lantone.common.util.DateUtil;
|
|
import com.lantone.common.util.DateUtil;
|
|
import com.lantone.common.util.EntityUtil;
|
|
import com.lantone.common.util.EntityUtil;
|
|
import com.lantone.common.util.HttpUtils;
|
|
import com.lantone.common.util.HttpUtils;
|
|
@@ -110,6 +116,10 @@ public class UserManagementFacade {
|
|
private DictionaryInfoFacade dictionaryInfoFacade;
|
|
private DictionaryInfoFacade dictionaryInfoFacade;
|
|
@Autowired
|
|
@Autowired
|
|
private MessageService messageService;
|
|
private MessageService messageService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisService redisService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysTokenService sysTokenService;
|
|
|
|
|
|
public CommonResult login(LoginVO loginVO) {
|
|
public CommonResult login(LoginVO loginVO) {
|
|
Map<String, String> params = new HashMap<>();
|
|
Map<String, String> params = new HashMap<>();
|
|
@@ -119,10 +129,40 @@ public class UserManagementFacade {
|
|
params.put("username", loginVO.getUsername());
|
|
params.put("username", loginVO.getUsername());
|
|
params.put("password", loginVO.getPassword());
|
|
params.put("password", loginVO.getPassword());
|
|
CommonResult restResult = authService.getAccessToken(params);
|
|
CommonResult restResult = authService.getAccessToken(params);
|
|
|
|
+ userLoginCheck(restResult);
|
|
sendLogRecordMessage(restResult);
|
|
sendLogRecordMessage(restResult);
|
|
return restResult;
|
|
return restResult;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void userLoginCheck(CommonResult restResult) {
|
|
|
|
+ if (restResult.getData() != null) {
|
|
|
|
+ Map<String, Object> map = JSONObject.parseObject(JSON.toJSONString(restResult.getData()));
|
|
|
|
+ if (map.containsKey(AuthConstant.ASSESS_TOKEN) && null != map.get(AuthConstant.ASSESS_TOKEN)) {
|
|
|
|
+ String userId = sysTokenService.getUserIDByToken(map.get(AuthConstant.ASSESS_TOKEN).toString());
|
|
|
|
+ JwtStore oldJwt = sysTokenService.getToken(userId);
|
|
|
|
+ String ip = HttpUtils.getIpAddress();
|
|
|
|
+ //异地登录
|
|
|
|
+ if (StringUtil.isNotBlank(ip)
|
|
|
|
+ && oldJwt != null
|
|
|
|
+ && !ip.equals(oldJwt.getIp())) {
|
|
|
|
+ //推送消息
|
|
|
|
+ List<SendToTopicDTO> sendToTopics = new ArrayList<>();
|
|
|
|
+ SendToTopicDTO sendToTopicDTO = new SendToTopicDTO();
|
|
|
|
+ sendToTopicDTO.setMessage("温誓提示,您的账号在其它地方已登录您将被迫下线!");
|
|
|
|
+ sendToTopicDTO.setType("login");
|
|
|
|
+ sendToTopicDTO.setTopic(userId);
|
|
|
|
+ sendToTopics.add(sendToTopicDTO);
|
|
|
|
+ messageService.sendToTopic(sendToTopics);
|
|
|
|
+ }
|
|
|
|
+ JwtStore jwtStore = new JwtStore();
|
|
|
|
+ jwtStore.setAccessToken(map.get(AuthConstant.ASSESS_TOKEN).toString());
|
|
|
|
+ jwtStore.setRefreshToken(map.get(AuthConstant.REFRESH_TOKEN).toString());
|
|
|
|
+ jwtStore.setIp(HttpUtils.getIpAddress());
|
|
|
|
+ sysTokenService.createToken(jwtStore);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public UserDto loadUserByUsername(String username) {
|
|
public UserDto loadUserByUsername(String username) {
|
|
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
|
userQueryWrapper.eq("username", username);
|
|
userQueryWrapper.eq("username", username);
|
|
@@ -211,7 +251,7 @@ public class UserManagementFacade {
|
|
} else {
|
|
} else {
|
|
if (ListUtil.isNotEmpty(users)) {
|
|
if (ListUtil.isNotEmpty(users)) {
|
|
users.stream().forEach(user1 -> {
|
|
users.stream().forEach(user1 -> {
|
|
- if(!user.getId().equals(user1.getId())){
|
|
|
|
|
|
+ if (!user.getId().equals(user1.getId())) {
|
|
Asserts.fail("该用户已存在,请更换用户名");
|
|
Asserts.fail("该用户已存在,请更换用户名");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -823,4 +863,13 @@ public class UserManagementFacade {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *@Description用户登出
|
|
|
|
+ *
|
|
|
|
+ * @param userId
|
|
|
|
+ * @Return com.lantone.common.api.CommonResult<java.lang.Boolean>
|
|
|
|
+ */
|
|
|
|
+ public CommonResult<Boolean> close(String userId) {
|
|
|
|
+ return CommonResult.success(sysTokenService.deleteToken(userId));
|
|
|
|
+ }
|
|
}
|
|
}
|