|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.boot.tools.signature.SignatureEntity;
|
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
@@ -16,6 +17,7 @@ import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.sync.CloudMarkingTaskUtils;
|
|
|
import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
+import org.apache.commons.text.StringEscapeUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -25,6 +27,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -50,8 +53,11 @@ public class SsoServiceImpl implements SsoService {
|
|
|
@Resource
|
|
|
SysOrgService sysOrgService;
|
|
|
|
|
|
- @Value("${cas.config.questionLoginUrl}")
|
|
|
- String questionLoginUrl;
|
|
|
+ @Value("${cas.config.questionLoginUri}")
|
|
|
+ String questionLoginUri;
|
|
|
+
|
|
|
+ @Value("${cas.config.questionHostUrl}")
|
|
|
+ String questionHostUrl;
|
|
|
|
|
|
@Resource
|
|
|
SysRoleService sysRoleService;
|
|
@@ -125,21 +131,25 @@ public class SsoServiceImpl implements SsoService {
|
|
|
Optional.ofNullable(sysUserRole).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户没有该角色"));
|
|
|
|
|
|
if (role == RoleTypeEnum.PRESIDENT || role == RoleTypeEnum.TEACHER) {
|
|
|
- List<SysOrg> sysOrgList = sysOrgService.findByConnectByParentId(sysUserCas.getOrgId(), false, true);
|
|
|
- if (CollectionUtils.isEmpty(sysOrgList)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到学院信息");
|
|
|
- } else {
|
|
|
- List<SysOrg> sysOrgSchool = sysOrgList.stream().filter(s -> s.getType() == OrgTypeEnum.SCHOOL).collect(Collectors.toList());
|
|
|
- if (!CollectionUtils.isEmpty(sysOrgSchool)) {
|
|
|
- for (SysOrg s : sysOrgList) {
|
|
|
- if (Objects.nonNull(s.getParentId()) && s.getParentId().longValue() == sysOrgSchool.get(0).getId().longValue()) {
|
|
|
- orgName = s.getName();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("未找到顶级学校信息");
|
|
|
- }
|
|
|
+// List<SysOrg> sysOrgList = sysOrgService.findByConnectByParentId(sysUserCas.getOrgId(), false, true);
|
|
|
+ SysOrg sysOrg = sysOrgService.findCollegeLevelOrgByOrgId(sysUserCas.getOrgId());
|
|
|
+// if (CollectionUtils.isEmpty(sysOrgList)) {
|
|
|
+// throw ExceptionResultEnum.ERROR.exception("未找到学院信息");
|
|
|
+// } else {
|
|
|
+// List<SysOrg> sysOrgSchool = sysOrgList.stream().filter(s -> s.getType() == OrgTypeEnum.SCHOOL).collect(Collectors.toList());
|
|
|
+// if (!CollectionUtils.isEmpty(sysOrgSchool)) {
|
|
|
+// for (SysOrg s : sysOrgList) {
|
|
|
+// if (Objects.nonNull(s.getParentId()) && s.getParentId().longValue() == sysOrgSchool.get(0).getId().longValue()) {
|
|
|
+// orgName = s.getName();
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// throw ExceptionResultEnum.ERROR.exception("未找到顶级学校信息");
|
|
|
+// }
|
|
|
+// }
|
|
|
+ if (Objects.isNull(sysOrg)){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未找到顶级机构");
|
|
|
}
|
|
|
} else if (role == RoleTypeEnum.OFFICE_TEACHER && Objects.nonNull(sysUserCas.getOrgId())) {
|
|
|
SysOrg sysOrg = commonCacheService.orgCache(sysUserCas.getOrgId());
|
|
@@ -170,6 +180,7 @@ public class SsoServiceImpl implements SsoService {
|
|
|
|
|
|
hostUrl = SystemConstant.getLocalFileHost(hostUrl);
|
|
|
map.put("redirectUrl", hostUrl + dictionaryConfig.reportOpenDomain().getSsoLoginApi());
|
|
|
+ System.out.println(JSON.toJSONString(map));
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -184,7 +195,7 @@ public class SsoServiceImpl implements SsoService {
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String, Object> questionLibraryLogin(String loginName, RoleTypeEnum role, String returnUrl, String params) throws IOException {
|
|
|
+ public Map<String, Object> questionLibraryLogin(String loginName,String realName, RoleTypeEnum role, String returnUrl, String params) throws IOException {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
|
|
|
|
|
@@ -205,16 +216,11 @@ public class SsoServiceImpl implements SsoService {
|
|
|
SysUserRole sysUserRole = sysUserRoleService.getOne(sysUserRoleQueryWrapper);
|
|
|
Optional.ofNullable(sysUserRole).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户没有该角色"));
|
|
|
|
|
|
- //TODO 题库推送用户逻辑
|
|
|
-
|
|
|
- //TODO 拼装redirectUrl
|
|
|
- if (questionLoginUrl.contains(SystemConstant.PATH_MATCH)) {
|
|
|
- questionLoginUrl = questionLoginUrl.replace(SystemConstant.PATH_MATCH, basicSchool.getCode());
|
|
|
- }
|
|
|
-
|
|
|
long timestamp = System.currentTimeMillis();
|
|
|
- String path = questionLoginUrl.substring(questionLoginUrl.indexOf(SystemConstant.PATH_SUBSTR), questionLoginUrl.length());
|
|
|
+ String questionLoginUrl = questionHostUrl + questionLoginUri;
|
|
|
+ String path = questionLoginUri;
|
|
|
String signature = SignatureEntity.build(SignatureType.SECRET, SystemConstant.GET, path, timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
|
|
|
+ signature = URLEncoder.encode(signature,"utf-8");
|
|
|
|
|
|
StringJoiner stringJoiner = new StringJoiner("")
|
|
|
.add(questionLoginUrl)
|
|
@@ -232,8 +238,8 @@ public class SsoServiceImpl implements SsoService {
|
|
|
stringJoiner = stringJoiner.add(SystemConstant.GET_SYMBOL).add(SystemConstant.PARAMS).add(SystemConstant.GET_EQUAL).add(JacksonUtil.parseJson(openParams));
|
|
|
map.computeIfAbsent(SystemConstant.PARAMS, v -> JacksonUtil.parseJson(openParams));
|
|
|
}
|
|
|
-
|
|
|
map.computeIfAbsent("loginName", v -> loginName);
|
|
|
+ map.computeIfAbsent("realName", v -> realName);
|
|
|
map.computeIfAbsent("role", v -> role);
|
|
|
map.computeIfAbsent("returnUrl", v -> returnUrl);
|
|
|
map.put("redirectUrl", stringJoiner.toString());
|