單點登錄分兩套係統+待办跳转到待办页面

This commit is contained in:
wenlukang1 2025-06-24 17:27:00 +08:00
parent 8c5e4e88c7
commit 614ec9da4f
1 changed files with 56 additions and 28 deletions

View File

@ -16,7 +16,10 @@ import shkd.sys.sys.utils.AesUtils;
import javax.servlet.http.*; import javax.servlet.http.*;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.util.Base64;
/** /**
@ -44,7 +47,7 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
String secret; String secret;
String queryUrl = httpServletRequest.getQueryString(); String queryUrl = httpServletRequest.getQueryString();
String redirect = "http://10.1.7.83:8022/ierp/integration/yzjShareOpen.do?"+queryUrl;
if (queryUrl.contains("isNew")) { if (queryUrl.contains("isNew")) {
ip = EOSS_IP2; ip = EOSS_IP2;
client = CLIENT_ID2; client = CLIENT_ID2;
@ -54,29 +57,39 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
client = CLIENT_ID; client = CLIENT_ID;
secret = CLIENT_SECRET; secret = CLIENT_SECRET;
} }
//认证中心的登录地址 if(queryUrl.contains("code")){
logger.info(String.format("eoss_ip:%s,client_id:%s,client_secret:%s,重定向地址:%s", ip, client, secret, s)); // httpServletResponse.sendRedirect(ssourl);
try {
}else{
queryUrl = Base64.getEncoder().encodeToString(queryUrl.getBytes(StandardCharsets.UTF_8));
// String skIp = httpServletRequest.getRemoteAddr();
String skUrl = httpServletRequest.getRequestURL().toString();
skUrl = skUrl.substring(0, skUrl.indexOf("ierp"));
String redirect = skUrl+"ierp/index.html?param="+queryUrl;
//认证中心的登录地址
logger.info(String.format("eoss_ip:%s,client_id:%s,client_secret:%s,重定向地址:%s", ip, client, secret, s));
String ssourl = ip + "/service/SGE-project-sctz-master/pc/dist/login.html"; String ssourl = ip + "/service/SGE-project-sctz-master/pc/dist/login.html";
if (httpServletRequest.getRequestURI().contains("/auth/logout.do")) {
String userName = UserServiceHelper.getCurrentUser("name").getString("name"); try {
DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion"); if (httpServletRequest.getRequestURI().contains("/auth/logout.do")) {
String userKey = "user_sessionId_" + userName; // 构造一个唯一的键 String userName = UserServiceHelper.getCurrentUser("name").getString("name");
String sessionId = cache.get(userKey); DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion");
if (sessionId != null) { String userKey = "user_sessionId_" + userName; // 构造一个唯一的键
AuthService.logout(ip, sessionId); String sessionId = cache.get(userKey);
if (sessionId != null) {
AuthService.logout(ip, sessionId);
}
} else {
//重定向的统一认证的地址 获取授权码
ssourl = String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&sessionKeep=false&authType=0&redirect_uri=%s",
ip, client, redirect);
logger.info(String.format("重定向地址→sendRedirect%s", ssourl));
} }
} else { httpServletResponse.sendRedirect(ssourl);
/* } catch (IOException e) {
*重定向的统一认证的地址 获取授权码 throw new RuntimeException(e);
*/
ssourl = String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&authType=0&redirect_uri=%s",
ip, client, s);
logger.info(String.format("重定向地址→sendRedirect%s", ssourl));
} }
httpServletResponse.sendRedirect(ssourl);
} catch (IOException e) {
throw new RuntimeException(e);
} }
} }
@ -98,22 +111,37 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
client = CLIENT_ID; client = CLIENT_ID;
secret = CLIENT_SECRET; secret = CLIENT_SECRET;
} }
//返回的认证结果 //返回的认证结果
UserAuthResult result = new UserAuthResult(); UserAuthResult result = new UserAuthResult();
//获取返回的授权码 //获取返回的授权码
String code = httpServletRequest.getParameter("code"); String code = httpServletRequest.getParameter("code");
//获取返回的 sessionId String param = httpServletRequest.getParameter("param");
String sessionId = httpServletRequest.getParameter("sessionId"); if(param!=null){
String userName = httpServletRequest.getParameter("userName"); byte[] decodedBytes = Base64.getDecoder().decode(param);
if (userName != null) { String paramString = new String(decodedBytes, StandardCharsets.UTF_8);
userName = userName.replace(" ", "+"); // 将空格替换为 + try {
httpServletResponse.sendRedirect(httpServletRequest.getRequestURI()+"?"+paramString+"&code="+code);
} catch (IOException e) {
throw new RuntimeException(e);
}
result.setSucess(false);
return result;
} }
logger.info("获取待办链接中参数userName:" + userName);
// //获取返回的 sessionId
// String sessionId = httpServletRequest.getParameter("sessionId");
// String userName = httpServletRequest.getParameter("userName");
// if (userName != null) {
// userName = userName.replace(" ", "+"); // 将空格替换为 +
// }
// logger.info("获取待办链接中参数userName:" + userName);
// RSAUtils. // RSAUtils.
logger.info(String.format("getTrdSSOAuth→授权码code%s", code)); logger.info(String.format("getTrdSSOAuth→授权码code%s", code));
result.setUserType(UserProperType.UserName); result.setUserType(UserProperType.UserName);
if (StringUtils.isEmpty(code) && StringUtils.isEmpty(userName)) { if (StringUtils.isEmpty(code)) {
logger.error("getTrdSSOAuth→授权码code为空"); logger.error("getTrdSSOAuth→授权码code为空");
result.setSucess(false); result.setSucess(false);
return result; return result;