This commit is contained in:
李靖 2024-05-24 15:44:29 +08:00
parent cb68498723
commit e79705cb98
1 changed files with 31 additions and 11 deletions

View File

@ -5,6 +5,9 @@ import java.util.Arrays;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 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.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.bos.login.thirdauth.ThirdSSOAuthHandler; import kd.bos.login.thirdauth.ThirdSSOAuthHandler;
@ -26,7 +29,7 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler {
private String service; private String service;
private boolean encodeServiceUrl; private boolean encodeServiceUrl;
private String casSeverLoginUrl; private String casSeverLoginUrl;
Cas10TicketValidator ticketValidator; Cas10TicketValidator ticketValidator10;
private AuthenticationRedirectStrategy authenticationRedirectStrategy; private AuthenticationRedirectStrategy authenticationRedirectStrategy;
public SSOLoginPugin() { public SSOLoginPugin() {
@ -84,19 +87,36 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler {
String ticket = this.retrieveTicketFromRequest(request); String ticket = this.retrieveTicketFromRequest(request);
if (CommonUtils.isNotBlank(ticket)) { if (CommonUtils.isNotBlank(ticket)) {
try { try {
logger.info(String.format("Attempting to validate ticket: %s", ticket));
logger.debug(String.format("Attempting to validate ticket: %s", ticket)); logger.debug(String.format("Attempting to validate ticket: %s", ticket));
if (this.ticketValidator == null) { String service2 = this.constructServiceUrl(request, response);
this.ticketValidator = new Cas10TicketValidator(this.casSeverLoginUrl); 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; if (tempXml != null) {
Assertion assertion = this.ticketValidator.validate(ticket, this.constructServiceUrl(request, response)); JSONObject user = XML.toJSONObject(tempXml);
logger.debug(String.format("Successfully authenticated user: %s", assertion.getPrincipal().getName())); String username = user.getJSONObject("cas:serviceResponse")
if (assertion != null) { .getJSONObject("cas:authenticationSuccess").getStr("cas:user");
userName = assertion.getPrincipal().getName(); if(username != null){
result.setUser(userName); result.setUser(username);
result.setSucess(true); 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) { } catch (Exception var7) {
logger.error(var7); logger.error(var7);
} }