use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.
the class RestAuthenticationHandlerTest method shouldInitiateAuthenticationViaGET5.
@Test
public void shouldInitiateAuthenticationViaGET5() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, RestAuthException, RestAuthResponseException {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse httpResponse = mock(HttpServletResponse.class);
String authIndexType = "UNKNOWN";
String indexValue = null;
String sessionUpgradeSSOTokenId = null;
//When
try {
restAuthenticationHandler.initiateAuthentication(request, httpResponse, authIndexType, indexValue, sessionUpgradeSSOTokenId);
} catch (RestAuthException e) {
assertEquals(e.getStatusCode(), 400);
return;
}
//Then
fail();
}
use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldThrow400ExceptionWithOrgDNNotValidReturningNull.
@Test
public void shouldThrow400ExceptionWithOrgDNNotValidReturningNull() throws SSOException, AuthException, AuthLoginException, IOException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = "SESSION_ID";
AuthIndexType authIndexType = AuthIndexType.COMPOSITE;
String authIndexValue = "INDEX_VALUE";
String ssoTokenId = "SSO_TOKEN_ID";
loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn(null);
//When
boolean exceptionCaught = false;
RestAuthException exception = null;
try {
loginAuthenticator.getLoginProcess(loginConfiguration);
} catch (RestAuthException e) {
exceptionCaught = true;
exception = e;
}
//Then
assertTrue(exceptionCaught);
assertEquals(exception.getStatusCode(), 400);
}
use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldThrow400ExceptionWithOrgDNNotValid.
@Test
public void shouldThrow400ExceptionWithOrgDNNotValid() throws SSOException, AuthException, AuthLoginException, IOException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = "SESSION_ID";
AuthIndexType authIndexType = AuthIndexType.COMPOSITE;
String authIndexValue = "INDEX_VALUE";
String ssoTokenId = "SSO_TOKEN_ID";
loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("");
//When
boolean exceptionCaught = false;
RestAuthException exception = null;
try {
loginAuthenticator.getLoginProcess(loginConfiguration);
} catch (RestAuthException e) {
exceptionCaught = true;
exception = e;
}
//Then
assertTrue(exceptionCaught);
assertEquals(exception.getStatusCode(), 400);
}
use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.
the class AuthenticationServiceV2Test method shouldReturnResponseContainingUnauthorizedCodeWithJsonErrorMessage.
@Test
public void shouldReturnResponseContainingUnauthorizedCodeWithJsonErrorMessage() throws IOException {
// given
Request httpRequest = new Request();
RestAuthException testException = new RestAuthException(401, "Invalid Password!!");
testException.setFailureUrl("http://localhost:8080");
// when
Response response = authServiceV2.handleErrorResponse(httpRequest, Status.valueOf(401), testException);
// then
assertThat(response.getStatus()).isEqualToComparingFieldByField(Status.UNAUTHORIZED);
JsonValue responseBody = json(response.getEntity().getJson());
assertThat(responseBody).integerAt("code").isEqualTo(401);
assertThat(responseBody).stringAt("reason").isEqualTo("Unauthorized");
assertThat(responseBody).stringAt("message").isEqualTo("Invalid Password!!");
assertThat(responseBody).stringAt("detail/failureUrl").isEqualTo("http://localhost:8080");
}
use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.
the class AuthenticationServiceV1Test method shouldReturnFrenchErrorMessageFromCause.
@Test
public void shouldReturnFrenchErrorMessageFromCause() throws IOException {
// given
Request httpRequest = new Request();
AuthLoginException ale = new AuthLoginException("amAuth", "120", null);
RestAuthException exception = new RestAuthException(401, ale);
httpRequest.getHeaders().put("Accept-Language", "fr-fr");
// when
String message = authServiceV1.getLocalizedMessage(httpRequest, exception);
// then
assertThat(message).isEqualTo("L’authentification sur module n’est pas autorisée.");
}
Aggregations