From ac46f7e57b21a8f7e2de8f8f12eb443f06c94105 Mon Sep 17 00:00:00 2001 From: wangyu Date: Sat, 12 Oct 2024 22:48:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flyfish/boot/cas/context/CASReceipt.java | 4 +- .../cas/validator/ProxyTicketValidator.java | 2 +- .../flyfish/boot/cas/validator/SecureURL.java | 6 +- .../cas/validator/ServiceTicketValidator.java | 71 ++++++------------- 4 files changed, 27 insertions(+), 56 deletions(-) diff --git a/src/main/java/dev/flyfish/boot/cas/context/CASReceipt.java b/src/main/java/dev/flyfish/boot/cas/context/CASReceipt.java index f500664..b2d774a 100644 --- a/src/main/java/dev/flyfish/boot/cas/context/CASReceipt.java +++ b/src/main/java/dev/flyfish/boot/cas/context/CASReceipt.java @@ -36,7 +36,7 @@ public class CASReceipt implements Serializable { log.trace("entering getReceipt(ProxyTicketValidator=[" + ptv + "])"); } - if (!ptv.isAuthenticationSuccesful()) { + if (!ptv.isAuthenticationSuccessful()) { try { ptv.validate(); } catch (Exception e) { @@ -46,7 +46,7 @@ public class CASReceipt implements Serializable { } } - if (!ptv.isAuthenticationSuccesful()) { + if (!ptv.isAuthenticationSuccessful()) { log.error("validation of [" + ptv + "] was not successful."); throw new CASAuthenticationException("Unable to validate ProxyTicketValidator [" + ptv + "]"); } else { diff --git a/src/main/java/dev/flyfish/boot/cas/validator/ProxyTicketValidator.java b/src/main/java/dev/flyfish/boot/cas/validator/ProxyTicketValidator.java index a044a6c..36c8204 100644 --- a/src/main/java/dev/flyfish/boot/cas/validator/ProxyTicketValidator.java +++ b/src/main/java/dev/flyfish/boot/cas/validator/ProxyTicketValidator.java @@ -24,7 +24,7 @@ public class ProxyTicketValidator extends ServiceTicketValidator { pv.validate(); System.out.println(pv.getResponse()); System.out.println(); - if (pv.isAuthenticationSuccesful()) { + if (pv.isAuthenticationSuccessful()) { System.out.println("user: " + pv.getUser()); System.out.println("proxies:\n " + pv.getProxyList()); } else { diff --git a/src/main/java/dev/flyfish/boot/cas/validator/SecureURL.java b/src/main/java/dev/flyfish/boot/cas/validator/SecureURL.java index 5665743..a7ba238 100644 --- a/src/main/java/dev/flyfish/boot/cas/validator/SecureURL.java +++ b/src/main/java/dev/flyfish/boot/cas/validator/SecureURL.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; public class SecureURL { private static final Log log = LogFactory.getLog(SecureURL.class); @@ -40,12 +41,11 @@ public class SecureURL { output.write(chByte); } - String var7 = output.toString("utf-8"); - return var7; + return output.toString(StandardCharsets.UTF_8); } finally { try { if (r != null) { - ((BufferedReader) r).close(); + r.close(); } } catch (IOException var14) { } diff --git a/src/main/java/dev/flyfish/boot/cas/validator/ServiceTicketValidator.java b/src/main/java/dev/flyfish/boot/cas/validator/ServiceTicketValidator.java index 8dd2e08..2c8b265 100644 --- a/src/main/java/dev/flyfish/boot/cas/validator/ServiceTicketValidator.java +++ b/src/main/java/dev/flyfish/boot/cas/validator/ServiceTicketValidator.java @@ -1,6 +1,7 @@ package dev.flyfish.boot.cas.validator; import lombok.Getter; +import lombok.Setter; import lombok.ToString; import org.xml.sax.Attributes; import org.xml.sax.InputSource; @@ -15,16 +16,26 @@ import java.io.StringReader; @ToString public class ServiceTicketValidator { + @Getter + @Setter private String casValidateUrl; + @Getter + @Setter private String proxyCallbackUrl; private String st; + @Setter private String service; + @Getter private String pgtIou; + @Getter private String user; + @Getter private String errorCode; + @Getter private String errorMessage; private String entireResponse; private String ss; + @Setter @Getter private boolean renew = false; private boolean attemptedAuthentication; @@ -43,7 +54,7 @@ public class ServiceTicketValidator { sv.validate(); System.out.println(sv.getResponse()); System.out.println(); - if (sv.isAuthenticationSuccesful()) { + if (sv.isAuthenticationSuccessful()) { System.out.println("user: " + sv.getUser()); System.out.println("pgtIou: " + sv.getPgtIou()); } else { @@ -53,54 +64,14 @@ public class ServiceTicketValidator { } - public void setCasValidateUrl(String x) { - this.casValidateUrl = x; - } - - public String getCasValidateUrl() { - return this.casValidateUrl; - } - - public void setProxyCallbackUrl(String x) { - this.proxyCallbackUrl = x; - } - - public void setRenew(boolean b) { - this.renew = b; - } - - public String getProxyCallbackUrl() { - return this.proxyCallbackUrl; - } - public void setServiceTicket(String x) { this.st = x; } - public void setService(String x) { - this.service = x; - } - - public String getUser() { - return this.user; - } - - public String getPgtIou() { - return this.pgtIou; - } - - public boolean isAuthenticationSuccesful() { + public boolean isAuthenticationSuccessful() { return this.successfulAuthentication; } - public String getErrorMessage() { - return this.errorMessage; - } - - public String getErrorCode() { - return this.errorCode; - } - public String getResponse() { return this.entireResponse; } @@ -109,7 +80,7 @@ public class ServiceTicketValidator { if (this.casValidateUrl != null && this.st != null) { this.clear(); this.attemptedAuthentication = true; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(this.casValidateUrl); if (this.casValidateUrl.indexOf(63) == -1) { sb.append('?'); @@ -117,9 +88,9 @@ public class ServiceTicketValidator { sb.append('&'); } - sb.append("service=" + this.service + "&ticket=" + this.st); + sb.append("service=").append(this.service).append("&ticket=").append(this.st); if (this.proxyCallbackUrl != null) { - sb.append("&pgtUrl=" + this.proxyCallbackUrl); + sb.append("&pgtUrl=").append(this.proxyCallbackUrl); } if (this.renew) { @@ -170,9 +141,9 @@ public class ServiceTicketValidator { public void startElement(String ns, String ln, String qn, Attributes a) { this.currentText = new StringBuffer(); - if (qn.equals("cas:authenticationSuccess")) { + if (qn.equals(AUTHENTICATION_SUCCESS)) { this.authenticationSuccess = true; - } else if (qn.equals("cas:authenticationFailure")) { + } else if (qn.equals(AUTHENTICATION_FAILURE)) { this.authenticationFailure = true; this.errorCode = a.getValue("code"); if (this.errorCode != null) { @@ -188,14 +159,14 @@ public class ServiceTicketValidator { public void endElement(String ns, String ln, String qn) throws SAXException { if (this.authenticationSuccess) { - if (qn.equals("cas:user")) { + if (qn.equals(USER)) { ServiceTicketValidator.this.user = this.currentText.toString().trim(); } - if (qn.equals("cas:proxyGrantingTicket")) { + if (qn.equals(PROXY_GRANTING_TICKET)) { this.pgtIou = this.currentText.toString().trim(); } - } else if (this.authenticationFailure && qn.equals("cas:authenticationFailure")) { + } else if (this.authenticationFailure && qn.equals(AUTHENTICATION_FAILURE)) { this.errorMessage = this.currentText.toString().trim(); }