From 1293d5189bfdc7c46fc456f52126b81febf23df8 Mon Sep 17 00:00:00 2001
From: Matthias Piepkorn <mpiepk@gmail.com>
Date: Mon, 22 Jan 2018 12:00:27 +0000
Subject: [PATCH] remove dependency on internal SAML packages

---
 src/main/java/org/keycloak/protocol/cas/CASLoginProtocol.java |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/keycloak/protocol/cas/CASLoginProtocol.java b/src/main/java/org/keycloak/protocol/cas/CASLoginProtocol.java
index cbcf1d0..b796962 100644
--- a/src/main/java/org/keycloak/protocol/cas/CASLoginProtocol.java
+++ b/src/main/java/org/keycloak/protocol/cas/CASLoginProtocol.java
@@ -18,6 +18,7 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.net.URI;
 
 public class CASLoginProtocol implements LoginProtocol {
@@ -91,9 +92,19 @@
 
         String service = clientSession.getRedirectUri();
         //TODO validate service
-        accessCode.setAction(CommonClientSessionModel.Action.CODE_TO_TOKEN.name());
+
+        String code;
+        try {
+            // Keycloak >3.4 branch: Method getCode was renamed to getOrGenerateCode, CODE_TO_TOKEN was removed
+            Method getOrGenerateCode = ClientSessionCode.class.getMethod("getOrGenerateCode");
+            code = (String) getOrGenerateCode.invoke(accessCode);
+        } catch (ReflectiveOperationException e) {
+            // Keycloak <=3.3 branch
+            accessCode.setAction(CommonClientSessionModel.Action.CODE_TO_TOKEN.name());
+            code = accessCode.getCode();
+        }
         KeycloakUriBuilder uriBuilder = KeycloakUriBuilder.fromUri(service);
-        uriBuilder.queryParam(TICKET_RESPONSE_PARAM, SERVICE_TICKET_PREFIX + accessCode.getCode());
+        uriBuilder.queryParam(TICKET_RESPONSE_PARAM, SERVICE_TICKET_PREFIX + code);
 
         URI redirectUri = uriBuilder.build();
 

--
Gitblit v1.9.1