From fca346254e458563ee0e951d571574a980865c02 Mon Sep 17 00:00:00 2001 From: owan Date: Tue, 12 Nov 2024 15:12:15 +0800 Subject: [PATCH] =?UTF-8?q?EOSS-=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shkd/sys/sys/eoss/AuthService.java | 11 +++++++ .../shkd/sys/sys/eoss/SSOPluginLogin.java | 30 ++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/AuthService.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/AuthService.java index 42ca4e2..be7be55 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/AuthService.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/AuthService.java @@ -83,4 +83,15 @@ public class AuthService { } return null; } + + public static void logout(String eoss_ip,String session_id){ + String url = String.format("%s/sso2/authCenter/logout", eoss_ip); + // 构建 URL,添加查询参数 + String urlWithParams = UriComponentsBuilder.fromHttpUrl(url) + .queryParam("sessionId", session_id) + .toUriString(); // 生成带参数的完整 URL + + ResponseEntity response = restTemplate.exchange(urlWithParams, HttpMethod.GET,null, String.class); + logger.info(String.format("logout→返回结果:%s",response.getBody())); + } } diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/SSOPluginLogin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/SSOPluginLogin.java index 6c3714c..4ea3f0f 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/SSOPluginLogin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/eoss/SSOPluginLogin.java @@ -2,12 +2,18 @@ package shkd.sys.sys.eoss; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import kd.bos.cache.CacheFactory; +import kd.bos.cache.DistributeSessionlessCache; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.login.thirdauth.ThirdSSOAuthHandler; import kd.bos.login.thirdauth.UserAuthResult; import kd.bos.login.thirdauth.UserProperType; +import kd.bos.servicehelper.user.UserServiceHelper; import org.apache.commons.lang3.StringUtils; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -35,9 +41,18 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { //认证中心的登录地址 logger.info(String.format("eoss_ip:%s,client_id:%s,client_secret:%s,重定向地址:%s",EOSS_IP,CLIENT_ID,CLIENT_SECRET,s)); try { - //重定向的统一认证的地址 + if (httpServletRequest.getRequestURI().contains("/auth/logout.do")){ + String userName = UserServiceHelper.getCurrentUser("name").getString("name"); + DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion"); + String userKey = "user_sessionId_" + userName; // 构造一个唯一的键 + String sessionId = cache.get(userKey); + if (sessionId != null) { + AuthService.logout(EOSS_IP, sessionId); + } + } + /** - * 获取授权码 + *重定向的统一认证的地址 获取授权码 */ String ssourl=String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&authType=0&redirect_uri=%s", EOSS_IP,CLIENT_ID,s); @@ -61,9 +76,11 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { UserAuthResult result=new UserAuthResult(); //获取返回的授权码 String code = httpServletRequest.getParameter("code"); - logger.info(String.format("getTrdSSOAuth→code:%s",code)); + //获取返回的 sessionId + String sessionId = httpServletRequest.getParameter("sessionId"); + logger.info(String.format("getTrdSSOAuth→授权码code:%s",code)); if (StringUtils.isEmpty(code)){ - logger.error("getTrdSSOAuth→code为空"); + logger.error("getTrdSSOAuth→授权码code为空"); result.setSucess(false); }else { try { @@ -81,6 +98,11 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { result.setUser(user); result.setSucess(true); logger.info("SSO用户登录成功,进入苍穹系统"); + + String userKey = "user_sessionId_" + user; // 构造一个唯一的键 + DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion"); + cache.put(userKey,sessionId);//将自定义参数加入缓存 + } } catch (Exception e) { e.printStackTrace();