From 755fd78fa0ee0f2a67417a119382c63e02c1091e Mon Sep 17 00:00:00 2001
From: Alexandre Rocha Wendling <alexandrerw@celepar.pr.gov.br>
Date: Tue, 16 Jul 2024 14:15:23 +0000
Subject: [PATCH] Proxy ticket service and proxy ticket validation Proxy endpoints improvements suggested by Jacek Kowalski Add ticket type to storage key Rename isreuse to isReusable Remove "parsing" of "codeUUID" that is String, not UUID Improve error reporting in CAS ticket validation

---
 src/main/java/org/keycloak/protocol/cas/utils/ServiceResponseHelper.java |   51 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/keycloak/protocol/cas/utils/ServiceResponseHelper.java b/src/main/java/org/keycloak/protocol/cas/utils/ServiceResponseHelper.java
index 8b927b8..ed6b635 100644
--- a/src/main/java/org/keycloak/protocol/cas/utils/ServiceResponseHelper.java
+++ b/src/main/java/org/keycloak/protocol/cas/utils/ServiceResponseHelper.java
@@ -1,12 +1,15 @@
 package org.keycloak.protocol.cas.utils;
 
-import org.keycloak.protocol.cas.representations.CasServiceResponse;
-import org.keycloak.protocol.cas.representations.CasServiceResponseAuthenticationFailure;
-import org.keycloak.protocol.cas.representations.CasServiceResponseAuthenticationSuccess;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import org.keycloak.protocol.cas.representations.CASErrorCode;
+import org.keycloak.protocol.cas.representations.CASServiceResponse;
+import org.keycloak.protocol.cas.representations.CASServiceResponseAuthenticationFailure;
+import org.keycloak.protocol.cas.representations.CASServiceResponseAuthenticationSuccess;
+import org.keycloak.protocol.cas.representations.CASServiceResponseProxySuccess;
+import org.keycloak.protocol.cas.representations.CASServiceResponseProxyFailure;
 
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 import java.util.List;
 import java.util.Map;
 
@@ -14,14 +17,14 @@
     private ServiceResponseHelper() {
     }
 
-    public static CasServiceResponse createSuccess(String username, Map<String, Object> attributes) {
+    public static CASServiceResponse createSuccess(String username, Map<String, Object> attributes) {
         return createSuccess(username, attributes, null, null);
     }
 
-    public static CasServiceResponse createSuccess(String username, Map<String, Object> attributes,
+    public static CASServiceResponse createSuccess(String username, Map<String, Object> attributes,
                                                    String proxyGrantingTicket, List<String> proxies) {
-        CasServiceResponse response = new CasServiceResponse();
-        CasServiceResponseAuthenticationSuccess success = new CasServiceResponseAuthenticationSuccess();
+        CASServiceResponse response = new CASServiceResponse();
+        CASServiceResponseAuthenticationSuccess success = new CASServiceResponseAuthenticationSuccess();
         success.setUser(username);
         success.setProxies(proxies);
         success.setProxyGrantingTicket(proxyGrantingTicket);
@@ -32,17 +35,35 @@
         return response;
     }
 
-    public static CasServiceResponse createFailure(String errorCode, String errorDescription) {
-        CasServiceResponse response = new CasServiceResponse();
-        CasServiceResponseAuthenticationFailure failure = new CasServiceResponseAuthenticationFailure();
-        failure.setCode(errorCode);
+    public static CASServiceResponse createFailure(CASErrorCode errorCode, String errorDescription) {
+        CASServiceResponse response = new CASServiceResponse();
+        CASServiceResponseAuthenticationFailure failure = new CASServiceResponseAuthenticationFailure();
+        failure.setCode(errorCode == null ? CASErrorCode.INTERNAL_ERROR.name() : errorCode.name());
         failure.setDescription(errorDescription);
         response.setAuthenticationFailure(failure);
 
         return response;
     }
 
-    public static Response createResponse(Response.Status status, MediaType mediaType, CasServiceResponse serviceResponse) {
+    public static CASServiceResponse createProxySuccess(String pt) {
+        CASServiceResponse response = new CASServiceResponse();
+        CASServiceResponseProxySuccess success = new CASServiceResponseProxySuccess();
+        success.setProxyTicket(pt);
+        response.setProxySuccess(success);
+        return response;
+    }
+
+    public static CASServiceResponse createProxyFailure(CASErrorCode errorCode, String errorDescription) {
+        CASServiceResponse response = new CASServiceResponse();
+        CASServiceResponseProxyFailure failure = new CASServiceResponseProxyFailure();
+        failure.setCode(errorCode == null ? CASErrorCode.INTERNAL_ERROR.name() : errorCode.name());
+        failure.setDescription(errorDescription);
+        response.setProxyFailure(failure);
+
+        return response;
+    }
+
+    public static Response createResponse(Response.Status status, MediaType mediaType, CASServiceResponse serviceResponse) {
         Response.ResponseBuilder builder = Response.status(status)
                 .header(HttpHeaders.CONTENT_TYPE, mediaType.withCharset("utf-8"));
         if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {

--
Gitblit v1.9.1