|
@@ -4,12 +4,12 @@ import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.exception.CustomException;
|
|
|
-import com.ruoyi.common.exception.user.CaptchaException;
|
|
|
-import com.ruoyi.common.exception.user.CaptchaExpireException;
|
|
|
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.framework.manager.AsyncManager;
|
|
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
|
|
+import com.ruoyi.system.domain.SysUserOnline;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
@@ -18,6 +18,9 @@ import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 登录校验方法
|
|
@@ -48,14 +51,14 @@ public class SysLoginService {
|
|
|
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
|
|
String captcha = redisCache.getCacheObject(verifyKey);
|
|
|
redisCache.deleteObject(verifyKey);
|
|
|
- if (captcha == null) {
|
|
|
+ /*if (captcha == null) {
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
|
|
|
throw new CaptchaExpireException();
|
|
|
}
|
|
|
if (!code.equalsIgnoreCase(captcha)) {
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
|
|
throw new CaptchaException();
|
|
|
- }
|
|
|
+ }*/
|
|
|
// 用户验证
|
|
|
Authentication authentication = null;
|
|
|
try {
|
|
@@ -71,6 +74,18 @@ public class SysLoginService {
|
|
|
throw new CustomException(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+ Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*");
|
|
|
+ for (String key : keys) {
|
|
|
+ LoginUser user = redisCache.getCacheObject(key);
|
|
|
+ if (StringUtils.isNotEmpty(username) && StringUtils.isNotNull(user.getUser()))
|
|
|
+ {
|
|
|
+ if (StringUtils.equals(username, user.getUsername()))
|
|
|
+ {
|
|
|
+ // 若发现有其他用户登录,顶替掉其他用户
|
|
|
+ redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + user.getToken());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
// 生成token
|