|
|
|
@ -2,7 +2,6 @@ package cn.estsh.i3plus.core.apiservice.controller.base;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISynchronizedService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemInitService;
|
|
|
|
|
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.busi.*;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.controller.busi.PersonnelController;
|
|
|
|
@ -29,6 +28,7 @@ import cn.estsh.i3plus.pojo.model.platform.SysLoginModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.UserDetailModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.UserDetailPagerModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.*;
|
|
|
|
|
import cn.estsh.i3plus.sdk.dingtalk.cn.estsh.i3plus.sdk.service.IDingTalkService;
|
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
@ -42,11 +42,15 @@ import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dingtalk.api.response.OapiV2UserGetResponse;
|
|
|
|
|
import com.google.common.cache.Cache;
|
|
|
|
|
import com.google.common.cache.CacheBuilder;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
|
|
|
import org.apache.shiro.authc.CredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.ExpiredCredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.IncorrectCredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.LockedAccountException;
|
|
|
|
|
import org.apache.shiro.authc.UnknownAccountException;
|
|
|
|
@ -75,6 +79,7 @@ import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -132,7 +137,7 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISystemLoginService loginService;
|
|
|
|
|
private ISysUserPasswordService userPasswordService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysUserPasswordUtil userPasswordUtil;
|
|
|
|
@ -149,6 +154,14 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IDingTalkService dingTalkService;
|
|
|
|
|
|
|
|
|
|
private Cache<String, Integer> unsavedLocaleResSwitch = CacheBuilder.newBuilder()
|
|
|
|
|
.maximumSize(1)
|
|
|
|
|
.expireAfterWrite(1, TimeUnit.MINUTES)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/sys-locale-language/list")
|
|
|
|
|
@ApiOperation(value = "查询可用语言", notes = "查询可用语言")
|
|
|
|
|
public ResultBean listSysLocaleLanguage() {
|
|
|
|
@ -285,6 +298,54 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
return Optional.ofNullable(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/auth/dingtalk/login")
|
|
|
|
|
@ApiOperation(value = "登录", notes = "登录")
|
|
|
|
|
public ResultBean loginByPhoneNumber(HttpServletRequest request, String dingTalkTmpAuthCode,
|
|
|
|
|
@RequestParam(required = false) String languageCode,
|
|
|
|
|
@RequestParam(required = false) String deviceId) {
|
|
|
|
|
SysLoginModel loginModel = SysLoginModel.builder()
|
|
|
|
|
.dingTalkTmpAuthCode(dingTalkTmpAuthCode)
|
|
|
|
|
.languageCode(languageCode)
|
|
|
|
|
.deviceId(deviceId)
|
|
|
|
|
.loginStrategy(ImppEnumUtil.AUTH_LOGIN_STRATEGY.NAME.getCode()).build();
|
|
|
|
|
|
|
|
|
|
String dingTalkUrl = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_URL);
|
|
|
|
|
String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET);
|
|
|
|
|
String dingTalkWhiteList = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_WHITE_LIST);
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(dingTalkUrl) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkAppKey) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkAppSecret) ||
|
|
|
|
|
StringUtils.isEmpty(dingTalkWhiteList)) {
|
|
|
|
|
return ResultBean.fail("访问钉钉的系统参数缺失,请在平台的系统参数中进行配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Optional<OapiV2UserGetResponse> userInfo =
|
|
|
|
|
dingTalkService.getUserInfo(dingTalkUrl, dingTalkAppKey, dingTalkAppSecret, loginModel.getDingTalkTmpAuthCode());
|
|
|
|
|
if (userInfo.isPresent()) {
|
|
|
|
|
String mobile = userInfo.get().getResult().getMobile();
|
|
|
|
|
if (StringUtils.isEmpty(mobile)) {
|
|
|
|
|
return ResultBean.fail("用户并未在钉钉中设置手机号 或 钉钉接口权限不足无法获取到手机号");
|
|
|
|
|
}
|
|
|
|
|
if (!Arrays.asList(dingTalkWhiteList.split(",")).contains(mobile)) {
|
|
|
|
|
return ResultBean.fail("对指定手机号允许,权限不足,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
SysUser sysUserByPhone = userService.getSysUserByPhone(mobile);
|
|
|
|
|
if (sysUserByPhone == null) {
|
|
|
|
|
return ResultBean.fail("未根据用户手机在平台中找到相应记录 钉钉获取的手机号为" + mobile);
|
|
|
|
|
}
|
|
|
|
|
loginModel.setLoginName(sysUserByPhone.getUserLoginName());
|
|
|
|
|
loginModel.setPhoneNumber(mobile);
|
|
|
|
|
} else {
|
|
|
|
|
return ResultBean.fail("获取钉钉用户信息失败");
|
|
|
|
|
}
|
|
|
|
|
String beanName = ImppEnumUtil.AUTH_LOGIN_STRATEGY.codeOfStrategyName(loginModel.getLoginStrategy());
|
|
|
|
|
ISystemLoginStrategyService loginStrategyService = (ISystemLoginStrategyService) SpringContextsUtil.getBean(beanName);
|
|
|
|
|
|
|
|
|
|
return loginByStrategy(request, loginModel, loginStrategyService.login());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/auth/login")
|
|
|
|
|
@ApiOperation(value = "登录", notes = "登录")
|
|
|
|
|
public ResultBean login(HttpServletRequest request, String loginName, String loginPwd,
|
|
|
|
@ -316,8 +377,10 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
} catch (IncorrectCredentialsException e) {
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD);
|
|
|
|
|
userPasswordUtil.checkLoginErrorNumber(loginModel.getLoginName(), result, e);
|
|
|
|
|
|
|
|
|
|
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.WRONG_PASSWORD;
|
|
|
|
|
} catch (ExpiredCredentialsException e) {
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_PASSWORD_EXPIRED);
|
|
|
|
|
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.WRONG_USERNAME_OR_PASSWORD;
|
|
|
|
|
} catch (CredentialsException e) {
|
|
|
|
|
// 用户名或密码错误
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_NAME);
|
|
|
|
@ -335,13 +398,16 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getDescription()).setCode(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getCode());
|
|
|
|
|
result.setErrorMsg(e.getMessage());
|
|
|
|
|
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
|
|
|
|
|
LOGGER.warn("Impp业务异常AuthenticationException 登录失败 ", e);
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
result = ResultBean.fail(e);
|
|
|
|
|
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
|
|
|
|
|
LOGGER.warn("Impp业务异常ImppBusiException 登录失败 ", e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
result = ResultBean.fail(e.getMessage()).setCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode())
|
|
|
|
|
.setErrorMsg(LocaleUtils.getEnumLocaleResDesc(ImppExceptionEnum.SYSTEM_EXCEPTION, ImppExceptionEnum.SYSTEM_EXCEPTION.getDescription()));
|
|
|
|
|
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
|
|
|
|
|
LOGGER.warn("Impp业务异常Exception 登录失败 ", e);
|
|
|
|
|
} finally {
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginModel.getLoginName(), userLoginStatus.getValue());
|
|
|
|
@ -685,6 +751,17 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
@ApiOperation(value = "缺失资源", notes = "缺失资源")
|
|
|
|
|
public ResultBean getMissResourceByKey(String key, String menuCode) {
|
|
|
|
|
try {
|
|
|
|
|
Integer switcher = unsavedLocaleResSwitch.asMap().get(PlatformConstWords.WEB_MISS_RESOURCE_LISTENER_SWITCH);
|
|
|
|
|
|
|
|
|
|
if (switcher == null) {
|
|
|
|
|
switcher = RedisCacheTool.getSysConfigIntVal(PlatformConstWords.WEB_MISS_RESOURCE_LISTENER_SWITCH,
|
|
|
|
|
CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
|
|
|
|
|
unsavedLocaleResSwitch.put(PlatformConstWords.WEB_MISS_RESOURCE_LISTENER_SWITCH, switcher);
|
|
|
|
|
}
|
|
|
|
|
if (switcher == -1 || switcher == CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) {
|
|
|
|
|
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, String> missResource = new HashMap<>();
|
|
|
|
|
missResource.put(key, menuCode);
|
|
|
|
|
rabbitTemplate.convertAndSend(PlatformConstWords.QUEUE_IMPP_RESOURCE, JsonUtilTool.encode(missResource));
|
|
|
|
@ -717,6 +794,24 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping(value = "/update-expired-password")
|
|
|
|
|
@ApiOperation(value = "修改密码", notes = "松下修改当前登录用户密码")
|
|
|
|
|
public ResultBean updateSysUserPassword(String loginName, String password, String newPwd) {
|
|
|
|
|
try {
|
|
|
|
|
// 数据校验
|
|
|
|
|
ValidatorBean.checkNotNull(password, "旧密码不能为空");
|
|
|
|
|
ValidatorBean.checkNotNull(newPwd, "新密码不能为空");
|
|
|
|
|
ValidatorBean.checkNotNull(loginName, "用户名不能为空");
|
|
|
|
|
|
|
|
|
|
userPasswordService.updatePasswordWizoutSession(loginName, password, newPwd.trim());
|
|
|
|
|
return ResultBean.success("修改密码成功,请重新登陆").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/license")
|
|
|
|
|
@ApiOperation(value = "更新授权", notes = "更新授权")
|
|
|
|
|
public ResultBean updateLicense(String content) {
|
|
|
|
|