mirror of https://github.com/jacekkow/keycloak-protocol-cas

github-actions
2024-12-03 0d71e01978a7871823e81ba1430777c3e6eca853
commit | author | age
513246 1 package org.keycloak.protocol.cas.utils;
MP 2
fdb9f6 3 import jakarta.ws.rs.core.*;
513246 4 import org.keycloak.protocol.cas.CASLoginProtocol;
6fff26 5 import org.keycloak.protocol.cas.representations.CASErrorCode;
513246 6
MP 7 public class ContentTypeHelper {
8     private final UriInfo uriInfo;
9
6fff26 10     public ContentTypeHelper(UriInfo uriInfo) {
513246 11         this.uriInfo = uriInfo;
MP 12     }
13
14     public MediaType selectResponseType() {
15         String format = uriInfo.getQueryParameters().getFirst(CASLoginProtocol.FORMAT_PARAM);
16         if (format != null && !format.isEmpty()) {
6fff26 17             if (format.equalsIgnoreCase("json")) {
JK 18                 return MediaType.APPLICATION_JSON_TYPE;
19             } else if (format.equalsIgnoreCase("xml")) {
20                 return MediaType.APPLICATION_XML_TYPE;
21             } else {
22                 throw new CASValidationException(CASErrorCode.INVALID_REQUEST, "Unsupported value of parameter " + CASLoginProtocol.FORMAT_PARAM, Response.Status.BAD_REQUEST);
23             }
513246 24         }
6fff26 25         return MediaType.APPLICATION_XML_TYPE;
513246 26     }
MP 27 }