Search in sources :

Example 16 with ConfirmationCallback

use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandlerTest method shouldHandleCallback.

@Test
public void shouldHandleCallback() {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    JsonValue jsonPostBody = mock(JsonValue.class);
    ConfirmationCallback originalConfirmationCallback = mock(ConfirmationCallback.class);
    //When
    ConfirmationCallback confirmationCallback = restAuthConfirmationCallbackHandler.handle(request, response, jsonPostBody, originalConfirmationCallback);
    //Then
    assertEquals(originalConfirmationCallback, confirmationCallback);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) JsonValue(org.forgerock.json.JsonValue) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 17 with ConfirmationCallback

use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandlerTest method shouldNotUpdateCallbackFromRequest.

@Test
public void shouldNotUpdateCallbackFromRequest() throws RestAuthResponseException, RestAuthException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
    //When
    boolean updated = restAuthConfirmationCallbackHandler.updateCallbackFromRequest(request, response, confirmationCallback);
    //Then
    assertFalse(updated);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 18 with ConfirmationCallback

use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandlerTest method shouldConvertFromJsonWithStringChoice.

@Test
public void shouldConvertFromJsonWithStringChoice() throws RestAuthException {
    //Given
    ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
    JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", "0").build()).put("type", "ConfirmationCallback").build();
    //When
    ConfirmationCallback convertedConfirmationCallback = restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
    //Then
    assertEquals(confirmationCallback, convertedConfirmationCallback);
    assertEquals("Select confirmation:", convertedConfirmationCallback.getPrompt());
    assertEquals(ConfirmationCallback.INFORMATION, convertedConfirmationCallback.getMessageType());
    assertEquals("OK", convertedConfirmationCallback.getOptions()[0]);
    assertEquals("NO", convertedConfirmationCallback.getOptions()[1]);
    assertEquals("CANCEL", convertedConfirmationCallback.getOptions()[2]);
    assertEquals(-1, convertedConfirmationCallback.getOptionType());
    assertEquals(0, convertedConfirmationCallback.getDefaultOption());
    assertEquals(2, convertedConfirmationCallback.getSelectedIndex());
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 19 with ConfirmationCallback

use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandlerTest method shouldNotFailToConvertFromJsonWithTypeLowerCase.

@Test
public void shouldNotFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException {
    //Given
    ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
    JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "confirmationcallback").build();
    //When
    ConfirmationCallback convertedConfirmationCallback = restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
    //Then
    assertEquals(confirmationCallback, convertedConfirmationCallback);
    assertEquals("Select confirmation:", convertedConfirmationCallback.getPrompt());
    assertEquals(ConfirmationCallback.INFORMATION, convertedConfirmationCallback.getMessageType());
    assertEquals("OK", convertedConfirmationCallback.getOptions()[0]);
    assertEquals("NO", convertedConfirmationCallback.getOptions()[1]);
    assertEquals("CANCEL", convertedConfirmationCallback.getOptions()[2]);
    assertEquals(-1, convertedConfirmationCallback.getOptionType());
    assertEquals(0, convertedConfirmationCallback.getDefaultOption());
    assertEquals(2, convertedConfirmationCallback.getSelectedIndex());
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 20 with ConfirmationCallback

use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandlerTest method shouldFailToConvertFromJsonWithInvalidType.

@Test(expectedExceptions = RestAuthException.class)
public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException {
    //Given
    ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
    JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "PasswordCallback").build();
    //When
    restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
    //Then
    fail();
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Aggregations

ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)29 NameCallback (javax.security.auth.callback.NameCallback)18 PasswordCallback (javax.security.auth.callback.PasswordCallback)18 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)14 Callback (javax.security.auth.callback.Callback)13 Test (org.testng.annotations.Test)13 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)7 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)6 JsonValue (org.forgerock.json.JsonValue)6 DevicePrint (org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)6 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)5 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)5 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 TextInputCallback (javax.security.auth.callback.TextInputCallback)4 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)4 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)3 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)3 LanguageCallback (javax.security.auth.callback.LanguageCallback)3