From 8379a316bc051ff05ac2fb06671871ab82f01feb Mon Sep 17 00:00:00 2001
From: Phy <git@phy25.com>
Date: Wed, 06 May 2020 00:52:58 +0000
Subject: [PATCH] Update to Keycloak 9.0.0 and apply API change

---
 src/main/java/org/keycloak/protocol/cas/representations/SamlResponseHelper.java |    6 +++---
 src/main/java/org/keycloak/protocol/cas/representations/SAMLCASConstants.java   |   11 +++++++++++
 pom.xml                                                                         |    2 +-
 src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java |    2 +-
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6891b7a..16ed5ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
 
     <groupId>org.keycloak</groupId>
     <artifactId>keycloak-protocol-cas</artifactId>
-    <version>8.0.2</version>
+    <version>9.0.0</version>
     <name>Keycloak CAS Protocol</name>
     <description />
 
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 d1acb61..b480679 100644
--- a/src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java
+++ b/src/main/java/org/keycloak/protocol/cas/endpoints/AbstractValidateEndpoint.java
@@ -153,7 +153,7 @@
     protected Map<String, Object> getUserAttributes() {
         UserSessionModel userSession = clientSession.getUserSession();
         // CAS protocol does not support scopes, so pass null scopeParam
-        ClientSessionContext clientSessionCtx = DefaultClientSessionContext.fromClientSessionAndScopeParameter(clientSession, null);
+        ClientSessionContext clientSessionCtx = DefaultClientSessionContext.fromClientSessionAndScopeParameter(clientSession, null, session);
 
         Set<ProtocolMapperModel> mappings = clientSessionCtx.getProtocolMappers();
         KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory();
diff --git a/src/main/java/org/keycloak/protocol/cas/representations/SAMLCASConstants.java b/src/main/java/org/keycloak/protocol/cas/representations/SAMLCASConstants.java
new file mode 100644
index 0000000..574142c
--- /dev/null
+++ b/src/main/java/org/keycloak/protocol/cas/representations/SAMLCASConstants.java
@@ -0,0 +1,11 @@
+package org.keycloak.protocol.cas.representations;
+
+public interface SAMLCASConstants {
+
+    String AUTH_METHOD_PASSWORD = "urn:oasis:names:tc:SAML:1.0:am:password";
+
+    String FORMAT_EMAIL_ADDRESS = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
+
+    String FORMAT_UNSPECIFIED = "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
+
+}
diff --git a/src/main/java/org/keycloak/protocol/cas/representations/SamlResponseHelper.java b/src/main/java/org/keycloak/protocol/cas/representations/SamlResponseHelper.java
index f5db51c..cc8ec8d 100644
--- a/src/main/java/org/keycloak/protocol/cas/representations/SamlResponseHelper.java
+++ b/src/main/java/org/keycloak/protocol/cas/representations/SamlResponseHelper.java
@@ -74,7 +74,7 @@
                             conditions.setNotOnOrAfter(factory.newXMLGregorianCalendar(GregorianCalendar.from(nowZoned.plusMinutes(5))));
                         }));
                         assertion.add(applyTo(new SAML11AuthenticationStatementType(
-                                URI.create(SAML11Constants.AUTH_METHOD_PASSWORD),
+                                URI.create(SAMLCASConstants.AUTH_METHOD_PASSWORD),
                                 now
                         ), stmt -> stmt.setSubject(toSubject(username))));
                         assertion.addAllStatements(toAttributes(username, attributes));
@@ -141,8 +141,8 @@
 
     private static URI nameIdFormat(String username) {
         return URI.create(Validation.isEmailValid(username) ?
-                SAML11Constants.FORMAT_EMAIL_ADDRESS :
-                SAML11Constants.FORMAT_UNSPECIFIED
+                SAMLCASConstants.FORMAT_EMAIL_ADDRESS :
+                SAMLCASConstants.FORMAT_UNSPECIFIED
         );
     }
 

--
Gitblit v1.9.1