From 4d94388e69f5c4720669bd3551d8a5785af27d71 Mon Sep 17 00:00:00 2001
From: Rodolphe Prin <rodolphe.prin@univ-lr.fr>
Date: Tue, 10 Nov 2026 13:45:03 +0000
Subject: [PATCH] Fix compilation against Keycloak 26.8.2 (OAuth2Code userId)
---
src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java | 34 ++++++++++++++++++++++++++--------
1 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java b/src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java
index f510ebe..73d0aae 100644
--- a/src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java
+++ b/src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java
@@ -18,6 +18,7 @@
import org.keycloak.services.managers.UserSessionCrossDCManager;
import org.keycloak.services.util.DefaultClientSessionContext;
+import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HexFormat;
@@ -185,8 +186,6 @@
throw new CASValidationException(CASErrorCode.INVALID_SERVICE, "Ticket was not issued for this service", Response.Status.BAD_REQUEST);
}
- clientSession.setNote(CASLoginProtocol.SESSION_TICKET, ticket);
-
if (requireReauth && AuthenticationManager.isSSOAuthentication(clientSession)) {
event.error(Errors.SESSION_EXPIRED);
throw new CASValidationException(CASErrorCode.INVALID_TICKET, "Interactive authentication was requested but not performed", Response.Status.BAD_REQUEST);
@@ -225,19 +224,33 @@
throw new CASValidationException(CASErrorCode.INVALID_TICKET, "Session not active", Response.Status.BAD_REQUEST);
}
+ // Single logout refers to the service ticket the client session was established with
+ if (prefix.equals(CASLoginProtocol.SERVICE_TICKET_PREFIX)) {
+ clientSession.setNote(CASLoginProtocol.SESSION_TICKET, ticket);
+ }
}
protected void createProxyGrant(String pgtUrl) {
- if ( RedirectUtils.verifyRedirectUri(session, pgtUrl, client) == null ) {
+ String verifiedPgtUrl = RedirectUtils.verifyRedirectUri(session, pgtUrl, client);
+ if (verifiedPgtUrl == null) {
event.error(Errors.INVALID_REQUEST);
throw new CASValidationException(CASErrorCode.INVALID_PROXY_CALLBACK, "Proxy callback is invalid", Response.Status.BAD_REQUEST);
}
+ // The callback receives a PGT, so require HTTPS unless the realm's "Require SSL" setting allows plain HTTP for the host
+ URI pgtUri = URI.create(verifiedPgtUrl);
+ boolean isHttps = "https".equalsIgnoreCase(pgtUri.getScheme());
+ boolean isHttp = "http".equalsIgnoreCase(pgtUri.getScheme());
+ if (pgtUri.getHost() == null || !(isHttps || (isHttp && !realm.getSslRequired().isRequired(pgtUri.getHost())))) {
+ event.error(Errors.INVALID_REQUEST);
+ throw new CASValidationException(CASErrorCode.INVALID_PROXY_CALLBACK, "Proxy callback must use HTTPS", Response.Status.BAD_REQUEST);
+ }
+
String pgtIou = getPGTIOU();
- String pgtId = getPGT(session, clientSession, pgtUrl);
+ String pgtId = getPGT(session, clientSession, verifiedPgtUrl);
try {
- HttpGet request = new HttpGet(new URIBuilder(pgtUrl).setParameter("pgtIou",pgtIou).setParameter("pgtId",pgtId).build());
+ HttpGet request = new HttpGet(new URIBuilder(verifiedPgtUrl).setParameter("pgtIou",pgtIou).setParameter("pgtId",pgtId).build());
request.setConfig(PGT_CALLBACK_REQUEST_CONFIG);
HttpClient httpClient = session.getProvider(HttpClientProvider.class).getHttpClient();
@@ -307,7 +320,7 @@
{
String key = UUID.randomUUID().toString();
UserSessionModel userSession = clientSession.getUserSession();
- OAuth2Code codeData = new OAuth2Code(key, clientSession.getClient().getId(), Time.currentTime() + userSession.getRealm().getAccessCodeLifespan(), null, null, null, redirectUriParam, null, null, null, userSession.getId());
+ OAuth2Code codeData = new OAuth2Code(key, clientSession.getClient().getId(), Time.currentTime() + userSession.getRealm().getAccessCodeLifespan(), null, null, null, redirectUriParam, null, null, null, userSession.getId(), userSession.getUser().getId());
session.singleUseObjects().put(prefix + key, clientSession.getUserSession().getRealm().getAccessCodeLifespan(), codeData.serializeCode());
return prefix + key + "--" + hexEncode(clientSession.getUserSession().getId()) + "--" + clientSession.getClient().getId();
}
@@ -317,7 +330,12 @@
}
private String hexDecode(String hex) {
- byte[] bytes = HexFormat.of().parseHex(hex);
- return new String(bytes, StandardCharsets.US_ASCII);
+ try {
+ byte[] bytes = HexFormat.of().parseHex(hex);
+ return new String(bytes, StandardCharsets.US_ASCII);
+ } catch (IllegalArgumentException e) {
+ event.error(Errors.INVALID_CODE);
+ throw new CASValidationException(CASErrorCode.INVALID_TICKET_SPEC, "Invalid format of the code", Response.Status.BAD_REQUEST);
+ }
}
}
--
Gitblit v1.10.0