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; |
81877a
|
5 |
import org.keycloak.protocol.cas.representations.CASErrorCode; |
513246
|
6 |
|
MP |
7 |
public class ContentTypeHelper { |
|
8 |
private final UriInfo uriInfo; |
|
9 |
|
81877a
|
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()) { |
81877a
|
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 |
} |
81877a
|
25 |
return MediaType.APPLICATION_XML_TYPE; |
513246
|
26 |
} |
MP |
27 |
} |