|
@@ -1,26 +1,29 @@
|
|
|
package com.qmth.cdut.api;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.qmth.boot.api.annotation.Aac;
|
|
|
import com.qmth.boot.api.annotation.BOOL;
|
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
|
import com.qmth.cdut.supwisdom.CasUtils;
|
|
|
import com.qmth.cdut.supwisdom.Constants;
|
|
|
import com.qmth.cdut.supwisdom.LoginUser;
|
|
|
+import com.qmth.cdut.supwisdom.utils.HttpRequestUtils;
|
|
|
import com.qmth.teachcloud.exchange.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.exchange.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.exchange.common.service.AuthInfoService;
|
|
|
import com.qmth.teachcloud.exchange.common.service.CommonService;
|
|
|
import com.qmth.teachcloud.exchange.common.util.Result;
|
|
|
import com.qmth.teachcloud.exchange.common.util.ServletUtil;
|
|
|
-import io.swagger.annotations.*;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiResponse;
|
|
|
+import io.swagger.annotations.ApiResponses;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
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;
|
|
@@ -30,7 +33,6 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Objects;
|
|
|
-import java.util.StringJoiner;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -54,44 +56,25 @@ public class OpenApiController {
|
|
|
@Value("${cas.config.logoutUrl}")
|
|
|
String logoutUrl;
|
|
|
|
|
|
- @Value("${cas.config.returnUrl}")
|
|
|
- String returnUrl;
|
|
|
-
|
|
|
@ApiOperation(value = "成都理工大学cas鉴权接口")
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
@RequestMapping(value = "/authentication", method = RequestMethod.GET)
|
|
|
@Aac(auth = BOOL.FALSE)
|
|
|
- public void sso(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ public void authentication(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
HttpSession session = request.getSession();
|
|
|
String targetUrl = CasUtils.getTargetUrl(request);
|
|
|
authInfoService.appHasExpired(schoolCode);
|
|
|
if (CasUtils.isLogin(session)) {
|
|
|
- LoginUser loginUser = (LoginUser) session.getAttribute(Constants.LOGIN_USER_KEY);
|
|
|
- String account = loginUser.getAccount();
|
|
|
-
|
|
|
- String sessionId = session.getId();
|
|
|
- if (StringUtils.isNotBlank(sessionId)) {
|
|
|
- StringJoiner stringJoiner = new StringJoiner("");
|
|
|
- stringJoiner.add(logoutUrl).add(SystemConstant.GET_UNKNOWN).add("sessionId")
|
|
|
- .add(SystemConstant.GET_EQUAL).add(sessionId);
|
|
|
- returnUrl = stringJoiner.toString();
|
|
|
- } else {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("sessionId为空");
|
|
|
- }
|
|
|
- commonService.redirectLogic(account, schoolCode, returnUrl, null);
|
|
|
+ response.sendRedirect(targetUrl);
|
|
|
} else {
|
|
|
if (CasUtils.hasTicket(request)) {
|
|
|
LoginUser loginUser = CasUtils.getLoginUser(request);
|
|
|
- if (loginUser.isLogin() && doLogin(loginUser, request)) {
|
|
|
+ if (loginUser.isLogin()) {
|
|
|
CasUtils.login(loginUser, session);
|
|
|
-
|
|
|
- String account = loginUser.getAccount();
|
|
|
- commonService.redirectLogic(account, schoolCode, returnUrl, null);
|
|
|
+ response.sendRedirect(targetUrl);
|
|
|
} else {
|
|
|
String loginUrl = CasUtils.getLoginUrl(request);
|
|
|
response.sendRedirect(loginUrl);
|
|
|
- // TODO 可选:业务系统可根据实际情况进行处理
|
|
|
-// response.sendRedirect(CasUtils.getErrorUrl(request));
|
|
|
}
|
|
|
} else {
|
|
|
String loginUrl = CasUtils.getLoginUrl(request);
|
|
@@ -104,26 +87,37 @@ public class OpenApiController {
|
|
|
@RequestMapping(value = "/authentication/logout", method = RequestMethod.GET)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
@Aac(auth = BOOL.FALSE)
|
|
|
- public void logout(@ApiParam(value = "sessionId", required = true) @RequestParam String sessionId) throws IOException {
|
|
|
+ public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
if (Objects.isNull(logoutUrl) || Objects.equals(logoutUrl, "")) {
|
|
|
throw ExceptionResultEnum.PARAMS_ERROR.exception("鉴权退出地址不存在");
|
|
|
}
|
|
|
- if (Objects.isNull(sessionId) || Objects.equals(sessionId, "")) {
|
|
|
- throw ExceptionResultEnum.PARAMS_ERROR.exception("sessionId为空");
|
|
|
- }
|
|
|
authInfoService.appHasExpired(schoolCode);
|
|
|
-
|
|
|
- HttpServletRequest request = ServletUtil.getRequest();
|
|
|
- HttpServletResponse response = ServletUtil.getResponse();
|
|
|
if (doLogout(request)) {
|
|
|
HttpSession session = request.getSession();
|
|
|
CasUtils.logout(session);
|
|
|
response.sendRedirect(CasUtils.getLogoutUrl(request));
|
|
|
} else {
|
|
|
- response.sendRedirect(CasUtils.getLoginUrl(request));
|
|
|
+ response.sendRedirect(CasUtils.getLogoutUrl(request));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "跳转知学知考")
|
|
|
+ @RequestMapping(value = "/zxzk_login", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
+ @Aac(auth = BOOL.FALSE)
|
|
|
+ public void zxzkLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ if (CasUtils.isLogin(session)) {
|
|
|
+ LoginUser loginUser = (LoginUser) session.getAttribute(Constants.LOGIN_USER_KEY);
|
|
|
+ String account = loginUser.getAccount();
|
|
|
+ commonService.redirectLogic(account, schoolCode, logoutUrl, null);
|
|
|
+ } else {
|
|
|
+ String loginUrl = CasUtils.getLoginUrl(request);
|
|
|
+ response.sendRedirect(loginUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public boolean doLogin(LoginUser loginUser, HttpServletRequest request) {
|
|
|
HttpSession session = request.getSession();
|
|
|
ServletContext application = session.getServletContext();
|