use of com.thoughtworks.go.server.newsecurity.models.ContentTypeAwareResponse in project gocd by gocd.
the class UserEnabledCheckFilterForApiRequest method handleFailure.
@Override
void handleFailure(HttpServletRequest request, HttpServletResponse response, String errorMessage) throws IOException {
response.setStatus(401);
final ContentTypeAwareResponse contentTypeAwareResponse = CONTENT_TYPE_NEGOTIATION_MESSAGE_HANDLER.getResponse(request);
response.setCharacterEncoding("utf-8");
response.setContentType(contentTypeAwareResponse.getContentType().toString());
response.getOutputStream().print(contentTypeAwareResponse.getFormattedMessage(errorMessage));
}
use of com.thoughtworks.go.server.newsecurity.models.ContentTypeAwareResponse in project gocd by gocd.
the class BasicAuthenticationWithChallengeFailureResponseHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, int statusCode, String errorMessage) throws IOException {
if (!isAjaxRequest(request)) {
if (securityService.isSecurityEnabled()) {
response.addHeader("WWW-Authenticate", "Basic realm=\"GoCD\"");
}
}
response.setStatus(statusCode);
final ContentTypeAwareResponse contentTypeAwareResponse = CONTENT_TYPE_NEGOTIATION_MESSAGE_HANDLER.getResponse(request);
response.setCharacterEncoding("utf-8");
response.setContentType(contentTypeAwareResponse.getContentType().toString());
response.getOutputStream().print(contentTypeAwareResponse.getFormattedMessage(errorMessage));
}
use of com.thoughtworks.go.server.newsecurity.models.ContentTypeAwareResponse in project gocd by gocd.
the class RequestRejectedExceptionHandler method handle.
public void handle(HttpServletRequest request, HttpServletResponse response, String message, HttpStatus httpStatus) throws IOException {
if (API_REQUEST_MATCHER.matches(request)) {
response.setStatus(HttpStatus.BAD_REQUEST.value());
final ContentTypeAwareResponse contentTypeAwareResponse = CONTENT_TYPE_NEGOTIATION_MESSAGE_HANDLER.getResponse(request);
response.setCharacterEncoding("utf-8");
response.setContentType(contentTypeAwareResponse.getContentType().toString());
response.getOutputStream().print(contentTypeAwareResponse.getFormattedMessage(message));
} else {
response.sendError(httpStatus.value(), message);
}
}
use of com.thoughtworks.go.server.newsecurity.models.ContentTypeAwareResponse in project gocd by gocd.
the class ContentTypeNegotiationMessageRendererTest method shouldGenerateXMLResponseMessageForContentType.
@ParameterizedTest
@ValueSource(strings = { MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE })
void shouldGenerateXMLResponseMessageForContentType(String contentType) {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/").withHeader("Accept", contentType).build();
final ContentTypeAwareResponse response = new ContentTypeNegotiationMessageRenderer().getResponse(request);
assertThat(response.getContentType().toString()).isEqualTo(contentType);
assertThat(response.getFormattedMessage("foo")).isEqualTo("<access-denied>\n <message>foo</message>\n</access-denied>\n");
}
use of com.thoughtworks.go.server.newsecurity.models.ContentTypeAwareResponse in project gocd by gocd.
the class ContentTypeNegotiationMessageRendererTest method shouldJsonResponseMessageWhenRequestIsMadeWithoutContentTypeAndItIsNotForXMLFile.
@Test
void shouldJsonResponseMessageWhenRequestIsMadeWithoutContentTypeAndItIsNotForXMLFile() {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/random").build();
final ContentTypeAwareResponse response = new ContentTypeNegotiationMessageRenderer().getResponse(request);
assertThat(response.getContentType().toString()).isEqualTo("application/json");
assertThat(response.getFormattedMessage("foo")).isEqualTo("{\n \"message\": \"foo\"\n}");
}
Aggregations