|
@@ -12,28 +12,32 @@ 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.service.SysUserService;
|
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
-import com.qmth.teachcloud.common.util.*;
|
|
|
-import com.qmth.teachcloud.report.aspect.ApiControllerAspect;
|
|
|
+import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
+import com.qmth.teachcloud.common.util.Result;
|
|
|
+import com.qmth.teachcloud.common.util.ResultUtil;
|
|
|
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.validation.BindingResult;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import javax.validation.Valid;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
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")
|
|
@@ -69,6 +73,21 @@ public class WudaOpenApiController {
|
|
|
response.sendRedirect(dictionaryConfig.sysDomain().getReportUrl() + basicSchool.getId() + "/" + uid);
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "cas鉴权退出接口")
|
|
|
+ @RequestMapping(value = "/authentication/logout", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
+ @Aac(auth = BOOL.FALSE)
|
|
|
+ public void authenticationLogout(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ log.info("logout is come in:{}");
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ session.invalidate();
|
|
|
+ String casLogoutURL = "http://cas.whu.edu.cn/authserver/logout";
|
|
|
+ // service后面带的参数为应用的访问地址,需要使用URLEncoder进行编码
|
|
|
+ String redirectURL = casLogoutURL + "?service=" + URLEncoder.encode("http://cas.whu.edu.cn/authserver/login", SystemConstant.CHARSET_NAME);
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ response.sendRedirect(redirectURL);
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation(value = "cas用户鉴权接口")
|
|
|
@RequestMapping(value = "/user/authentication", method = RequestMethod.GET)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
@@ -79,9 +98,13 @@ 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用户鉴权测试接口")
|
|
@@ -92,19 +115,22 @@ public class WudaOpenApiController {
|
|
|
String uid = "yz1";
|
|
|
UserAuthenticationDto userAuthenticationDto = new UserAuthenticationDto(uid, SystemConstant.getUuid());
|
|
|
WhuUserAuthCacheUtil.setAuthCode(userAuthenticationDto);
|
|
|
- String PATTERN = "{0}{1}{2}";
|
|
|
- String code = MessageFormat.format(PATTERN, userAuthenticationDto.getUid(), SignatureEntityTest.FIELD_JOINER, SignatureEntityTest.encrypt(userAuthenticationDto.getCode()));
|
|
|
+ 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() + code);
|
|
|
+ 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 {
|
|
|
- String[] values = StringUtils.split(code, SignatureEntityTest.FIELD_JOINER);
|
|
|
+ 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]);
|