EOSS-退出登录代码完善

This commit is contained in:
owan 2024-11-12 15:12:15 +08:00
parent 0b924c9cd7
commit fca346254e
2 changed files with 37 additions and 4 deletions

View File

@ -83,4 +83,15 @@ public class AuthService {
} }
return null; 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<String> response = restTemplate.exchange(urlWithParams, HttpMethod.GET,null, String.class);
logger.info(String.format("logout→返回结果:%s",response.getBody()));
}
} }

View File

@ -2,12 +2,18 @@ package shkd.sys.sys.eoss;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import kd.bos.cache.CacheFactory;
import kd.bos.cache.DistributeSessionlessCache;
import kd.bos.logging.Log; import kd.bos.logging.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.bos.login.thirdauth.ThirdSSOAuthHandler; import kd.bos.login.thirdauth.ThirdSSOAuthHandler;
import kd.bos.login.thirdauth.UserAuthResult; import kd.bos.login.thirdauth.UserAuthResult;
import kd.bos.login.thirdauth.UserProperType; import kd.bos.login.thirdauth.UserProperType;
import kd.bos.servicehelper.user.UserServiceHelper;
import org.apache.commons.lang3.StringUtils; 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.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 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)); logger.info(String.format("eoss_ip:%s,client_id:%s,client_secret:%s,重定向地址:%s",EOSS_IP,CLIENT_ID,CLIENT_SECRET,s));
try { 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", String ssourl=String.format("%s/sso2/authCenter/authorize?client_id=%s&response_type=code&authType=0&redirect_uri=%s",
EOSS_IP,CLIENT_ID,s); EOSS_IP,CLIENT_ID,s);
@ -61,9 +76,11 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
UserAuthResult result=new UserAuthResult(); UserAuthResult result=new UserAuthResult();
//获取返回的授权码 //获取返回的授权码
String code = httpServletRequest.getParameter("code"); 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)){ if (StringUtils.isEmpty(code)){
logger.error("getTrdSSOAuth→code为空"); logger.error("getTrdSSOAuth→授权码code为空");
result.setSucess(false); result.setSucess(false);
}else { }else {
try { try {
@ -81,6 +98,11 @@ public class SSOPluginLogin implements ThirdSSOAuthHandler {
result.setUser(user); result.setUser(user);
result.setSucess(true); result.setSucess(true);
logger.info("SSO用户登录成功进入苍穹系统"); logger.info("SSO用户登录成功进入苍穹系统");
String userKey = "user_sessionId_" + user; // 构造一个唯一的键
DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache("customRegion");
cache.put(userKey,sessionId);//将自定义参数加入缓存
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();