From fca346254e458563ee0e951d571574a980865c02 Mon Sep 17 00:00:00 2001 From: owan Date: Tue, 12 Nov 2024 15:12:15 +0800 Subject: [PATCH 1/3] =?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(); From b4cfd0aaf6ea704e109c459c9427251e32a2006a Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Tue, 12 Nov 2024 17:36:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?=E9=82=B9=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=9AAPI=E5=85=A5=E5=8F=82=E5=87=BA=E5=8F=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=EF=BC=9A2024/11/12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys/plugin/api/PayBillApiSavePlugin.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java index db952ff..976e223 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/api/PayBillApiSavePlugin.java @@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; import kd.bos.openapi.api.plugin.ApiSavePlugin; import kd.bos.openapi.api.plugin.ApiSerializerPlugin; import kd.bos.openapi.api.plugin.SerializerResult; @@ -24,13 +26,14 @@ import java.util.Map; * @Date 2024/11/7 */ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin { + private static final Log logger = LogFactory.getLog(PayBillApiSavePlugin.class); private static final long serialVersionUID = 7055073356277386444L; private String shkd_businessid; private String shkd_businessnumber; @Override public List> preHandleRequestData(List> reqData) { - + logger.info("接口调用接口参数:{}", reqData); //付款处理 → 收款人ID payee → 付款银行.编码 payerbank_number payeetype 收款人类型 → payeenumber 收款人编码 //payeracctbank_number 付款银行账号.number @@ -51,6 +54,7 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin Object payeetype = map.get("payeetype");//如果是收款人类型 则为付款处理保存接口 Object payertype = map.get("payertype");//如果是付款人类型 则为收款处理保存接口 if (payeetype != null) { + logger.info("进入付款处理单API"); objectType = payeetype.toString(); objectNumber = map.get("payeenumber").toString(); fieldName1 = "payee"; @@ -58,12 +62,14 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin bankNumber = map.get("payeracctbank_number").toString(); fieldName2 = "payerbank_number"; DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); + logger.info("objectType:{},objectNumber:{}", objectType, objectNumber); DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); + logger.info("amAccountbank:{}", amAccountbank); map.put(fieldName1, dynamicObject.getString("id")); map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number")); } - if (payertype != null){ + if (payertype != null) { objectType = payertype.toString(); objectNumber = map.get("payernumber").toString(); fieldName1 = "payer"; @@ -71,7 +77,9 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin bankNumber = map.get("accountbank_number").toString(); fieldName2 = "payeebank_number"; DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(objectType, "id", new QFilter("billno", QCP.equals, objectNumber).toArray()); + logger.info("objectType:{},objectNumber:{}", objectType, objectNumber); DynamicObject amAccountbank = BusinessDataServiceHelper.loadSingle("am_accountbank", "id,bank,bank.number", new QFilter("number", QCP.equals, bankNumber).toArray()); + logger.info("amAccountbank:{}", amAccountbank); map.put(fieldName1, dynamicObject.getString("id")); map.put(fieldName2, amAccountbank.getDynamicObject("bank").getString("number")); } @@ -80,14 +88,17 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin // shkd_businessid // shkd_businessnumber // shkd_businessname + logger.info("最终处理 → 调用接口参数:{}", reqData); } return reqData; } @Override public SerializerResult serialize(Object response, String accept, String contentType) { + logger.info("进入serialize方法"); try { if (contentType.contains(MediaType.APPLICATION_JSON)) { + logger.info("进入if"); //返回text文本 String responseStr = new ObjectMapper().writeValueAsString(response); JSONObject jsonObject = JSON.parseObject(responseStr); @@ -100,13 +111,15 @@ public class PayBillApiSavePlugin implements ApiSavePlugin, ApiSerializerPlugin result.getJSONObject(0).put("shkd_businessnumber", shkd_businessnumber); return new SerializerResult(MediaType.TEXT_PLAIN, jsonObject.toJSONString()); } else { + logger.info("进入else"); //其他类型的出参序列化 return null; } } catch (JsonProcessingException e) { + logger.info("catch"); //处理异常时严禁抛出异常,可以定义自己的错误返回信息 - String result="..."; - return new SerializerResult(MediaType.TEXT_PLAIN,result); + String result = "..."; + return new SerializerResult(MediaType.TEXT_PLAIN, result); } } } From 0a44401a5ab2917e0530bbe269b22cc5b275e0c7 Mon Sep 17 00:00:00 2001 From: owan Date: Tue, 12 Nov 2024 18:10:49 +0800 Subject: [PATCH 3/3] =?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-=E9=87=8D=E5=AE=9A=E5=90=91EOSS=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shkd/sys/sys/eoss/SSOPluginLogin.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 4ea3f0f..0c6164d 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 @@ -40,7 +40,9 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { public void callTrdSSOLogin(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) { //认证中心的登录地址 logger.info(String.format("eoss_ip:%s,client_id:%s,client_secret:%s,重定向地址:%s",EOSS_IP,CLIENT_ID,CLIENT_SECRET,s)); + try { + String ssourl= EOSS_IP+"/service/SGE-project-sctz-master/pc/dist/login.html"; if (httpServletRequest.getRequestURI().contains("/auth/logout.do")){ String userName = UserServiceHelper.getCurrentUser("name").getString("name"); DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion"); @@ -49,14 +51,14 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { if (sessionId != null) { AuthService.logout(EOSS_IP, sessionId); } + }else{ + /** + *重定向的统一认证的地址 获取授权码 + */ + ssourl=String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&authType=0&redirect_uri=%s", + EOSS_IP,CLIENT_ID,s); + logger.info(String.format("重定向地址→sendRedirect:%s",ssourl)); } - - /** - *重定向的统一认证的地址 获取授权码 - */ - String ssourl=String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&authType=0&redirect_uri=%s", - EOSS_IP,CLIENT_ID,s); - logger.info(String.format("重定向地址→sendRedirect:%s",ssourl)); httpServletResponse.sendRedirect(ssourl); } catch (IOException e) { throw new RuntimeException(e);