feat: 优化模式

This commit is contained in:
wangyu 2024-10-12 17:17:02 +08:00
parent 8202f4ad05
commit 34aa45f799
3 changed files with 17 additions and 11 deletions

View File

@ -120,7 +120,7 @@ public class CASFilter implements WebFilter {
if (parameter.casServiceUrl != null) { if (parameter.casServiceUrl != null) {
serviceString = URLEncoder.encode(parameter.casServiceUrl, StandardCharsets.UTF_8); serviceString = URLEncoder.encode(parameter.casServiceUrl, StandardCharsets.UTF_8);
} else { } else {
serviceString = computeService(context, parameter.casServerName); serviceString = computeService(context, parameter.getFullServerUrl());
} }
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
@ -136,12 +136,11 @@ public class CASFilter implements WebFilter {
* @param server 服务 * @param server 服务
* @return 结果 * @return 结果
*/ */
public static String computeService(CASContext context, String server) { public String computeService(CASContext context, String server) {
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
log.trace("entering getService({}, {})", context, server); log.trace("entering getService({}, {})", context, server);
} }
if (server == null) { if (server == null) {
log.error("getService() argument \"server\" was illegally null."); log.error("getService() argument \"server\" was illegally null.");
throw new IllegalArgumentException("name of server is required"); throw new IllegalArgumentException("name of server is required");
@ -149,13 +148,8 @@ public class CASFilter implements WebFilter {
URI uri = context.getRequest().getURI(); URI uri = context.getRequest().getURI();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder(server).append(uri.getPath());
if (server.startsWith("http")) {
sb.append(server);
} else {
sb.append(uri.getScheme()).append("://").append(server);
}
sb.append(uri.getPath());
if (uri.getQuery() != null) { if (uri.getQuery() != null) {
String query = uri.getQuery(); String query = uri.getQuery();

View File

@ -2,6 +2,7 @@ package dev.flyfish.boot.cas.filter;
import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonAlias;
import lombok.Data; import lombok.Data;
import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -27,6 +28,8 @@ public class CASParameter {
@JsonAlias(CASFilter.SERVERNAME_INIT_PARAM) @JsonAlias(CASFilter.SERVERNAME_INIT_PARAM)
String casServerName; String casServerName;
String casServerProtocol = "http";
@JsonAlias(CASFilter.PROXY_CALLBACK_INIT_PARAM) @JsonAlias(CASFilter.PROXY_CALLBACK_INIT_PARAM)
String casProxyCallbackUrl; String casProxyCallbackUrl;
@ -60,6 +63,13 @@ public class CASParameter {
} }
} }
public String getFullServerUrl() {
if (StringUtils.hasText(casServerName)) {
return casServerProtocol + "://" + casServerName;
}
return null;
}
/** /**
* 检查配置参数是否有误 * 检查配置参数是否有误
*/ */

View File

@ -9,6 +9,8 @@ cas:
filter: filter:
cas-login: https://sdsfzt.sxu.edu.cn/authserver/login cas-login: https://sdsfzt.sxu.edu.cn/authserver/login
cas-validate: https://sdsfzt.sxu.edu.cn/authserver/serviceValidate 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 cas-init-context-class: dev.flyfish.boot.cas.filter.CASLoginFilter
debug: true debug: true