|
|
@ -2,24 +2,32 @@ package cn.estsh.i3plus.core.apiservice.serviceimpl.base.login.strategy;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginStrategyService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginStrategyService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ILicenseClickService;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysUserService;
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysUserService;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.BaseThreadLocal;
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.BaseThreadLocal;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
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.SysConfig;
|
|
|
|
|
|
|
|
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.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;
|
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.estsh.i3plus.platform.common.util.CommonConstWords.DEFAULT_LANGUAGE;
|
|
|
|
import static cn.estsh.i3plus.platform.common.util.CommonConstWords.DEFAULT_LANGUAGE;
|
|
|
@ -37,9 +45,6 @@ public class DefaultLoginStrategy implements ISystemLoginStrategyService {
|
|
|
|
protected ImppRedis redisCore;
|
|
|
|
protected ImppRedis redisCore;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ILicenseClickService licenseClickService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ISysUserService userService;
|
|
|
|
private ISysUserService userService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
@ -65,6 +70,9 @@ public class DefaultLoginStrategy implements ISystemLoginStrategyService {
|
|
|
|
if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) {
|
|
|
|
if (sessionMode != CommonEnumUtil.SESSION_MODE.SEIZE.getValue()) {
|
|
|
|
AuthUtil.logout();
|
|
|
|
AuthUtil.logout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 已经对用户名和密码做过验证了
|
|
|
|
|
|
|
|
// 获取系统参数【密码过期时间】 进行密码有效时间判断
|
|
|
|
|
|
|
|
validatePasswordIsExpired(loginModel.getLoginName());
|
|
|
|
|
|
|
|
|
|
|
|
SessionUser user = userService.loginUser(
|
|
|
|
SessionUser user = userService.loginUser(
|
|
|
|
loginModel.getLoginName().trim(),
|
|
|
|
loginModel.getLoginName().trim(),
|
|
|
@ -84,4 +92,30 @@ public class DefaultLoginStrategy implements ISystemLoginStrategyService {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validatePasswordIsExpired(String loginName) {
|
|
|
|
|
|
|
|
SysConfig passwordExpireSwitch = RedisCacheTool.getSysConfigByConfigCode(CommonConstWords.CONFIG_PWD_EXPIRE_SWITCH);
|
|
|
|
|
|
|
|
if (passwordExpireSwitch != null
|
|
|
|
|
|
|
|
&& CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() == Integer.parseInt(passwordExpireSwitch.getConfigValue())) {
|
|
|
|
|
|
|
|
SysConfig passwordExpireDays = RedisCacheTool.getSysConfigByConfigCode(CommonConstWords.CONFIG_PWD_EXPIRE_DAY_TIME);
|
|
|
|
|
|
|
|
if (passwordExpireDays != null && Integer.parseInt(passwordExpireDays.getConfigValue()) > 0) {
|
|
|
|
|
|
|
|
SysUser user = userService.getSysUserByLoginName(loginName);
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(user.getUserPasswordLastModifyTime())) {
|
|
|
|
|
|
|
|
throw new ExpiredCredentialsException("用户密码过期 请重新设置新密码");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
DateFormat df = new SimpleDateFormat(CommonConstWords.DATE_TIME_FORMAT_HH_MM_SS_RISK);
|
|
|
|
|
|
|
|
Date lastModifyDate = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
lastModifyDate = df.parse(user.getUserPasswordLastModifyTime());
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
throw new ImppBusiException("验证用户密码登录时间,时间解析错误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
long dayGap = System.currentTimeMillis() - lastModifyDate.getTime() / (60 * 60 * 1000 * 24);
|
|
|
|
|
|
|
|
if ((int) dayGap >= Integer.parseInt(passwordExpireDays.getConfigValue())) {
|
|
|
|
|
|
|
|
throw new ExpiredCredentialsException("用户密码过期 请重新设置新密码");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|