|
|
|
@ -30,17 +30,11 @@ import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack;
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
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.ValidatorBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.*;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
|
|
|
import org.apache.shiro.authc.CredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.IncorrectCredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.UnknownAccountException;
|
|
|
|
|
import org.apache.shiro.authc.*;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -140,6 +134,9 @@ public class SysUserService implements ISysUserService {
|
|
|
|
|
if (user == null) {
|
|
|
|
|
throw new CredentialsException("用户不存在");
|
|
|
|
|
}
|
|
|
|
|
if (user.getUserStatus() != CommonEnumUtil.USER_STATUS.ENABLE.getValue()) {
|
|
|
|
|
throw new LockedAccountException("账号已被锁定");
|
|
|
|
|
}
|
|
|
|
|
//校验 用户
|
|
|
|
|
ResultBean result = passwordUtil.checkSysUserLogin(user);
|
|
|
|
|
if (!result.isSuccess()) {
|
|
|
|
@ -156,25 +153,60 @@ public class SysUserService implements ISysUserService {
|
|
|
|
|
AuthUtil.setSessionUser(sessionUser);
|
|
|
|
|
AuthUtil.online(sessionUser);
|
|
|
|
|
resultBean = ResultBean.success().setResultObject(sessionUser);
|
|
|
|
|
} catch (CredentialsException e) {
|
|
|
|
|
}catch (ImppBusiException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultBean = ResultBean.fail(e);
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (CredentialsException e) {
|
|
|
|
|
// 用户名或密码错误
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultBean = ResultBean.fail(e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
resultBean = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_NAME);
|
|
|
|
|
} catch (LockedAccountException e) {
|
|
|
|
|
// 账号已锁定
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultBean = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_LOCKING);
|
|
|
|
|
} catch (UnknownAccountException e) {
|
|
|
|
|
// 用户信息不存在
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultBean = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_INFO_NULL);
|
|
|
|
|
}catch (AuthenticationException e) {
|
|
|
|
|
// 系统异常
|
|
|
|
|
resultBean = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getDescription()).setCode(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getCode());
|
|
|
|
|
if (e.getCause() != null) {
|
|
|
|
|
if (e.getCause() instanceof ImppBusiException) {
|
|
|
|
|
ImppBusiException imppBusiException = (ImppBusiException) e.getCause();
|
|
|
|
|
resultBean.setErrorMsg(LocaleUtils.getLocaleRes(imppBusiException.getErrorDetail()));
|
|
|
|
|
} else {
|
|
|
|
|
resultBean.setErrorMsg(e.getCause().getMessage());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
resultBean.setErrorMsg(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
LOGGER.warn("Impp业务异常AuthenticationException 登录失败 ", e);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultBean = ResultBean.fail(e);
|
|
|
|
|
if (e.getCause() != null) {
|
|
|
|
|
resultBean.setErrorMsg(e.getCause().getMessage());
|
|
|
|
|
} else {
|
|
|
|
|
resultBean.setErrorMsg(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
//如果登录成功,刷新登录成功次数和上次登录时间
|
|
|
|
|
if (resultBean.isSuccess()){
|
|
|
|
|
try{
|
|
|
|
|
if (resultBean.isSuccess()) {
|
|
|
|
|
this.refreshUserLoginInformation(user.getId());
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
//如果登录不成功,且有这个用户,就只刷新上次用户的登录时间。
|
|
|
|
|
if (!ObjectUtils.isEmpty(user) && !ObjectUtils.isEmpty(user.getId())) {
|
|
|
|
|
this.refreshUserLoginDateTime(user.getId(), user.getUserInfoId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return resultBean;
|
|
|
|
@ -333,13 +365,13 @@ public class SysUserService implements ISysUserService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateUserLoginNum(Long userId,Integer loginNum) {
|
|
|
|
|
public void updateUserLoginNum(Long userId, Integer loginNum) {
|
|
|
|
|
SysUser user = userRDao.getById(userId);
|
|
|
|
|
user.setUserLoginNum(loginNum);
|
|
|
|
|
userRDao.save(user);
|
|
|
|
|
DdlPackBean userInfoDdlPackBean = DdlPackBean.getDdlPackBean();
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(user.getUserInfoId(), "id", userInfoDdlPackBean);
|
|
|
|
|
sysUserInfoRDao.updateByProperties(new String[]{"userLoginNum"}, new Object[]{loginNum},userInfoDdlPackBean);
|
|
|
|
|
sysUserInfoRDao.updateByProperties(new String[]{"userLoginNum"}, new Object[]{loginNum}, userInfoDdlPackBean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|