增加用户账号类型,修改登录逻辑

yun-zuoyi
nies 3 years ago
parent 4c49c5c393
commit c69deadbf0

@ -116,7 +116,7 @@ public class PersonnelController extends CoreBaseController {
} }
info.setUserInfoStatus(CommonEnumUtil.USER_INFO_STATUS.INCUMBENT.getValue()); info.setUserInfoStatus(CommonEnumUtil.USER_INFO_STATUS.INCUMBENT.getValue());
if (info.getUserLoginNum() == null){ if (info.getUserLoginNum() == null) {
info.setUserLoginNum(0); info.setUserLoginNum(0);
} }
info.setIsValid(CommonEnumUtil.IS_VAILD.VAILD.getValue()); info.setIsValid(CommonEnumUtil.IS_VAILD.VAILD.getValue());
@ -125,7 +125,7 @@ public class PersonnelController extends CoreBaseController {
user.setUserType(CommonEnumUtil.USER_TYPE.USER.getValue()); user.setUserType(CommonEnumUtil.USER_TYPE.USER.getValue());
user.setUserStatus(CommonEnumUtil.USER_STATUS.ENABLE.getValue()); user.setUserStatus(CommonEnumUtil.USER_STATUS.ENABLE.getValue());
user.setIsValid(CommonEnumUtil.IS_VAILD.VAILD.getValue()); user.setIsValid(CommonEnumUtil.IS_VAILD.VAILD.getValue());
if (user.getUserLoginNum() == null){ if (user.getUserLoginNum() == null) {
user.setUserLoginNum(0); user.setUserLoginNum(0);
} }
ConvertBean.modelInitialize(user, AuthUtil.getSessionUser()); ConvertBean.modelInitialize(user, AuthUtil.getSessionUser());
@ -161,7 +161,7 @@ public class PersonnelController extends CoreBaseController {
//松下需要创建的新用户 第一次登陆系统就要重置密码 //松下需要创建的新用户 第一次登陆系统就要重置密码
// user.setUserPasswordLastModifyTime(TimeTool.getNowTime(true)); // user.setUserPasswordLastModifyTime(TimeTool.getNowTime(true));
refreshSysUserPassword(user); refreshSysUserPassword(user);
SysUser userSaved=personnelService.saveSysUser(user); SysUser userSaved = personnelService.saveSysUser(user);
// 添加保存passwordId进SysUser表 // 添加保存passwordId进SysUser表
SysUserPassword pwd = new SysUserPassword(); SysUserPassword pwd = new SysUserPassword();
@ -264,6 +264,12 @@ public class PersonnelController extends CoreBaseController {
sysUser.setUserEmpNo(userInfo.getUserEmpNo()); sysUser.setUserEmpNo(userInfo.getUserEmpNo());
sysUser.setAuthPlatform(user.getAuthPlatform()); sysUser.setAuthPlatform(user.getAuthPlatform());
if (StringUtils.isBlank(user.getUserAccountType()) || CommonEnumUtil.USER_ACCOUNT_TYPE.valueOfEnum(user.getUserAccountType()) == null) {
sysUser.setUserAccountType(String.valueOf(CommonEnumUtil.USER_ACCOUNT_TYPE.SYSTEM.getValue()));
} else {
sysUser.setUserAccountType(user.getUserAccountType());
}
// 关系 刷新 // 关系 刷新
refreshRef(sysUser, userInfo, model); refreshRef(sysUser, userInfo, model);
@ -728,9 +734,9 @@ public class PersonnelController extends CoreBaseController {
.notNull("infoDepartmentId", model.getInfoDepartmentId()) .notNull("infoDepartmentId", model.getInfoDepartmentId())
.notNull("userDepartmentId", model.getUserDepartmentId()) .notNull("userDepartmentId", model.getUserDepartmentId())
.notNull("userLoginName", model.getUserLoginName()); .notNull("userLoginName", model.getUserLoginName());
// FIXME 松下移除邮箱校验 // FIXME 松下移除邮箱校验
// .notNull("userEmail", model.getUserEmail()) // .notNull("userEmail", model.getUserEmail())
// FIXME 松下移除手机号校验 // FIXME 松下移除手机号校验
// .notNull("userPhone", model.getUserPhone()); // .notNull("userPhone", model.getUserPhone());
} }

@ -29,6 +29,7 @@ import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException; import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ImppRedis; import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.RedisCacheTool;
import cn.estsh.impp.framework.boot.util.ResultBean; import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean; import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -583,7 +584,8 @@ public class SysUserController extends CoreBaseController {
SysUser user = sysUserService.getSysUserById(Long.parseLong(id)); SysUser user = sysUserService.getSysUserById(Long.parseLong(id));
if (user != null) { if (user != null) {
Integer num = personnelService.checkSysUserResetPassword(user); Integer num = personnelService.checkSysUserResetPassword(user);
num = CommonConstWords.CONFIG_PWD_RESET_PASSWORD_DEFAULT - num; int numMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_PWD_RESET_PASSWORD, CommonConstWords.CONFIG_PWD_RESET_PASSWORD_DEFAULT);
num = numMax - num;
// String password = RandomStringUtils.random(6, true, false); // String password = RandomStringUtils.random(6, true, false);
@ -642,7 +644,8 @@ public class SysUserController extends CoreBaseController {
SysUser user = sysUserService.getSysUserById(Long.parseLong(id)); SysUser user = sysUserService.getSysUserById(Long.parseLong(id));
if (user != null) { if (user != null) {
Integer num = personnelService.checkSysUserResetPassword(user); Integer num = personnelService.checkSysUserResetPassword(user);
num = CommonConstWords.CONFIG_PWD_RESET_PASSWORD_DEFAULT - num; int numMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_PWD_RESET_PASSWORD, CommonConstWords.CONFIG_PWD_RESET_PASSWORD_DEFAULT);
num = numMax - num;
userPasswordService.updatePasswordResetLastModifyTime(user.getId(), password, true); userPasswordService.updatePasswordResetLastModifyTime(user.getId(), password, true);
LOGGER.info("系统提示:{} 使用密码重置功能帮{}重置了{}账号的密码,新密码是:{}", LOGGER.info("系统提示:{} 使用密码重置功能帮{}重置了{}账号的密码,新密码是:{}",

@ -11,6 +11,7 @@ import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
import cn.estsh.i3plus.pojo.platform.bean.SysConfig; import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
import cn.estsh.i3plus.pojo.platform.bean.SysUser; import cn.estsh.i3plus.pojo.platform.bean.SysUser;
import cn.estsh.impp.framework.boot.auth.AuthUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.auth.filter.UserFilter;
import cn.estsh.impp.framework.boot.exception.ImppBusiException; import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.util.ImppRedis; import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.RedisCacheTool; import cn.estsh.impp.framework.boot.util.RedisCacheTool;
@ -18,6 +19,7 @@ import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean; import cn.estsh.impp.framework.boot.util.ValidatorBean;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.CredentialsException;
import org.apache.shiro.authc.ExpiredCredentialsException; import org.apache.shiro.authc.ExpiredCredentialsException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -66,9 +68,19 @@ public class DefaultLoginStrategy implements ISystemLoginStrategyService {
ValidatorBean.checkNotNull(loginModel.getLoginName(), "用户名不能为空"); ValidatorBean.checkNotNull(loginModel.getLoginName(), "用户名不能为空");
ValidatorBean.checkNotNull(loginModel.getLoginPwd(), "密码不能为空"); ValidatorBean.checkNotNull(loginModel.getLoginPwd(), "密码不能为空");
int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT); // int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT);
SysUser dbUser = userService.getSysUserByLoginName(loginModel.getLoginName().trim());
if (dbUser == null) {
throw new CredentialsException("用户不存在");
}
int sessionMode = UserFilter.getSessionModeByUserAccountType(dbUser.getUserAccountType());
if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) { if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) {
AuthUtil.logout(); if (sessionMode == CommonEnumUtil.SESSION_MODE.OVERWRITE.getValue()){
log.info("session Mode 是{},可以多端登录",sessionMode);
}else{
log.info("session Mode 是{},把上一个用户挤下线",sessionMode);
AuthUtil.logout();
}
} }
// 已经对用户名和密码做过验证了 // 已经对用户名和密码做过验证了
// 获取系统参数【密码过期时间】 进行密码有效时间判断 // 获取系统参数【密码过期时间】 进行密码有效时间判断

@ -12,12 +12,15 @@ import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import cn.estsh.i3plus.pojo.model.platform.SysLoginModel; import cn.estsh.i3plus.pojo.model.platform.SysLoginModel;
import cn.estsh.i3plus.pojo.platform.bean.SessionUser; import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
import cn.estsh.i3plus.pojo.platform.bean.SysUser;
import cn.estsh.impp.framework.boot.auth.AuthUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.auth.filter.UserFilter;
import cn.estsh.impp.framework.boot.util.ImppRedis; import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.RedisCacheTool; import cn.estsh.impp.framework.boot.util.RedisCacheTool;
import cn.estsh.impp.framework.boot.util.ResultBean; import cn.estsh.impp.framework.boot.util.ResultBean;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authc.CredentialsException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -69,7 +72,12 @@ public class E9LoginStrategy implements ISystemLoginStrategyService {
BaseThreadLocal.setData(BaseThreadLocal.LANGUAGE_CODE, loginModel.getLanguageCode()); BaseThreadLocal.setData(BaseThreadLocal.LANGUAGE_CODE, loginModel.getLanguageCode());
BaseThreadLocal.setData(PlatformConstWords.AUTH_LOGIN_STRATEGY, ImppEnumUtil.AUTH_LOGIN_STRATEGY.E9.getCode()); BaseThreadLocal.setData(PlatformConstWords.AUTH_LOGIN_STRATEGY, ImppEnumUtil.AUTH_LOGIN_STRATEGY.E9.getCode());
int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT); // int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT);
SysUser dbUser = userService.getSysUserByLoginName(loginModel.getLoginName().trim());
if (dbUser == null) {
throw new CredentialsException("用户不存在");
}
int sessionMode = UserFilter.getSessionModeByUserAccountType(dbUser.getUserAccountType());
if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) { if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) {
AuthUtil.logout(); AuthUtil.logout();
} }

@ -12,12 +12,15 @@ import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import cn.estsh.i3plus.pojo.model.platform.SysLoginModel; import cn.estsh.i3plus.pojo.model.platform.SysLoginModel;
import cn.estsh.i3plus.pojo.platform.bean.SessionUser; import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
import cn.estsh.i3plus.pojo.platform.bean.SysUser;
import cn.estsh.impp.framework.boot.auth.AuthUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.auth.filter.UserFilter;
import cn.estsh.impp.framework.boot.util.ImppRedis; import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.RedisCacheTool; import cn.estsh.impp.framework.boot.util.RedisCacheTool;
import cn.estsh.impp.framework.boot.util.ResultBean; import cn.estsh.impp.framework.boot.util.ResultBean;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authc.CredentialsException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -65,7 +68,12 @@ public class NameLoginStrategy implements ISystemLoginStrategyService {
BaseThreadLocal.setData(BaseThreadLocal.LANGUAGE_CODE, loginModel.getLanguageCode()); BaseThreadLocal.setData(BaseThreadLocal.LANGUAGE_CODE, loginModel.getLanguageCode());
BaseThreadLocal.setData(PlatformConstWords.AUTH_LOGIN_STRATEGY, ImppEnumUtil.AUTH_LOGIN_STRATEGY.NAME.getCode()); BaseThreadLocal.setData(PlatformConstWords.AUTH_LOGIN_STRATEGY, ImppEnumUtil.AUTH_LOGIN_STRATEGY.NAME.getCode());
int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT); // int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT);
SysUser dbUser = userService.getSysUserByLoginName(loginModel.getLoginName().trim());
if (dbUser == null) {
throw new CredentialsException("用户不存在");
}
int sessionMode = UserFilter.getSessionModeByUserAccountType(dbUser.getUserAccountType());
if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) { if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) {
AuthUtil.logout(); AuthUtil.logout();
} }

@ -28,6 +28,7 @@ import cn.estsh.i3plus.pojo.platform.repository.SysUserInfoRepository;
import cn.estsh.i3plus.pojo.platform.repository.SysUserRepository; import cn.estsh.i3plus.pojo.platform.repository.SysUserRepository;
import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack; import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack;
import cn.estsh.impp.framework.boot.auth.AuthUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.auth.filter.UserFilter;
import cn.estsh.impp.framework.boot.exception.ImppBusiException; import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.*; import cn.estsh.impp.framework.boot.util.*;
@ -130,7 +131,6 @@ public class SysUserService implements ISysUserService {
SysUser user = null; SysUser user = null;
ResultBean resultBean = ResultBean.fail(); ResultBean resultBean = ResultBean.fail();
try { try {
BaseToken token = getToken(loginName, password, languageCode, loginPlatform);
user = this.getSysUserByLoginName(loginName); user = this.getSysUserByLoginName(loginName);
if (user == null) { if (user == null) {
throw new CredentialsException("用户不存在"); throw new CredentialsException("用户不存在");
@ -144,10 +144,13 @@ public class SysUserService implements ISysUserService {
resultBean = result; resultBean = result;
return resultBean; return resultBean;
} }
BaseToken token = getToken(loginName, password, languageCode, loginPlatform);
sessionUser = AuthUtil.login(token); sessionUser = AuthUtil.login(token);
// 判断会话模式 // 判断会话模式
checkSessionMode(loginPlatform, user.getId()); // checkSessionMode(loginPlatform, user.getId());
checkSessionMode(loginPlatform, user);
packSessionUser(sessionUser, user, user.getUserType(), loginPlatform, languageCode, deviceId); packSessionUser(sessionUser, user, user.getUserType(), loginPlatform, languageCode, deviceId);
packConfigSessionUser(sessionUser, user); packConfigSessionUser(sessionUser, user);
@ -233,6 +236,27 @@ public class SysUserService implements ISysUserService {
} }
} }
private void checkSessionMode(Integer loginPlatform, SysUser sysUser) {
// int sessionMode = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_SESSION_MODE, CommonConstWords.CONFIG_SESSION_MODE_DEFAULT);
int sessionMode = UserFilter.getSessionModeByUserAccountType(sysUser.getUserAccountType());
String redisKey;
if (sessionMode == CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) {
redisKey = CommonConstWords.SESSION_USER + ":*_" + sysUser.getId();
} else {
return;
}
List<Object> ds = redisSession.findObject(redisKey);
if (CollectionUtils.isNotEmpty(ds)) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
.setErrorCode(ImppExceptionEnum.LOGIN_EXCEPTION_LOGGED.getCode())
.setErrorDetail("用户已在其他设备登录,无法同时登录!")
.setErrorSolution("请联系管理员")
.build();
}
}
@Override @Override
public BaseToken getToken(String loginName, String password, String languageCode, Integer loginPlatform) { public BaseToken getToken(String loginName, String password, String languageCode, Integer loginPlatform) {
SysUser user = this.getSysUserByLoginName(loginName); SysUser user = this.getSysUserByLoginName(loginName);

Loading…
Cancel
Save