diff --git a/shkd-cosmic-debug/src/main/java/shkd/plugin/SSOLoginPugin.java b/shkd-cosmic-debug/src/main/java/shkd/plugin/SSOLoginPugin.java index e9763b5..a1dfe00 100644 --- a/shkd-cosmic-debug/src/main/java/shkd/plugin/SSOLoginPugin.java +++ b/shkd-cosmic-debug/src/main/java/shkd/plugin/SSOLoginPugin.java @@ -5,6 +5,9 @@ import java.util.Arrays; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import cn.hutool.http.HttpRequest; +import cn.hutool.json.JSONObject; +import cn.hutool.json.XML; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.login.thirdauth.ThirdSSOAuthHandler; @@ -26,7 +29,7 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler { private String service; private boolean encodeServiceUrl; private String casSeverLoginUrl; - Cas10TicketValidator ticketValidator; + Cas10TicketValidator ticketValidator10; private AuthenticationRedirectStrategy authenticationRedirectStrategy; public SSOLoginPugin() { @@ -84,19 +87,36 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler { String ticket = this.retrieveTicketFromRequest(request); if (CommonUtils.isNotBlank(ticket)) { try { + logger.info(String.format("Attempting to validate ticket: %s", ticket)); logger.debug(String.format("Attempting to validate ticket: %s", ticket)); - if (this.ticketValidator == null) { - this.ticketValidator = new Cas10TicketValidator(this.casSeverLoginUrl); - } + String service2 = this.constructServiceUrl(request, response); + logger.info(String.format("Attempting to validate service2: %s", service2)); + logger.debug(String.format("Attempting to validate service2: %s", service2)); + String tempXml = HttpRequest.post("https://oa-uat.elmleaf.com.cn/sso/proxyValidate") + .contentType("application/x-www-form-urlencoded") + .form("ticket",ticket) + .form("service", service2).execute().body(); - String userName = null; - Assertion assertion = this.ticketValidator.validate(ticket, this.constructServiceUrl(request, response)); - logger.debug(String.format("Successfully authenticated user: %s", assertion.getPrincipal().getName())); - if (assertion != null) { - userName = assertion.getPrincipal().getName(); - result.setUser(userName); - result.setSucess(true); + if (tempXml != null) { + JSONObject user = XML.toJSONObject(tempXml); + String username = user.getJSONObject("cas:serviceResponse") + .getJSONObject("cas:authenticationSuccess").getStr("cas:user"); + if(username != null){ + result.setUser(username); + result.setSucess(true); + } } + //if (this.ticketValidator == null) { + // this.ticketValidator = new Cas11TicketValidator(this.casSeverLoginUrl); + //} + //String userName = null; + //Assertion assertion = this.ticketValidator.validate2(ticket, this.constructServiceUrl(request, response)); + //logger.debug(String.format("Successfully authenticated user: %s", assertion.getPrincipal().getName())); + //if (assertion != null) { + // userName = assertion.getPrincipal().getName(); + // result.setUser(userName); + // result.setSucess(true); + //} } catch (Exception var7) { logger.error(var7); }