|
|
@@ -4,10 +4,11 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.account.AccountConfig;
|
|
|
import com.uas.sso.*;
|
|
|
-import com.uas.sso.exception.VisibleError;
|
|
|
-import com.uas.sso.foreign.factory.ForeignFactory;
|
|
|
-import com.uas.sso.foreign.entity.ForeignInfo;
|
|
|
-import com.uas.sso.foreign.service.ForeignService;
|
|
|
+import com.uas.sso.entity.UserAccount;
|
|
|
+import com.uas.sso.entity.login.ForeignLogin;
|
|
|
+import com.uas.sso.entity.login.PasswordLogin;
|
|
|
+import com.uas.sso.entity.login.SmsLogin;
|
|
|
+import com.uas.sso.entity.login.TokenLogin;
|
|
|
import com.uas.sso.foreign.bihe.entity.BiHeInfo;
|
|
|
import com.uas.sso.foreign.bihe.service.BiHeService;
|
|
|
import com.uas.sso.common.util.HttpUtil;
|
|
|
@@ -16,6 +17,7 @@ import com.uas.sso.entity.*;
|
|
|
import com.uas.sso.entity.Token;
|
|
|
import com.uas.sso.service.*;
|
|
|
import com.uas.sso.util.*;
|
|
|
+import com.uas.sso.util.BeanUtil;
|
|
|
import com.uas.sso.web.waf.request.WafRequestWrapper;
|
|
|
import com.uas.sso.foreign.weixin.entity.OAuthInfo;
|
|
|
import com.uas.sso.foreign.weixin.service.WeChatService;
|
|
|
@@ -84,80 +86,13 @@ public class LoginController extends BaseController {
|
|
|
@Autowired
|
|
|
private BiHeService biHeService;
|
|
|
|
|
|
- @RequestMapping(method = RequestMethod.POST)
|
|
|
- public ModelMap login() {
|
|
|
- // 获取登录信息
|
|
|
- Long start = System.currentTimeMillis();
|
|
|
- request.getSession().setAttribute("time", start);
|
|
|
- WafRequestWrapper wr = new WafRequestWrapper(request);
|
|
|
- String appId = wr.getParameter("appId");
|
|
|
- String spaceUU = wr.getParameter("spaceUU");
|
|
|
- String username = StringUtils.trimAllWhitespace(wr.getParameter("username"));
|
|
|
- String password = wr.getParameter("password");
|
|
|
- String captcha = wr.getParameter("captcha");
|
|
|
- String returnUrl = wr.getParameter("returnUrl");
|
|
|
- String baseUrl = wr.getParameter("baseUrl");
|
|
|
-
|
|
|
- // 校验空参数
|
|
|
- try {
|
|
|
- Assert.hasText(username, "用户名不能为空");
|
|
|
- Assert.hasText(password, "密码不能为空");
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
- return error(e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 设置baseUrl
|
|
|
- if (!StringUtils.isEmpty(baseUrl)) {
|
|
|
- request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
- }
|
|
|
-
|
|
|
- // 校验appId,appId为空的话默认为sso
|
|
|
- appId = StringUtils.isEmpty(appId) ? SSOHelper.getSSOService().getConfig().getAppName() : appId;
|
|
|
- App app = appService.findOne(appId);
|
|
|
- if (app == null) {
|
|
|
- return error("应用id不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验returnUrl,为空默认为优软云
|
|
|
- if (StringUtils.isEmpty(returnUrl)) {
|
|
|
- returnUrl = HOME_PAGE;
|
|
|
- }
|
|
|
- // 获取用户基本信息
|
|
|
- User user = userService.findByUsername(username);
|
|
|
- if (user == null) {
|
|
|
- return error("用户名或密码错误");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验账户密码输错次数
|
|
|
- UserRecord userRecord = userRecordService.findOne(user.getUserUU());
|
|
|
- int pwdErrorCount = userRecord == null ? 0 : userRecord.getPwdErrorCount();
|
|
|
- Object loginCaptcha = request.getSession().getAttribute(LOGIN_CAPTCHA);
|
|
|
- String checkCode = loginCaptcha == null ? "" : loginCaptcha.toString();
|
|
|
- if (pwdErrorCount >= PWD_ERROR_FIVE_TIME) {
|
|
|
- return error("403", "密码错误次数已达上限,今日无法登陆");
|
|
|
- }
|
|
|
- // 校验账号是否被锁定,5次输错密码
|
|
|
- if (pwdErrorCount >= PWD_ERROR_THREE_TIME && StringUtils.isEmpty(captcha)) {
|
|
|
- return error("404", "验证码不能为空");
|
|
|
- }
|
|
|
- if (pwdErrorCount >= PWD_ERROR_THREE_TIME && !captcha.equalsIgnoreCase(checkCode)) {
|
|
|
- return error("验证码错误");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验密码
|
|
|
- String encryPwd = userService.getEncryPassword(Const.ENCRY_FORMAT, password, user.getSalt());
|
|
|
- if (!encryPwd.equals(user.getPassword())) {
|
|
|
- pwdErrorCount = inputErrorPwd(user.getUserUU());
|
|
|
- return error("您输入的账号或密码有误").addAttribute("errorCount", pwdErrorCount);
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private LoginService loginService;
|
|
|
|
|
|
- // 校验密码强度,如果和存储的不同,则保存
|
|
|
- int strength = PasswordLevelUtils.checkPasswordLevel(password).getValue();
|
|
|
- if (strength != user.getPasswordLevel()) {
|
|
|
- user.setPasswordLevel(strength);
|
|
|
- userService.save(user);
|
|
|
- }
|
|
|
- return success(login(user.getUserUU(), appId, spaceUU, returnUrl));
|
|
|
+ @RequestMapping(method = RequestMethod.POST)
|
|
|
+ public ModelMap login(PasswordLogin loginParam) {
|
|
|
+ loginParam.setSureCaptcha((String) request.getSession().getAttribute(LOGIN_CAPTCHA));
|
|
|
+ return success(loginService.loginByPassword(loginParam));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -228,80 +163,22 @@ public class LoginController extends BaseController {
|
|
|
* erp和uu互联跳转
|
|
|
* 代理登录,根据tokenId拿到当前用户登录的用户uu号和企业uu号进行登录
|
|
|
*
|
|
|
- * @param token tokenId
|
|
|
- * @param appId 应用id
|
|
|
- * @param returnUrl 跳转页面
|
|
|
- * @param baseUrl 而外登录接口
|
|
|
+ * @param loginParam loginParam
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/proxy", method = RequestMethod.POST)
|
|
|
- public ModelMap loginProxyByToken(String token, String appId, String returnUrl, String baseUrl) {
|
|
|
- Token tk = tokenService.findOne(token);
|
|
|
- if (null != tk) {
|
|
|
- JSONObject data = JSON.parseObject(JSON.toJSONString(tk.getBind()));
|
|
|
- Long userUU = data.getLong("userUU");
|
|
|
- Long spaceUU = data.getLong("spaceUU");
|
|
|
- request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
- App app = appService.findOne(appId);
|
|
|
- if (app != null) {
|
|
|
- app = StringUtils.isEmpty(app.getUserControl()) ? app : appService.findOne(app.getUserControl());
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(returnUrl)) {
|
|
|
- returnUrl = HOME_PAGE;
|
|
|
- }
|
|
|
-
|
|
|
- if (app == null) {
|
|
|
- app = appService.findOne(AccountConfig.ACCOUNT_CENTER);
|
|
|
- }
|
|
|
-
|
|
|
- UserAccount userAccount = userAccountService.findOneByUserUU(app.getUid(), userUU, spaceUU);
|
|
|
-
|
|
|
- if (userAccount == null) {
|
|
|
- return success(new ModelMap("returnUrl", HttpUtil.decodeURL(returnUrl)));
|
|
|
- }
|
|
|
- return success(loginByUser(userAccount, returnUrl, true));
|
|
|
- }
|
|
|
- return success(new ModelMap("returnUrl", HttpUtil.decodeURL(returnUrl)));
|
|
|
+ public ModelMap loginProxyByToken(TokenLogin loginParam) {
|
|
|
+ return success(loginService.loginByToken(loginParam));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* uu互联代理登录
|
|
|
- * @param token tokenId
|
|
|
- * @param appId 登录应用应用id
|
|
|
- * @param spaceUU 企业uu号
|
|
|
- * @param returnUrl 跳转页面
|
|
|
+ * @param loginParam loginParam
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/mobile/proxy", method = RequestMethod.POST)
|
|
|
- public ModelMap loginProxyByToken(String token, @RequestParam(defaultValue = "sso") String appId, Long spaceUU, String returnUrl, String baseUrl) {
|
|
|
- Token tk = tokenService.findOne(token);
|
|
|
- if (tk == null) {
|
|
|
- return success(new ModelMap("returnUrl", HttpUtil.decodeURL(returnUrl)));
|
|
|
- }
|
|
|
- App app = appService.findOne(appId);
|
|
|
- baseUrl = StringUtils.isEmpty(baseUrl) ? app.getLoginUrl() : baseUrl;
|
|
|
- request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
- ModelMap modelMap = (ModelMap) tk.getBind();
|
|
|
- Long userUU = (Long) modelMap.get("userUU");
|
|
|
- if (modelMap.containsKey("spaceUU")) {
|
|
|
- spaceUU = (Long) modelMap.get("spaceUU");
|
|
|
- }
|
|
|
-
|
|
|
- if (app != null) {
|
|
|
- app = StringUtils.isEmpty(app.getUserControl()) ? app : appService.findOne(app.getUserControl());
|
|
|
- }
|
|
|
-
|
|
|
- if (app == null) {
|
|
|
- app = appService.findOne(AccountConfig.ACCOUNT_CENTER);
|
|
|
- }
|
|
|
-
|
|
|
- UserAccount userAccount = userAccountService.findOneByUserUU(app.getUid(), userUU, spaceUU);
|
|
|
- if (userAccount == null) {
|
|
|
- List<UserAccount> userAccounts = userAccountService.findByUserUU(app.getUid(), userUU);
|
|
|
- return success(getSpaceSelect(userAccounts, false));
|
|
|
- }
|
|
|
- return success(loginByUser(userAccount, returnUrl, false));
|
|
|
+ public ModelMap loginProxyByTokenMobile(TokenLogin loginParam) {
|
|
|
+ return success(loginService.loginByToken(loginParam));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -655,51 +532,8 @@ public class LoginController extends BaseController {
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/sms", method = RequestMethod.POST)
|
|
|
- public ModelMap loginBySms(String code, String token) {
|
|
|
- // 获取登录信息
|
|
|
- WafRequestWrapper wr = new WafRequestWrapper(request);
|
|
|
- String appId = wr.getParameter("appId");
|
|
|
- String spaceUU = wr.getParameter("spaceUU");
|
|
|
- String mobile = StringUtils.trimAllWhitespace(wr.getParameter("mobile"));
|
|
|
- String returnUrl = wr.getParameter("returnUrl");
|
|
|
- String baseUrl = wr.getParameter("baseUrl");
|
|
|
-
|
|
|
- appId = StringUtils.isEmpty(appId) ? AccountConfig.ACCOUNT_CENTER : appId;
|
|
|
-
|
|
|
- // 校验手机号是否被注册
|
|
|
- boolean hasRegister = userService.mobileHasRegistered(mobile);
|
|
|
- if (!hasRegister) {
|
|
|
- return error("该手机号未注册,请先注册");
|
|
|
- }
|
|
|
-
|
|
|
- // 设置baseUrl
|
|
|
- if (!StringUtils.isEmpty(baseUrl)) {
|
|
|
- request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(returnUrl)) {
|
|
|
- returnUrl = HOME_PAGE;
|
|
|
- }
|
|
|
-
|
|
|
- // 校验token
|
|
|
- Assert.hasText(token, "请先获取验证码");
|
|
|
- Token existToken = tokenService.findOne(token);
|
|
|
- if (existToken == null || existToken.isExpired()) {
|
|
|
- return error("验证码已过期,请重新获取");
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(existToken.getMobile()) && !existToken.getMobile().equals(mobile)) {
|
|
|
- return error("手机号被修改,请重新获取验证码");
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(code) || !code.equals(existToken.getBind())) {
|
|
|
- return error("验证码错误");
|
|
|
- }
|
|
|
-
|
|
|
- // 获取登录用户
|
|
|
- User user = userService.findByMobile(mobile);
|
|
|
- if (user == null) {
|
|
|
- return error("该手机号未注册");
|
|
|
- }
|
|
|
- return success(login(user.getUserUU(), appId, spaceUU, returnUrl));
|
|
|
+ public ModelMap loginBySms(SmsLogin loginParam) {
|
|
|
+ return success(loginService.loginBySms(loginParam));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -853,44 +687,13 @@ public class LoginController extends BaseController {
|
|
|
return success(login(user.getUserUU(), appId, spaceUU, returnUrl));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 碧合登录接口
|
|
|
- * @param appId 应用id(优软云应用id)
|
|
|
- * @param code 第三方获取用户信息code
|
|
|
+ * @param loginParam
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/foreignLogin", method = RequestMethod.POST)
|
|
|
- public ModelMap foreignLogin(@RequestParam(defaultValue = "city") String appId, String code, String type) {
|
|
|
- // 获取用户信息
|
|
|
- User user = null;
|
|
|
- Long userUU = (Long) request.getSession().getAttribute("userUU");
|
|
|
- if (userUU != null) {
|
|
|
- user = new User(userUU);
|
|
|
- } else {
|
|
|
- ForeignService foreignService = ForeignFactory.getForeignService(type);
|
|
|
- ForeignInfo foreignInfo = foreignService.getForeignInfoByCode(code);
|
|
|
- String accessToken = Optional.ofNullable(foreignInfo).map(ForeignInfo::getForeignAccessToken).orElseThrow(() -> new VisibleError("验证信息过期"));
|
|
|
- user = userService.findByForeignId(foreignInfo);
|
|
|
- // user为空提示未注册,不为空则放入session绑定用户使用
|
|
|
- if (user == null) {
|
|
|
- // 提示前端用户微信未绑定账号
|
|
|
- ModelMap map = new ModelMap("data", foreignInfo);
|
|
|
- Token token = new Token(map, foreignInfo.getForeignExpiresIn());
|
|
|
- tokenService.save(token);
|
|
|
- ModelMap data = new ModelMap("hasRegister", false);
|
|
|
- data.put("token", token.getId());
|
|
|
- return success(data);
|
|
|
- }
|
|
|
- request.getSession().setAttribute("userUU", user.getUserUU());
|
|
|
- }
|
|
|
-
|
|
|
- // 登录
|
|
|
- WafRequestWrapper wr = new WafRequestWrapper(request);
|
|
|
- String spaceUU = wr.getParameter("spaceUU");
|
|
|
- String returnUrl = wr.getParameter("returnUrl");
|
|
|
- String baseUrl = wr.getParameter("baseUrl");
|
|
|
- request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
- return success(login(user.getUserUU(), appId, spaceUU, returnUrl).addAttribute("hasRegister", true));
|
|
|
+ public ModelMap foreignLogin(ForeignLogin loginParam) {
|
|
|
+ return success(loginService.loginByForeign(loginParam));
|
|
|
}
|
|
|
}
|