From 459aa78c84cf552ebea6ef056d978c2531d71ac8 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期五, 06 三月 2026 17:14:27 +0800
Subject: [PATCH] 代码提交
---
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java | 93 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
index af9e233..b13fa65 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
@@ -2,9 +2,14 @@
import javax.annotation.Resource;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.utils.HttpUtil;
+import com.ruoyi.common.utils.RSAPublicKeyExample;
+import com.smartor.service.impl.ServiceSLTDHealthcareRecordServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -30,6 +35,9 @@
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* 鐧诲綍鏍¢獙鏂规硶
*
@@ -53,6 +61,21 @@
@Autowired
private ISysConfigService configService;
+ @Autowired
+ private RSAPublicKeyExample rsaPublicKeyExample;
+
+ @Value("${pri_key}")
+ private String priKey;
+
+ @Value("${isEncryp}")
+ private Integer isEncryp;
+
+ @Value("${sltd_pub_path}")
+ private String sltdPubPath;
+
+ @Value("${spring.profiles.active}")
+ private String active;
+
/**
* 鐧诲綍楠岃瘉
*
@@ -71,6 +94,7 @@
// 鐢ㄦ埛楠岃瘉
Authentication authentication = null;
try {
+ if (StringUtils.isEmpty(campusid)) campusid = "1";
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username + "&" + orgid + "&" + campusid, password);
AuthenticationContextHolder.setContext(authenticationToken);
// 璇ユ柟娉曚細鍘昏皟鐢║serDetailsServiceImpl.loadUserByUsername
@@ -94,6 +118,75 @@
}
+ /**
+ * SSO 鍗曠偣鐧诲綍涓氬姟澶勭悊
+ * <p>
+ * 1. 濡傛灉鏄� sltd 鐜锛屽厛閫氳繃 SSO token 鎹㈠彇鍛樺伐璐﹀彿
+ * 2. RSA 瑙e瘑 userName锛堣嫢寮�鍚姞瀵嗭級
+ * 3. 鏍规嵁 userName + orgid + deptId + campusid 鐢熸垚鐧诲綍 token
+ *
+ * @param userName 鐢ㄦ埛鍚嶏紙鍙兘涓虹┖锛屽鏋� sltd 妯″紡鍒欎粠 token 涓幏鍙栵級
+ * @param orgid 缁勭粐鏈烘瀯ID
+ * @param deptId 閮ㄩ棬ID
+ * @param campusid 鏍″尯 ID
+ * @param token SLTD SSO token锛堜粎 sltd 鐜涓嬩娇鐢級
+ * @return 鐧诲綍鎴愬姛鍚庣殑 JWT token锛屽け璐ヨ繑鍥� null
+ */
+ public String ssoLogin(String userName, String orgid, String deptId, String campusid, String token) {
+ // sltd 鐜锛氶�氳繃 SSO token 鑾峰彇鍛樺伐璐﹀彿
+ if ("sltd".equals(active)) {
+ userName = resolveUserNameBySltdToken(token);
+ if (userName == null) {
+ return null;
+ }
+ }
+
+ log.info("銆怱SO鐧诲綍銆憉serName={}", userName);
+
+ if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(orgid)) {
+ log.error("銆怱SO鐧诲綍銆戠敤鎴峰悕鎴栫粍缁囨満鏋勪笉鑳戒负绌�");
+ return null;
+ }
+
+ // RSA 瑙e瘑鐢ㄦ埛鍚�
+ if (isEncryp != null && isEncryp == 1) {
+ userName = rsaPublicKeyExample.decryptedData(userName, priKey);
+ }
+
+ if (StringUtils.isEmpty(deptId)) deptId = "null";
+ if (StringUtils.isEmpty(campusid)) campusid = "null";
+ return loginByUserName(userName + "&" + orgid + "&" + deptId + "&" + campusid);
+ }
+
+ /**
+ * 璋冪敤鐪佺珛鍚屽痉鎺ュ彛锛岄�氳繃 SSO token 鑾峰彇鍛樺伐璐﹀彿
+ *
+ * @param token SLTD SSO token
+ * @return 鍛樺伐璐﹀彿锛岄獙璇佸け璐ヨ繑鍥� null
+ */
+ private String resolveUserNameBySltdToken(String token) {
+ Map<String, String> headers = new HashMap<>();
+ headers.put("app-key", ServiceSLTDHealthcareRecordServiceImpl.APP_KEY);
+ Map<String, String> requestParams = new HashMap<>();
+ requestParams.put("token", token);
+ String reqData = HttpUtil.postFormRequest(sltdPubPath + "/checkSsoTokenId", requestParams, headers, null);
+ log.info("銆怱LTD token 楠岃瘉銆戝搷搴旂粨鏋滐細{}", reqData);
+
+ if (StringUtils.isEmpty(reqData)) {
+ log.error("銆怱LTD token 楠岃瘉銆戝搷搴斾负绌猴紝楠岃瘉澶辫触");
+ return null;
+ }
+
+ Map<String, Object> map = JSONObject.parseObject(reqData, Map.class);
+ if (ObjectUtils.isEmpty(map) || (Integer) map.get("code") != 200) {
+ log.error("銆怱LTD token 楠岃瘉銆戝搷搴旂爜寮傚父锛岄獙璇佸け璐�");
+ return null;
+ }
+
+ Map<String, Object> data = (Map<String, Object>) map.get("data");
+ return (String) data.get("accountNo");
+ }
+
public String loginByUserName(String userName) {
SysUser sysUser = userService.selectUserByUserNameAndDeptId(userName);
log.info("---------sysUser鐨勫�间负:{}", sysUser);
--
Gitblit v1.9.3