|
@@ -17,6 +17,7 @@ import com.doc.framework.manager.factory.AsyncFactory;
|
|
|
import com.doc.framework.security.context.AuthenticationContextHolder;
|
|
import com.doc.framework.security.context.AuthenticationContextHolder;
|
|
|
import com.doc.system.service.ISysConfigService;
|
|
import com.doc.system.service.ISysConfigService;
|
|
|
import com.doc.system.service.ISysUserService;
|
|
import com.doc.system.service.ISysUserService;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
@@ -47,6 +48,9 @@ public class SysLoginService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private ISysConfigService configService;
|
|
private ISysConfigService configService;
|
|
|
|
|
|
|
|
|
|
+ @Value("${token.soloLogin}")
|
|
|
|
|
+ private boolean soloLogin;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 登录验证
|
|
* 登录验证
|
|
|
*
|
|
*
|
|
@@ -82,6 +86,16 @@ public class SysLoginService {
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
recordLoginInfo(loginUser.getUserId());
|
|
recordLoginInfo(loginUser.getUserId());
|
|
|
|
|
+ // 判断是否允许账户多终端同时登录
|
|
|
|
|
+ if (!soloLogin) {
|
|
|
|
|
+ // 如果用户不允许多终端同时登录,清除缓存信息
|
|
|
|
|
+ String userIdKey = Constants.LOGIN_USERID_KEY + loginUser.getUser().getUserId();
|
|
|
|
|
+ String userKey = redisCache.getCacheObject(userIdKey);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(userKey)) {
|
|
|
|
|
+ redisCache.deleteObject(userIdKey);
|
|
|
|
|
+ redisCache.deleteObject(userKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
// 生成token
|
|
// 生成token
|
|
|
return tokenService.createToken(loginUser);
|
|
return tokenService.createToken(loginUser);
|
|
|
}
|
|
}
|