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 0302ffc..fe52102 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 @@ -50,10 +50,18 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { client = CLIENT_ID; secret = CLIENT_SECRET; } - if(queryUrl.contains("code")){ -// httpServletResponse.sendRedirect(ssourl); - - + String ssourl = ip + "/service/SGE-project-sctz-master/pc/dist/login.html"; + //图标登录到首页 + if(!queryUrl.contains("yzjShareOpen.do")){ + try { + //重定向的统一认证的地址 获取授权码 + ssourl = String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&sessionKeep=true&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); + } }else{ queryUrl = Base64.getEncoder().encodeToString(queryUrl.getBytes(StandardCharsets.UTF_8)); // String skIp = httpServletRequest.getRemo @@ -62,13 +70,12 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { String redirect = skUrl+"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"; 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 userKey = "user_sessionId_" + userName; // 构造存储sessionId的键 String sessionId = cache.get(userKey); if (sessionId != null) { AuthService.logout(ip, sessionId); @@ -104,33 +111,34 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler { client = CLIENT_ID; secret = CLIENT_SECRET; } - //返回的认证结果 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→sessionId:%s", sessionId)); //调用EOSS获取token接口 String access_token = AuthService.accessToken(code, ip, client, secret); logger.info(String.format("accessToken返回数据:%s", access_token)); //调用EOSS获取用户信息接口 String user = AuthService.getUserInfo(access_token, ip, client, secret); logger.info(String.format("getUserInfo返回数据:%s", user)); - String userKey = "user_sessionId_" + user; - DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion"); - cache.put(userKey, sessionId); String param = httpServletRequest.getParameter("param"); //解码 if(param!=null){ byte[] decodedBytes = Base64.getDecoder().decode(param); String paramString = new String(decodedBytes, StandardCharsets.UTF_8); try { - //二次重定向到待办页面,并且去除EOSS返回的sessionId + //获取返回的 sessionId + String sessionId = httpServletRequest.getParameter("sessionId"); + logger.info(String.format("getTrdSSOAuth→sessionId:%s", sessionId)); + String userKey = "user_sessionId_" + user; + //存储sessionId用于退出系统 + DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion"); + cache.put(userKey, sessionId); + //二次重定向到待办页面,并且不携带EOSS返回的sessionId httpServletResponse.sendRedirect(httpServletRequest.getRequestURI()+"?"+paramString+"&code="+code); } catch (IOException e) { + logger.error("二次重定向到待办页面异常!"+e.getMessage()); throw new RuntimeException(e); } result.setSucess(false);