Search in sources :

Example 6 with RestAuthException

use of org.forgerock.openam.core.rest.authn.exceptions.RestAuthException in project OpenAM by OpenRock.

the class AuthIdHelperTest method shouldThrowSMSExceptionWhenFailToGetOrgConfig.

@Test
public void shouldThrowSMSExceptionWhenFailToGetOrgConfig() throws SSOException, SMSException, SignatureException {
    //Given
    LoginConfiguration loginConfiguration = mock(LoginConfiguration.class);
    AuthContextLocalWrapper authContext = mock(AuthContextLocalWrapper.class);
    given(coreServicesWrapper.getServiceConfigManager("iPlanetAMAuthService", null)).willThrow(SMSException.class);
    //When
    boolean exceptionCaught = false;
    RestAuthException exception = null;
    try {
        authIdHelper.createAuthId(loginConfiguration, authContext);
        fail();
    } catch (RestAuthException e) {
        exceptionCaught = true;
        exception = e;
    }
    //Then
    assertTrue(exceptionCaught);
    assertEquals(exception.getStatusCode(), 500);
}
Also used : RestAuthException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthException) LoginConfiguration(org.forgerock.openam.core.rest.authn.core.LoginConfiguration) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) Test(org.testng.annotations.Test)

Example 7 with RestAuthException

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");
}
Also used : RestAuthException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthException) Response(org.forgerock.http.protocol.Response) Request(org.forgerock.http.protocol.Request) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 8 with RestAuthException

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.");
}
Also used : RestAuthException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthException) Request(org.forgerock.http.protocol.Request) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) Test(org.testng.annotations.Test)

Example 9 with RestAuthException

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RestAuthException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 10 with RestAuthException

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RestAuthException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthException) Test(org.testng.annotations.Test)

Aggregations

RestAuthException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthException)22 Test (org.testng.annotations.Test)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JsonValue (org.forgerock.json.JsonValue)5 Request (org.forgerock.http.protocol.Request)4 Response (org.forgerock.http.protocol.Response)4 LoginConfiguration (org.forgerock.openam.core.rest.authn.core.LoginConfiguration)4 RestAuthResponseException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthResponseException)4 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)3 AuthContextLocalWrapper (org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper)3 SSOToken (com.iplanet.sso.SSOToken)2 PublicKey (java.security.PublicKey)2 Map (java.util.Map)2 SigningHandler (org.forgerock.json.jose.jws.handlers.SigningHandler)2 SessionID (com.iplanet.dpro.session.SessionID)1 SSOException (com.iplanet.sso.SSOException)1 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)1 L10NMessageImpl (com.sun.identity.shared.locale.L10NMessageImpl)1