fix(gateway): Spring 6.2 + Base64 API migrations (ResponseCookie, statusCode, encodeToString, orElseThrow, effectively-final)
CodeQL Advanced / Analyze (actions) (push) Canceled after 0s
CodeQL Advanced / Analyze (java-kotlin) (push) Canceled after 0s
CodeQL Advanced / Analyze (javascript-typescript) (push) Canceled after 0s
CodeQL Advanced / Analyze (python) (push) Canceled after 0s
Docker Image Build & Push / manifest (push) Canceled after 0s
Docker Image Build & Push / build-and-push-arm (push) Canceled after 0s
Docker Image Build & Push / build-and-push-amd (push) Canceled after 0s
Gateway Docker Image CI / Build and Push Gateway Docker Image (push) Canceled after 0s

- CasdoorOauthController: stateCookie -> ResponseCookie (HttpCookie.builder removed in 6.2),
  B64URL encoder/decoder split, encodeBytes -> encodeToString
- CasdoorClient: resp.status() -> resp.statusCode()
- CasdoorIdTokenVerifier: Optional.orElseThrow in map (type witness), no ternary+Mono.error
- CasdoorUserService: throw instead of Mono.error inside fromCallable (type inference)
- AuthFilter: effectively-final local for lambda capture
This commit is contained in:
figmar
2026-08-31 04:15:58 +08:00
parent 9b8f96c877
commit 7fcef906de
5 changed files with 17 additions and 16 deletions
@@ -90,10 +90,11 @@ public class AuthFilter implements GlobalFilter, Ordered {
ssoUser = request.getHeaders().getFirst("X-User-Name");
}
if (StringUtils.isNotBlank(ssoUser)) {
final String ssoUserFinal = ssoUser;
log.info("SSO mode detected, adding User header: {}", ssoUser);
ServerHttpRequest mutatedRequest = request.mutate()
.headers(httpHeaders -> {
httpHeaders.set(USER_HEADER, ssoUser);
httpHeaders.set(USER_HEADER, ssoUserFinal);
})
.build();
ServerWebExchange mutatedExchange = exchange.mutate()
@@ -122,7 +122,7 @@ public class CasdoorClient {
}
private Mono<String> errorBody(ClientResponse resp) {
return resp.bodyToMono(String.class).defaultIfEmpty(resp.status().toString());
return resp.bodyToMono(String.class).defaultIfEmpty(resp.statusCode().toString());
}
private static String enc(String s) {
@@ -119,11 +119,10 @@ public class CasdoorIdTokenVerifier {
"id_token kid not found in JWKS after refresh"));
}
return loadKeys(true)
.flatMap(k2 -> Optional.ofNullable(parseWithKid(idToken, k2)))
.flatMap(o2 -> o2.isPresent()
? Mono.just(o2.get())
: Mono.error(new CasdoorIdTokenException(
"id_token kid not found in JWKS after refresh")));
.map(k2 -> Optional.ofNullable(parseWithKid(idToken, k2)))
.map(o2 -> o2.<CasdoorIdTokenException>orElseThrow(() ->
new CasdoorIdTokenException(
"id_token kid not found in JWKS after refresh")));
});
}
@@ -62,8 +62,7 @@ public class CasdoorUserService {
User user = findByUsername(username);
if (user != null) {
if (!user.isEnabled()) {
return Mono.error(new CasdoorProvisionException(
"local user disabled: " + username));
throw new CasdoorProvisionException("local user disabled: " + username);
}
user.setLastLoginAt(now);
if (hasText(claims.email()) && !claims.email().equals(user.getEmail())) {
@@ -74,8 +73,8 @@ public class CasdoorUserService {
return new ProvisionedUser(user, userService.generateToken(user), false);
}
if (!props.isAutoProvision()) {
return Mono.error(new CasdoorProvisionException(
"local user not found and auto-provision disabled: " + username));
throw new CasdoorProvisionException(
"local user not found and auto-provision disabled: " + username);
}
User created = createUser(claims, username, now);
try {
@@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -64,6 +65,7 @@ public class CasdoorOauthController {
private static final SecureRandom RANDOM = new SecureRandom();
private static final Base64.Encoder B64URL = Base64.getUrlEncoder().withoutPadding();
private static final Base64.Decoder B64URL_DEC = Base64.getUrlDecoder();
private final CasdoorProperties props;
private final CasdoorClient casdoorClient;
@@ -75,8 +77,8 @@ public class CasdoorOauthController {
public Mono<ResponseEntity<Void>> login(@RequestParam(name = "next", required = false) String next,
ServerWebExchange exchange) {
String safeNext = sanitizeNext(next);
String state = B64URL.encodeBytes(randomBytes(32));
String cookieValue = state + "." + B64URL.encodeBytes(safeNext.getBytes(StandardCharsets.UTF_8));
String state = B64URL.encodeToString(randomBytes(32));
String cookieValue = state + "." + B64URL.encodeToString(safeNext.getBytes(StandardCharsets.UTF_8));
exchange.getResponse().addCookie(
stateCookie(cookieValue, Duration.ofSeconds(props.getStateTtlSeconds())));
@@ -184,7 +186,7 @@ public class CasdoorOauthController {
private static String decodeNext(String encoded) {
try {
return new String(B64URL.decode(encoded), StandardCharsets.UTF_8);
return new String(B64URL_DEC.decode(encoded), StandardCharsets.UTF_8);
} catch (IllegalArgumentException e) {
return "/";
}
@@ -201,8 +203,8 @@ public class CasdoorOauthController {
return cookie == null ? null : cookie.getValue();
}
private HttpCookie stateCookie(String value, Duration maxAge) {
HttpCookie.Builder builder = HttpCookie.builder(props.getStateCookieName());
private ResponseCookie stateCookie(String value, Duration maxAge) {
ResponseCookie.ResponseCookieBuilder builder = ResponseCookie.from(props.getStateCookieName());
if (value != null) {
builder.value(value);
}