use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class AuthenticationServiceV1 method createResponse.
/**
* Creates a response from the given JsonValue.
*
* @param jsonResponse The Json response body.
* @return a response.
* @throws IOException If there is a problem creating the response.
*/
private Response createResponse(final JsonValue jsonResponse) throws IOException {
Response response = new Response(Status.OK);
response.getHeaders().put(CACHE_CONTROL_HEADER_NAME, NO_CACHE_CACHE_CONTROL_HEADER);
response.getHeaders().put(PRAGMA_HEADER_NAME, PRAGMA_NO_CACHE_HEADER);
response.getHeaders().put(EXPIRES_HEADER_NAME, ALWAYS_EXPIRE_HEADER);
response.getHeaders().put(CONTENT_TYPE_HEADER_NAME, "application/json");
response.setEntity(jsonResponse.getObject());
return response;
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldReturnUnauthorizedCodeWithJsonErrorMessage.
@Test
public void shouldReturnUnauthorizedCodeWithJsonErrorMessage() throws IOException {
// given
Request httpRequest = new Request();
RestAuthException exception = new RestAuthException(401, "Invalid Password!!");
exception.setFailureUrl("http://localhost:8080");
// when
Response response = authServiceV1.handleErrorResponse(httpRequest, Status.valueOf(401), exception);
// then
assertThat(response.getStatus()).isEqualTo(Status.UNAUTHORIZED);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).stringAt("errorMessage").isEqualTo("Invalid Password!!");
assertThat(responseBody).stringAt("failureUrl").isEqualTo("http://localhost:8080");
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithInvalidDnsAlias.
@Test
public void filterShouldConsumeRealmFromRequestWithInvalidDnsAlias() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(INVALID_DNS_ALIAS_HOSTNAME, ENDPOINT_PATH_ELEMENT);
mockInvalidDnsAlias(INVALID_DNS_ALIAS_HOSTNAME);
//When
Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
//Then
assertThat(response.getStatus()).isSameAs(Status.BAD_REQUEST);
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithInvalidOverrideRealm.
@Test
public void filterShouldConsumeRealmFromRequestWithInvalidOverrideRealm() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + INVALID_OVERRIDE_REALM);
mockDnsAlias(HOSTNAME, "/");
mockInvalidRealmAlias(INVALID_OVERRIDE_REALM);
//When
Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
//Then
verifyInvalidRealmResponse(response, INVALID_OVERRIDE_REALM);
}
use of org.forgerock.http.protocol.Response in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldFailToConsumeRealmFromRequestOnExceptionWhenResolvingServerName.
@Test
public void filterShouldFailToConsumeRealmFromRequestOnExceptionWhenResolvingServerName() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT);
IdRepoException exception = mock(IdRepoException.class);
given(exception.getMessage()).willReturn("EXCEPTION_MESSAGE");
doThrow(exception).when(coreWrapper).getOrganization(any(SSOToken.class), eq(HOSTNAME));
//When
Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
//Then
assertThat(response.getStatus()).isSameAs(Status.BAD_REQUEST);
assertThat(response.getEntity().getJson()).isEqualTo(new BadRequestException("FQDN \"HOSTNAME\" is not valid.").toJsonValue().getObject());
}
Aggregations