Commit 8a551802 authored by Matthias Piepkorn's avatar Matthias Piepkorn
Browse files

Unify ServiceResponse filename casing

parent 35243641
......@@ -7,7 +7,7 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.protocol.ProtocolMapper;
import org.keycloak.protocol.cas.mappers.CASAttributeMapper;
import org.keycloak.protocol.cas.representations.CasServiceResponse;
import org.keycloak.protocol.cas.representations.CASServiceResponse;
import org.keycloak.protocol.cas.utils.CASValidationException;
import org.keycloak.protocol.cas.utils.ContentTypeHelper;
import org.keycloak.protocol.cas.utils.ServiceResponseHelper;
......@@ -40,17 +40,17 @@ public class ServiceValidateEndpoint extends ValidateEndpoint {
}
}
CasServiceResponse serviceResponse = ServiceResponseHelper.createSuccess(userSession.getUser().getUsername(), attributes);
CASServiceResponse serviceResponse = ServiceResponseHelper.createSuccess(userSession.getUser().getUsername(), attributes);
return prepare(Response.Status.OK, serviceResponse);
}
@Override
protected Response errorResponse(CASValidationException e) {
CasServiceResponse serviceResponse = ServiceResponseHelper.createFailure(e.getError(), e.getErrorDescription());
CASServiceResponse serviceResponse = ServiceResponseHelper.createFailure(e.getError(), e.getErrorDescription());
return prepare(e.getStatus(), serviceResponse);
}
private Response prepare(Response.Status status, CasServiceResponse serviceResponse) {
private Response prepare(Response.Status status, CASServiceResponse serviceResponse) {
MediaType responseMediaType = new ContentTypeHelper(request, restRequest, uriInfo).selectResponseType();
return ServiceResponseHelper.createResponse(status, responseMediaType, serviceResponse);
}
......
......@@ -3,23 +3,23 @@ package org.keycloak.protocol.cas.representations;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "serviceResponse")
public class CasServiceResponse {
private CasServiceResponseAuthenticationFailure authenticationFailure;
private CasServiceResponseAuthenticationSuccess authenticationSuccess;
public class CASServiceResponse {
private CASServiceResponseAuthenticationFailure authenticationFailure;
private CASServiceResponseAuthenticationSuccess authenticationSuccess;
public CasServiceResponseAuthenticationFailure getAuthenticationFailure() {
public CASServiceResponseAuthenticationFailure getAuthenticationFailure() {
return this.authenticationFailure;
}
public void setAuthenticationFailure(final CasServiceResponseAuthenticationFailure authenticationFailure) {
public void setAuthenticationFailure(final CASServiceResponseAuthenticationFailure authenticationFailure) {
this.authenticationFailure = authenticationFailure;
}
public CasServiceResponseAuthenticationSuccess getAuthenticationSuccess() {
public CASServiceResponseAuthenticationSuccess getAuthenticationSuccess() {
return this.authenticationSuccess;
}
public void setAuthenticationSuccess(final CasServiceResponseAuthenticationSuccess authenticationSuccess) {
public void setAuthenticationSuccess(final CASServiceResponseAuthenticationSuccess authenticationSuccess) {
this.authenticationSuccess = authenticationSuccess;
}
}
......@@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
@XmlAccessorType(XmlAccessType.FIELD)
public class CasServiceResponseAuthenticationFailure {
public class CASServiceResponseAuthenticationFailure {
@XmlAttribute
private String code;
@XmlValue
......
......@@ -8,7 +8,7 @@ import java.util.List;
import java.util.Map;
@XmlAccessorType(XmlAccessType.FIELD)
public class CasServiceResponseAuthenticationSuccess {
public class CASServiceResponseAuthenticationSuccess {
private String user;
private String proxyGrantingTicket;
@XmlElementWrapper
......
package org.keycloak.protocol.cas.utils;
import org.keycloak.protocol.cas.representations.CasServiceResponse;
import org.keycloak.protocol.cas.representations.CASServiceResponse;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
......@@ -50,7 +50,7 @@ public final class AttributesMapAdapter extends XmlAdapter<AttributesMapAdapter.
private void addElement(String name, Object value) {
if (value != null) {
String namespace = CasServiceResponse.class.getPackage().getAnnotation(XmlSchema.class).namespace();
String namespace = CASServiceResponse.class.getPackage().getAnnotation(XmlSchema.class).namespace();
elements.add(new JAXBElement<>(new QName(namespace, name), String.class, value.toString()));
}
}
......
package org.keycloak.protocol.cas.utils;
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.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;
......@@ -15,14 +15,14 @@ public final class ServiceResponseHelper {
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);
......@@ -33,9 +33,9 @@ public final class ServiceResponseHelper {
return response;
}
public static CasServiceResponse createFailure(CASErrorCode errorCode, String errorDescription) {
CasServiceResponse response = new CasServiceResponse();
CasServiceResponseAuthenticationFailure failure = new CasServiceResponseAuthenticationFailure();
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);
......@@ -43,7 +43,7 @@ public final class ServiceResponseHelper {
return response;
}
public static Response createResponse(Response.Status status, MediaType mediaType, CasServiceResponse serviceResponse) {
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)) {
......
......@@ -5,7 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.keycloak.protocol.cas.representations.CasServiceResponse;
import org.keycloak.protocol.cas.representations.CASServiceResponse;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
......@@ -23,9 +23,9 @@ public final class ServiceResponseMarshaller {
private ServiceResponseMarshaller() {
}
public static String marshalXml(CasServiceResponse serviceResponse) {
public static String marshalXml(CASServiceResponse serviceResponse) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(CasServiceResponse.class);
JAXBContext jaxbContext = JAXBContext.newInstance(CASServiceResponse.class);
Marshaller marshaller = jaxbContext.createMarshaller();
//disable xml header
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
......@@ -39,7 +39,7 @@ public final class ServiceResponseMarshaller {
}
}
public static String marshalJson(CasServiceResponse serviceResponse) {
public static String marshalJson(CASServiceResponse serviceResponse) {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//Force newlines to be LF (default is system dependent)
......
......@@ -2,7 +2,7 @@ package org.keycloak.protocol.cas;
import org.junit.Test;
import org.keycloak.protocol.cas.representations.CASErrorCode;
import org.keycloak.protocol.cas.representations.CasServiceResponse;
import org.keycloak.protocol.cas.representations.CASServiceResponse;
import org.keycloak.protocol.cas.utils.ServiceResponseHelper;
import org.keycloak.protocol.cas.utils.ServiceResponseMarshaller;
......@@ -62,7 +62,7 @@ public class ServiceResponseTest {
attributes.put("int", 123);
attributes.put("string", "abc");
CasServiceResponse response = ServiceResponseHelper.createSuccess("username", attributes, "PGTIOU-test",
CASServiceResponse response = ServiceResponseHelper.createSuccess("username", attributes, "PGTIOU-test",
Arrays.asList("https://proxy1/pgtUrl", "https://proxy2/pgtUrl"));
assertEquals(EXPECTED_JSON_SUCCESS, ServiceResponseMarshaller.marshalJson(response));
......@@ -71,7 +71,7 @@ public class ServiceResponseTest {
@Test
public void testErrorResponse() throws Exception {
CasServiceResponse response = ServiceResponseHelper.createFailure(CASErrorCode.INVALID_REQUEST, "Error description");
CASServiceResponse response = ServiceResponseHelper.createFailure(CASErrorCode.INVALID_REQUEST, "Error description");
assertEquals(EXPECTED_JSON_FAILURE, ServiceResponseMarshaller.marshalJson(response));
assertEquals(EXPECTED_XML_FAILURE, ServiceResponseMarshaller.marshalXml(response));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment