feat: 优化代码

This commit is contained in:
wangyu 2024-10-12 22:48:42 +08:00
parent 34aa45f799
commit ac46f7e57b
4 changed files with 27 additions and 56 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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) {
}

View File

@ -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();
}