|
@@ -2,11 +2,16 @@ package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonMapper;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.LoginRuleType;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.LoginRuleType;
|
|
import cn.com.qmth.examcloud.core.basic.service.LoginRuleService;
|
|
import cn.com.qmth.examcloud.core.basic.service.LoginRuleService;
|
|
import cn.com.qmth.examcloud.core.basic.service.VerifyCodeService;
|
|
import cn.com.qmth.examcloud.core.basic.service.VerifyCodeService;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.ClientLoginInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.ClientLoginInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.GeetestLoginInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.GeetestLoginInfo;
|
|
|
|
+import cn.com.qmth.examcloud.starters.crypto.common.CryptoConstant;
|
|
|
|
+import cn.com.qmth.examcloud.starters.crypto.common.CryptoHelper;
|
|
|
|
+import cn.com.qmth.examcloud.starters.crypto.common.FieldPair;
|
|
|
|
+import cn.com.qmth.examcloud.starters.crypto.utils.AesUtil;
|
|
import cn.com.qmth.examcloud.starters.greetest.model.RegisterReq;
|
|
import cn.com.qmth.examcloud.starters.greetest.model.RegisterReq;
|
|
import cn.com.qmth.examcloud.starters.greetest.model.RegisterResp;
|
|
import cn.com.qmth.examcloud.starters.greetest.model.RegisterResp;
|
|
import cn.com.qmth.examcloud.starters.greetest.model.ValidateResp;
|
|
import cn.com.qmth.examcloud.starters.greetest.model.ValidateResp;
|
|
@@ -17,12 +22,16 @@ import cn.com.qmth.examcloud.web.support.StatusResponseX;
|
|
import cn.com.qmth.examcloud.web.support.WithoutStackTrace;
|
|
import cn.com.qmth.examcloud.web.support.WithoutStackTrace;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 验证码相关接口
|
|
* 验证码相关接口
|
|
@@ -31,6 +40,8 @@ import javax.servlet.http.HttpServletRequest;
|
|
@Api(tags = "验证码登录相关接口")
|
|
@Api(tags = "验证码登录相关接口")
|
|
public class VerifyCodeController extends ControllerSupport {
|
|
public class VerifyCodeController extends ControllerSupport {
|
|
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(VerifyCodeController.class);
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private LoginRuleService loginRuleService;
|
|
private LoginRuleService loginRuleService;
|
|
|
|
|
|
@@ -70,6 +81,47 @@ public class VerifyCodeController extends ControllerSupport {
|
|
return new StatusResponseX<>(user);
|
|
return new StatusResponseX<>(user);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Naked
|
|
|
|
+ @WithoutStackTrace
|
|
|
|
+ @ApiOperation(value = "登录接口(新)")
|
|
|
|
+ @PostMapping(value = "/api/ecs_core/login")
|
|
|
|
+ public StatusResponseX<String> login(@RequestBody GeetestLoginInfo info, HttpServletRequest request) {
|
|
|
|
+ setAlwaysOKResponse();
|
|
|
|
+
|
|
|
|
+ if (info.getRootOrgId() == null) {
|
|
|
|
+ throw new StatusException("400", "顶级机构ID不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String timestampStr = request.getHeader(CryptoConstant.TIMESTAMP);
|
|
|
|
+ if (StringUtils.isEmpty(timestampStr)) {
|
|
|
|
+ log.error("[header] timestamp is wrong... {}", timestampStr);
|
|
|
|
+ throw new StatusException("400X01", CryptoConstant.REQUEST_PARAM_ERROR);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 当前机构是否“开放极验验证码登录”
|
|
|
|
+ boolean open = loginRuleService.isLoginRuleAllow(info.getRootOrgId(), LoginRuleType.GEETEST_LOGIN);
|
|
|
|
+ if (open) {
|
|
|
|
+ info.setIp_address(super.getIp(request));
|
|
|
|
+ ValidateResp resp = geetestService.validate(info);
|
|
|
|
+ if (!resp.getSuccess()) {
|
|
|
|
+ throw new StatusException("400", resp.getMsg());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ User user = verifyCodeService.geetestLogin(info);
|
|
|
|
+ log.info("[LOGIN_IN] user = {}, salt = {}", user.buildKey(), user.getSalt());
|
|
|
|
+
|
|
|
|
+ String key = CryptoHelper.buildKey(
|
|
|
|
+ new FieldPair("accountValue", info.getAccountValue()),
|
|
|
|
+ new FieldPair("password", info.getPassword()),
|
|
|
|
+ new FieldPair("timestamp", timestampStr)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ String json = new JsonMapper().toJson(user);
|
|
|
|
+ String content = AesUtil.encrypt(json, key.getBytes(StandardCharsets.UTF_8));
|
|
|
|
+ return new StatusResponseX<>(content);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Naked
|
|
@Naked
|
|
@WithoutStackTrace
|
|
@WithoutStackTrace
|
|
@ApiOperation(value = "极验-验证码登录接口")
|
|
@ApiOperation(value = "极验-验证码登录接口")
|