diff --git a/src/main/java/dev/flyfish/boot/cas/filter/CASFilter.java b/src/main/java/dev/flyfish/boot/cas/filter/CASFilter.java index f8c644d..4d30a09 100644 --- a/src/main/java/dev/flyfish/boot/cas/filter/CASFilter.java +++ b/src/main/java/dev/flyfish/boot/cas/filter/CASFilter.java @@ -120,7 +120,7 @@ public class CASFilter implements WebFilter { if (parameter.casServiceUrl != null) { serviceString = URLEncoder.encode(parameter.casServiceUrl, StandardCharsets.UTF_8); } else { - serviceString = computeService(context, parameter.casServerName); + serviceString = computeService(context, parameter.getFullServerUrl()); } if (log.isTraceEnabled()) { @@ -136,12 +136,11 @@ public class CASFilter implements WebFilter { * @param server 服务 * @return 结果 */ - public static String computeService(CASContext context, String server) { + public String computeService(CASContext context, String server) { if (log.isTraceEnabled()) { log.trace("entering getService({}, {})", context, server); } - if (server == null) { log.error("getService() argument \"server\" was illegally null."); throw new IllegalArgumentException("name of server is required"); @@ -149,13 +148,8 @@ public class CASFilter implements WebFilter { URI uri = context.getRequest().getURI(); - StringBuilder sb = new StringBuilder(); - if (server.startsWith("http")) { - sb.append(server); - } else { - sb.append(uri.getScheme()).append("://").append(server); - } - sb.append(uri.getPath()); + StringBuilder sb = new StringBuilder(server).append(uri.getPath()); + if (uri.getQuery() != null) { String query = uri.getQuery(); diff --git a/src/main/java/dev/flyfish/boot/cas/filter/CASParameter.java b/src/main/java/dev/flyfish/boot/cas/filter/CASParameter.java index a9827d6..9278e69 100644 --- a/src/main/java/dev/flyfish/boot/cas/filter/CASParameter.java +++ b/src/main/java/dev/flyfish/boot/cas/filter/CASParameter.java @@ -2,6 +2,7 @@ package dev.flyfish.boot.cas.filter; import com.fasterxml.jackson.annotation.JsonAlias; import lombok.Data; +import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; @@ -27,6 +28,8 @@ public class CASParameter { @JsonAlias(CASFilter.SERVERNAME_INIT_PARAM) String casServerName; + String casServerProtocol = "http"; + @JsonAlias(CASFilter.PROXY_CALLBACK_INIT_PARAM) String casProxyCallbackUrl; @@ -60,6 +63,13 @@ public class CASParameter { } } + public String getFullServerUrl() { + if (StringUtils.hasText(casServerName)) { + return casServerProtocol + "://" + casServerName; + } + return null; + } + /** * 检查配置参数是否有误 */ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 189d57d..3f2602b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,6 +9,8 @@ cas: filter: cas-login: https://sdsfzt.sxu.edu.cn/authserver/login cas-validate: https://sdsfzt.sxu.edu.cn/authserver/serviceValidate - cas-server-name: https://magnetic-first-yak.ngrok-free.app + cas-server-protocol: https + cas-server-name: magnetic-first-yak.ngrok-free.app cas-init-context-class: dev.flyfish.boot.cas.filter.CASLoginFilter + debug: true