|
@@ -1,33 +1,42 @@
|
|
|
package com.qmth.teachcloud.report.api;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.boot.api.annotation.Aac;
|
|
|
import com.qmth.boot.api.annotation.BOOL;
|
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
|
+import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.UserAuthenticationDto;
|
|
|
+import com.qmth.teachcloud.common.bean.result.LoginResult;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.enums.RoleTypeEnum;
|
|
|
import com.qmth.teachcloud.common.service.CacheService;
|
|
|
-import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
-import com.qmth.teachcloud.common.util.Result;
|
|
|
-import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
+import com.qmth.teachcloud.common.service.SysUserService;
|
|
|
+import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
+import com.qmth.teachcloud.common.util.*;
|
|
|
import com.qmth.teachcloud.report.aspect.ApiControllerAspect;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.annotations.ApiResponse;
|
|
|
-import io.swagger.annotations.ApiResponses;
|
|
|
+import com.qmth.teachcloud.report.business.cache.WhuUserAuthCacheUtil;
|
|
|
+import io.swagger.annotations.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@Api(tags = "武大开放接口层apiController")
|
|
@@ -42,6 +51,12 @@ public class WudaOpenApiController {
|
|
|
@Resource
|
|
|
CacheService cacheService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TeachcloudCommonService teachcloudCommonService;
|
|
|
+
|
|
|
@ApiOperation(value = "cas鉴权接口")
|
|
|
@RequestMapping(value = "/authentication", method = RequestMethod.GET)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
@@ -67,9 +82,59 @@ public class WudaOpenApiController {
|
|
|
if (Objects.isNull(uid)) {
|
|
|
throw ExceptionResultEnum.NOT_LOGIN.exception();
|
|
|
}
|
|
|
- BasicSchool basicSchool = cacheService.schoolCache(SystemConstant.SCHOOL_CODE);
|
|
|
+ UserAuthenticationDto userAuthenticationDto = new UserAuthenticationDto(uid, SystemConstant.getUuid());
|
|
|
+ WhuUserAuthCacheUtil.setAuthCode(userAuthenticationDto);
|
|
|
+ String pattern = "{0}{1}{2}";
|
|
|
+ String code = URLEncoder.encode(MessageFormat.format(pattern, userAuthenticationDto.getUid(), SignatureEntityTest.FIELD_JOINER, SignatureEntityTest.encrypt(userAuthenticationDto.getCode())), SystemConstant.CHARSET_NAME);
|
|
|
+ log.info("code:{}", code);
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
- response.sendRedirect(dictionaryConfig.sysDomain().getReportUrl() + basicSchool.getId() + "/" + uid);
|
|
|
+ response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + "/" + code);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "cas用户鉴权测试接口")
|
|
|
+ @RequestMapping(value = "/user/authentication/test", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
+ @Aac(auth = BOOL.FALSE)
|
|
|
+ public void userAuthenticationTest(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ String uid = "yz1";
|
|
|
+ UserAuthenticationDto userAuthenticationDto = new UserAuthenticationDto(uid, SystemConstant.getUuid());
|
|
|
+ WhuUserAuthCacheUtil.setAuthCode(userAuthenticationDto);
|
|
|
+ String pattern = "{0}{1}{2}";
|
|
|
+ String code = URLEncoder.encode(MessageFormat.format(pattern, userAuthenticationDto.getUid(), SignatureEntityTest.FIELD_JOINER, SignatureEntityTest.encrypt(userAuthenticationDto.getCode())), SystemConstant.CHARSET_NAME);
|
|
|
+ log.info("code:{}", code);
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + code);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "cas用户临时授权登录接口")
|
|
|
+ @RequestMapping(value = "/user/authentication/login", method = RequestMethod.POST)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = LoginResult.class)})
|
|
|
+ @Aac(auth = BOOL.FALSE)
|
|
|
+ public Result login(@ApiParam(value = "授权码信息", required = true) @RequestParam String code) throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
|
|
+ String[] values = StringUtils.split(URLDecoder.decode(code, SystemConstant.CHARSET_NAME), SignatureEntityTest.FIELD_JOINER);
|
|
|
+ if (Objects.isNull(values) || values.length != 2) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("临时授权码出错,请重新获取");
|
|
|
+ }
|
|
|
+ log.info("values:{}", JacksonUtil.parseJson(values));
|
|
|
+ QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.lambda().eq(SysUser::getLoginName, values[0]);
|
|
|
+ SysUser sysUser = sysUserService.getOne(wrapper);
|
|
|
+ //用户不存在
|
|
|
+ if (Objects.isNull(sysUser)) {
|
|
|
+ throw ExceptionResultEnum.USER_NO_DATA.exception();
|
|
|
+ }
|
|
|
+ //停用
|
|
|
+ if (!sysUser.getEnable()) {
|
|
|
+ throw ExceptionResultEnum.USER_ENABLE.exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ String userAuthCode = WhuUserAuthCacheUtil.getAuthCode(values[0]);
|
|
|
+ if (Objects.isNull(userAuthCode) || !Objects.equals(values[1], SignatureEntityTest.encrypt(userAuthCode))) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("临时授权码已过期");
|
|
|
+ }
|
|
|
+ LoginResult loginResult = teachcloudCommonService.login(sysUser.getPassword(), sysUser);
|
|
|
+ WhuUserAuthCacheUtil.deleteAuthCode(values[0]);
|
|
|
+ return ResultUtil.ok(loginResult);
|
|
|
}
|
|
|
|
|
|
// @ApiOperation(value = "cas鉴权接口")
|