// Path: src/main/java/org/keycloak/protocol/cas/representations/CASErrorCode.java
// public enum CASErrorCode {
//     /** not all of the required request parameters were present */
//     INVALID_REQUEST,
//     /** failure to meet the requirements of validation specification */
//     INVALID_TICKET_SPEC,
//     /** the service is not authorized to perform proxy authentication */
//     UNAUTHORIZED_SERVICE_PROXY,
//     /** The proxy callback specified is invalid. The credentials specified for proxy authentication do not meet the security requirements */
//     INVALID_PROXY_CALLBACK,
//     /** the ticket provided was not valid, or the ticket did not come from an initial login and renew was set on validation. */
//     INVALID_TICKET,
//     /** the ticket provided was valid, but the service specified did not match the service associated with the ticket. */
//     INVALID_SERVICE,
//     /** an internal error occurred during ticket validation */
//     INTERNAL_ERROR
// }
// 
// Path: src/main/java/org/keycloak/protocol/cas/representations/CASServiceResponse.java
// @XmlRootElement(name = "serviceResponse")
// public class CASServiceResponse {
//     private CASServiceResponseAuthenticationFailure authenticationFailure;
//     private CASServiceResponseAuthenticationSuccess authenticationSuccess;
// 
//     public CASServiceResponseAuthenticationFailure getAuthenticationFailure() {
//         return this.authenticationFailure;
//     }
// 
//     public void setAuthenticationFailure(final CASServiceResponseAuthenticationFailure authenticationFailure) {
//         this.authenticationFailure = authenticationFailure;
//     }
// 
//     public CASServiceResponseAuthenticationSuccess getAuthenticationSuccess() {
//         return this.authenticationSuccess;
//     }
// 
//     public void setAuthenticationSuccess(final CASServiceResponseAuthenticationSuccess authenticationSuccess) {
//         this.authenticationSuccess = authenticationSuccess;
//     }
// }
// 
// Path: src/main/java/org/keycloak/protocol/cas/representations/CASServiceResponseAuthenticationFailure.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class CASServiceResponseAuthenticationFailure {
//     @XmlAttribute
//     private String code;
//     @XmlValue
//     private String description;
// 
//     public String getCode() {
//         return this.code;
//     }
// 
//     public void setCode(final String code) {
//         this.code = code;
//     }
// 
//     public String getDescription() {
//         return this.description;
//     }
// 
//     public void setDescription(final String description) {
//         this.description = description;
//     }
// }
// 
// Path: src/main/java/org/keycloak/protocol/cas/representations/CASServiceResponseAuthenticationSuccess.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class CASServiceResponseAuthenticationSuccess {
//     private String user;
//     @XmlJavaTypeAdapter(AttributesMapAdapter.class)
//     private Map<String, Object> attributes;
//     private String proxyGrantingTicket;
//     @XmlElementWrapper
//     @XmlElement(name="proxy")
//     private List<String> proxies;
// 
//     public String getUser() {
//         return this.user;
//     }
// 
//     public void setUser(final String user) {
//         this.user = user;
//     }
// 
//     public Map<String, Object> getAttributes() {
//         return this.attributes;
//     }
// 
//     public void setAttributes(final Map<String, Object> attributes) {
//         this.attributes = attributes;
//     }
// 
//     public String getProxyGrantingTicket() {
//         return this.proxyGrantingTicket;
//     }
// 
//     public void setProxyGrantingTicket(final String proxyGrantingTicket) {
//         this.proxyGrantingTicket = proxyGrantingTicket;
//     }
// 
//     public List<String> getProxies() {
//         return this.proxies;
//     }
// 
//     public void setProxies(final List<String> proxies) {
//         this.proxies = proxies;
//     }
// }


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 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;
package org.keycloak.protocol.cas.utils;



public final class ServiceResponseHelper {
    private ServiceResponseHelper() {
    }

    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,
                                                   String proxyGrantingTicket, List<String> proxies) {
        CASServiceResponse response = new CASServiceResponse();
        CASServiceResponseAuthenticationSuccess success = new CASServiceResponseAuthenticationSuccess();
        success.setUser(username);
        success.setProxies(proxies);
        success.setProxyGrantingTicket(proxyGrantingTicket);
        success.setAttributes(attributes);

        response.setAuthenticationSuccess(success);

        return response;
    }

    public static CASServiceResponse createFailure(CASErrorCode errorCode, String errorDescription) {
        CASServiceResponse response = new CASServiceResponse();
        CASServiceResponseAuthenticationFailure failure = new CASServiceResponseAuthenticationFailure();
// Path: src/main/java/org/keycloak/protocol/cas/representations/CASErrorCode.java
// public enum CASErrorCode {
//     /** not all of the required request parameters were present */
//     INVALID_REQUEST,
//     /** failure to meet the requirements of validation specification */
//     INVALID_TICKET_SPEC,
//     /** the service is not authorized to perform proxy authentication */
//     UNAUTHORIZED_SERVICE_PROXY,
//     /** The proxy callback specified is invalid. The credentials specified for proxy authentication do not meet the security requirements */
//     INVALID_PROXY_CALLBACK,
//     /** the ticket provided was not valid, or the ticket did not come from an initial login and renew was set on validation. */
//     INVALID_TICKET,
//     /** the ticket provided was valid, but the service specified did not match the service associated with the ticket. */
//     INVALID_SERVICE,
//     /** an internal error occurred during ticket validation */
//     INTERNAL_ERROR
// }
// 
// Path: src/main/java/org/keycloak/protocol/cas/representations/CASServiceResponse.java
// @XmlRootElement(name = "serviceResponse")
// public class CASServiceResponse {
//     private CASServiceResponseAuthenticationFailure authenticationFailure;
//     private CASServiceResponseAuthenticationSuccess authenticationSuccess;
// 
//     public CASServiceResponseAuthenticationFailure getAuthenticationFailure() {
//         return this.authenticationFailure;
//     }
// 
//     public void setAuthenticationFailure(final CASServiceResponseAuthenticationFailure authenticationFailure) {
//         this.authenticationFailure = authenticationFailure;
//     }
// 
//     public CASServiceResponseAuthenticationSuccess getAuthenticationSuccess() {
//         return this.authenticationSuccess;
//     }
// 
//     public void setAuthenticationSuccess(final CASServiceResponseAuthenticationSuccess authenticationSuccess) {
//         this.authenticationSuccess = authenticationSuccess;
//     }
// }
// 
// Path: src/main/java/org/keycloak/protocol/cas/representations/CASServiceResponseAuthenticationFailure.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class CASServiceResponseAuthenticationFailure {
//     @XmlAttribute
//     private String code;
//     @XmlValue
//     private String description;
// 
//     public String getCode() {
//         return this.code;
//     }
// 
//     public void setCode(final String code) {
//         this.code = code;
//     }
// 
//     public String getDescription() {
//         return this.description;
//     }
// 
//     public void setDescription(final String description) {
//         this.description = description;
//     }
// }
// 
// Path: src/main/java/org/keycloak/protocol/cas/representations/CASServiceResponseAuthenticationSuccess.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class CASServiceResponseAuthenticationSuccess {
//     private String user;
//     @XmlJavaTypeAdapter(AttributesMapAdapter.class)
//     private Map<String, Object> attributes;
//     private String proxyGrantingTicket;
//     @XmlElementWrapper
//     @XmlElement(name="proxy")
//     private List<String> proxies;
// 
//     public String getUser() {
//         return this.user;
//     }
// 
//     public void setUser(final String user) {
//         this.user = user;
//     }
// 
//     public Map<String, Object> getAttributes() {
//         return this.attributes;
//     }
// 
//     public void setAttributes(final Map<String, Object> attributes) {
//         this.attributes = attributes;
//     }
// 
//     public String getProxyGrantingTicket() {
//         return this.proxyGrantingTicket;
//     }
// 
//     public void setProxyGrantingTicket(final String proxyGrantingTicket) {
//         this.proxyGrantingTicket = proxyGrantingTicket;
//     }
// 
//     public List<String> getProxies() {
//         return this.proxies;
//     }
// 
//     public void setProxies(final List<String> proxies) {
//         this.proxies = proxies;
//     }
// }


// Path: src/main/java/org/keycloak/protocol/cas/utils/ServiceResponseHelper.java
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 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;

package org.keycloak.protocol.cas.utils;



public final class ServiceResponseHelper {
    private ServiceResponseHelper() {
    }

    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,
                                                   String proxyGrantingTicket, List<String> proxies) {
        CASServiceResponse response = new CASServiceResponse();
        CASServiceResponseAuthenticationSuccess success = new CASServiceResponseAuthenticationSuccess();
        success.setUser(username);
        success.setProxies(proxies);
        success.setProxyGrantingTicket(proxyGrantingTicket);
        success.setAttributes(attributes);

        response.setAuthenticationSuccess(success);

        return response;
    }

    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());