|
@@ -2,21 +2,28 @@ package com.qmth.teachcloud.cas.util;
|
|
|
|
|
|
import com.qmth.teachcloud.cas.util.gdpu.CasUtils;
|
|
import com.qmth.teachcloud.cas.util.gdpu.CasUtils;
|
|
import com.qmth.teachcloud.cas.util.gdpu.Constants;
|
|
import com.qmth.teachcloud.cas.util.gdpu.Constants;
|
|
|
|
+import com.qmth.teachcloud.exchange.common.bean.dto.syssetting.SimpleObject;
|
|
|
|
+import com.qmth.teachcloud.exchange.common.bean.params.OpenParams;
|
|
import com.qmth.teachcloud.exchange.common.bean.params.RedirectParams;
|
|
import com.qmth.teachcloud.exchange.common.bean.params.RedirectParams;
|
|
import com.qmth.teachcloud.exchange.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.exchange.common.contant.SystemConstant;
|
|
|
|
+import com.qmth.teachcloud.exchange.common.entity.BasicSchool;
|
|
import com.qmth.teachcloud.exchange.common.service.AuthInfoService;
|
|
import com.qmth.teachcloud.exchange.common.service.AuthInfoService;
|
|
|
|
+import com.qmth.teachcloud.exchange.common.service.CommonCacheService;
|
|
|
|
+import com.qmth.teachcloud.exchange.common.util.JacksonUtil;
|
|
import com.qmth.teachcloud.exchange.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.exchange.common.util.ServletUtil;
|
|
-import net.psctech.sso.filter.LoginFilter;
|
|
|
|
|
|
+import org.ly.uap.client.authentication.AttributePrincipal;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpSession;
|
|
import javax.servlet.http.HttpSession;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.net.URLEncoder;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 广东药科大学cas工具类
|
|
* @Description: 广东药科大学cas工具类
|
|
@@ -27,16 +34,23 @@ import java.net.URLEncoder;
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
public class GdpuCasUtil {
|
|
public class GdpuCasUtil {
|
|
- private static final Logger log = LoggerFactory.getLogger(CdutCasUtil.class);
|
|
|
|
- private String teachcloudLoginUrl = null, logoutUrl = null, returnUrl = null;
|
|
|
|
- private static final String LOGIN_BEFORE_XJU_LOGIC_API = "/api/admin/print/open/login_before_xju_logic";//西交大登录之前逻辑
|
|
|
|
- private static final String ACCESS_TOKEN_URL = "http://org.xjtu.edu.cn/openplatform/oauth/getAccessToken";
|
|
|
|
- private static final String USER_INFO_URL = "http://org.xjtu.edu.cn/openplatform/oauth/open/getUserInfo";
|
|
|
|
- private static final String LOGOUT_URL = "http://org.xjtu.edu.cn/openplatform/oauth/logout";
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(GdpuCasUtil.class);
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
AuthInfoService authInfoService;
|
|
AuthInfoService authInfoService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ CommonCacheService commonCacheService;
|
|
|
|
+
|
|
|
|
+ // @Value("${cas.config.logoutUrl}")
|
|
|
|
+// String logoutUrl;
|
|
|
|
+//
|
|
|
|
+// @Value("${cas.config.returnUrl}")
|
|
|
|
+// String returnUrl;
|
|
|
|
+//
|
|
|
|
+// @Value("${cas.config.teachcloudPrintLoginUrl}")
|
|
|
|
+// String teachcloudLoginUrl;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 广东药科大学登录逻辑
|
|
* 广东药科大学登录逻辑
|
|
*
|
|
*
|
|
@@ -44,27 +58,44 @@ public class GdpuCasUtil {
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public void authentication(String schoolCode) throws IOException {
|
|
|
|
|
|
+ public RedirectParams authentication(String schoolCode) throws IOException {
|
|
HttpServletRequest request = ServletUtil.getRequest();
|
|
HttpServletRequest request = ServletUtil.getRequest();
|
|
- HttpSession session = request.getSession();
|
|
|
|
- HttpServletResponse response = ServletUtil.getResponse();
|
|
|
|
authInfoService.appHasExpired(schoolCode);
|
|
authInfoService.appHasExpired(schoolCode);
|
|
|
|
|
|
- Object object = session.getAttribute(LoginFilter.CONST_CAS_USERNAME);
|
|
|
|
- log.info("cas:authentication:object:{}", object);
|
|
|
|
- if (object != null) {
|
|
|
|
- String targetUrl = CasUtils.getTargetUrl(request);
|
|
|
|
- log.info("cas:authentication:targetUrl:{}", targetUrl);
|
|
|
|
- // 跳转到知学知考
|
|
|
|
- response.setHeader("Access-Control-Allow-Origin", SystemConstant.PATH_MATCH);
|
|
|
|
- response.sendRedirect(targetUrl);
|
|
|
|
- } else {
|
|
|
|
- // 返回登录页
|
|
|
|
- String loginUrl = URLEncoder.encode(Constants.CAS_BASE_PATH, Constants.UTF_8_STR);
|
|
|
|
- log.info("cas:authentication:loginUrl:{}", loginUrl);
|
|
|
|
- response.setHeader("Access-Control-Allow-Origin", SystemConstant.PATH_MATCH);
|
|
|
|
- response.sendRedirect(loginUrl);
|
|
|
|
|
|
+ BasicSchool basicSchool = commonCacheService.schoolCache(schoolCode);
|
|
|
|
+ Objects.requireNonNull(basicSchool, "学校信息不存在");
|
|
|
|
+
|
|
|
|
+ OpenParams openParams = null;
|
|
|
|
+ String employeeNo = null, returnUrl = null;
|
|
|
|
+ Map<String, SimpleObject> mapSetting = commonCacheService.getSysSetting(basicSchool.getId());
|
|
|
|
+ if (!CollectionUtils.isEmpty(mapSetting)) {
|
|
|
|
+ SimpleObject simpleObject = mapSetting.get(Constants.CAS_ADDRESS);
|
|
|
|
+ Objects.requireNonNull(simpleObject, "未配置单点登录地址");
|
|
|
|
+ String casAddress = simpleObject.getValue();
|
|
|
|
+ if (Objects.nonNull(casAddress) && !Objects.equals(casAddress.trim(), "")) {
|
|
|
|
+ if (casAddress.lastIndexOf("/") == casAddress.length() - 1) {
|
|
|
|
+ casAddress = casAddress.substring(0, casAddress.lastIndexOf("/"));
|
|
|
|
+ }
|
|
|
|
+ returnUrl = casAddress + Constants.SSO_LOGOUT_URI;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
|
+ log.info("principal.getName():{}", principal.getName());
|
|
|
|
+ log.info("principal.getAttributes():{}", JacksonUtil.parseJson(principal.getAttributes()));
|
|
|
|
+ if (principal != null) {
|
|
|
|
+ //获取用户信息中公开的Attributes部分
|
|
|
|
+ Map<String, Object> map = principal.getAttributes();
|
|
|
|
+ // 获取姓名,可以根据属性名称获取其他属性
|
|
|
|
+ employeeNo = (String) map.get("username");
|
|
|
|
+ String realname = (String) map.get("realname");
|
|
|
|
+ log.info("employeeNo:{}", employeeNo);
|
|
|
|
+ log.info("realname:{}", realname);
|
|
|
|
+ log.info("schoolCode:{}", schoolCode);
|
|
|
|
+ log.info("returnUrl:{}", returnUrl);
|
|
|
|
+ openParams = new OpenParams();
|
|
|
|
+ openParams.setName(realname);
|
|
}
|
|
}
|
|
|
|
+ return new RedirectParams(employeeNo, schoolCode, returnUrl, openParams);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -80,29 +111,45 @@ public class GdpuCasUtil {
|
|
authInfoService.appHasExpired(schoolCode);
|
|
authInfoService.appHasExpired(schoolCode);
|
|
//注销本系统session
|
|
//注销本系统session
|
|
session.invalidate();
|
|
session.invalidate();
|
|
- log.info("cas:logout:logoutUrl:{}", CasUtils.getLogoutUrl(request));
|
|
|
|
- //跳转至注销后地址
|
|
|
|
- response.setHeader("Access-Control-Allow-Origin", SystemConstant.PATH_MATCH);
|
|
|
|
- response.sendRedirect(CasUtils.getLogoutUrl(request));
|
|
|
|
- }
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * 知学登录
|
|
|
|
- *
|
|
|
|
- * @param schoolCode
|
|
|
|
- * @return
|
|
|
|
- * @throws IOException
|
|
|
|
- */
|
|
|
|
- public RedirectParams zxzkLogin(String schoolCode) throws IOException {
|
|
|
|
- HttpServletRequest request = ServletUtil.getRequest();
|
|
|
|
- HttpSession session = request.getSession();
|
|
|
|
- String userName = "";
|
|
|
|
- Object object = session.getAttribute(LoginFilter.CONST_CAS_USERNAME);
|
|
|
|
- RedirectParams redirectParams = null;
|
|
|
|
- if (object != null) {
|
|
|
|
- userName = object.toString();
|
|
|
|
- redirectParams = new RedirectParams(userName, schoolCode, logoutUrl, null);
|
|
|
|
|
|
+ BasicSchool basicSchool = commonCacheService.schoolCache(schoolCode);
|
|
|
|
+ Objects.requireNonNull(basicSchool, "学校信息不存在");
|
|
|
|
+
|
|
|
|
+ Map<String, SimpleObject> mapSetting = commonCacheService.getSysSetting(basicSchool.getId());
|
|
|
|
+ SimpleObject simpleObject = mapSetting.get(Constants.SCHOOL_SERVICE_ADDRESS);
|
|
|
|
+ if (!CollectionUtils.isEmpty(mapSetting)) {
|
|
|
|
+ Objects.requireNonNull(simpleObject, "未配置学校cas地址");
|
|
|
|
+ String schoolServiceAddress = simpleObject.getValue();
|
|
|
|
+ if (Objects.nonNull(schoolServiceAddress) && !Objects.equals(schoolServiceAddress.trim(), "")) {
|
|
|
|
+ if (schoolServiceAddress.lastIndexOf("/") == schoolServiceAddress.length() - 1) {
|
|
|
|
+ schoolServiceAddress = schoolServiceAddress.substring(0, schoolServiceAddress.lastIndexOf("/"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ log.info("cas:logout:logoutUrl:{}", CasUtils.getLogoutUrl(schoolServiceAddress));
|
|
|
|
+ //跳转至注销后地址
|
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", SystemConstant.PATH_MATCH);
|
|
|
|
+ response.sendRedirect(CasUtils.getLogoutUrl(schoolServiceAddress));
|
|
}
|
|
}
|
|
- return redirectParams;
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// /**
|
|
|
|
+// * 知学登录
|
|
|
|
+// *
|
|
|
|
+// * @param schoolCode
|
|
|
|
+// * @return
|
|
|
|
+// * @throws IOException
|
|
|
|
+// */
|
|
|
|
+// public RedirectParams zxzkLogin(String schoolCode) throws IOException {
|
|
|
|
+// String logoutUrl = null;
|
|
|
|
+// HttpServletRequest request = ServletUtil.getRequest();
|
|
|
|
+// HttpSession session = request.getSession();
|
|
|
|
+// String userName = "";
|
|
|
|
+// Object object = session.getAttribute(LoginFilter.CONST_CAS_USERNAME);
|
|
|
|
+// RedirectParams redirectParams = null;
|
|
|
|
+// if (object != null) {
|
|
|
|
+// userName = object.toString();
|
|
|
|
+// redirectParams = new RedirectParams(userName, schoolCode, logoutUrl, null);
|
|
|
|
+// }
|
|
|
|
+// return redirectParams;
|
|
|
|
+// }
|
|
}
|
|
}
|