|
@@ -0,0 +1,102 @@
|
|
|
+package com.qmth.sxufe.api;
|
|
|
+
|
|
|
+import com.qmth.boot.api.annotation.Aac;
|
|
|
+import com.qmth.boot.api.annotation.BOOL;
|
|
|
+import com.qmth.boot.api.constant.ApiConstant;
|
|
|
+import com.qmth.sxufe.utils.CasUtils;
|
|
|
+import com.qmth.sxufe.utils.Constants;
|
|
|
+import com.qmth.teachcloud.exchange.common.contant.SystemConstant;
|
|
|
+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 io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiResponse;
|
|
|
+import io.swagger.annotations.ApiResponses;
|
|
|
+import net.psctech.sso.filter.LoginFilter;
|
|
|
+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.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 山西财经大学开放接口前端控制器
|
|
|
+ * </p>
|
|
|
+ */
|
|
|
+@Api(tags = "山西财经大学开放接口Controller")
|
|
|
+@RestController
|
|
|
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_OPEN)
|
|
|
+@Validated
|
|
|
+public class OpenApiController {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(OpenApiController.class);
|
|
|
+ private static final String schoolCode = "sxufe";//测试学校code,山西财经大学
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ CommonService commonService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ AuthInfoService authInfoService;
|
|
|
+
|
|
|
+ @Value("${cas.config.logoutUrl}")
|
|
|
+ String logoutUrl;
|
|
|
+
|
|
|
+ @ApiOperation(value = "cas鉴权接口")
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
+ @RequestMapping(value = "/authentication", method = RequestMethod.GET)
|
|
|
+ @Aac(auth = BOOL.FALSE)
|
|
|
+ public void authentication(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ authInfoService.appHasExpired(schoolCode);
|
|
|
+
|
|
|
+ Object object = session.getAttribute(LoginFilter.CONST_CAS_USERNAME);
|
|
|
+ if (object != null) {
|
|
|
+ String targetUrl = CasUtils.getTargetUrl(request);
|
|
|
+ // 跳转到知学知考
|
|
|
+ response.sendRedirect(targetUrl);
|
|
|
+ } else {
|
|
|
+ // 返回登录页
|
|
|
+ String loginUrl = Constants.CAS_LOGIN_URL;
|
|
|
+ response.sendRedirect(loginUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "cas鉴权退出接口")
|
|
|
+ @RequestMapping(value = "/authentication/logout", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
+ @Aac(auth = BOOL.FALSE)
|
|
|
+ public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ authInfoService.appHasExpired(schoolCode);
|
|
|
+ //注销本系统session
|
|
|
+ session.invalidate();
|
|
|
+ //跳转至注销后地址
|
|
|
+ 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();
|
|
|
+ String userName = "";
|
|
|
+ Object object = session.getAttribute(LoginFilter.CONST_CAS_USERNAME);
|
|
|
+ if (object != null) {
|
|
|
+ userName = object.toString();
|
|
|
+ commonService.redirectLogic(userName, schoolCode, logoutUrl, null);
|
|
|
+ } else {
|
|
|
+ response.sendRedirect(Constants.CAS_LOGIN_URL);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|