Search in sources :

Example 6 with ChoiceCallback

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

the class PersistModuleProcesserTest method shouldReturnLoginSucceedWithoutSavingProfileWhenUserChooseToNotSaveProfile.

@Test
public void shouldReturnLoginSucceedWithoutSavingProfileWhenUserChooseToNotSaveProfile() throws AuthLoginException {
    //Given
    processor = new PersistModuleProcessor(devicePrintProfile, false, profilePersister);
    ChoiceCallback choiceCallback = mock(ChoiceCallback.class);
    Callback[] callbacks = new Callback[] { choiceCallback };
    int state = SAVE_PROFILE_STATE;
    given(choiceCallback.getSelectedIndexes()).willReturn(new int[] { 1 });
    //When
    int newState = processor.process(callbacks, state);
    //Then
    assertThat(newState).isEqualTo(ISAuthConstants.LOGIN_SUCCEED);
    verifyZeroInteractions(profilePersister);
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) Test(org.testng.annotations.Test)

Example 7 with ChoiceCallback

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

the class RestAuthChoiceCallbackHandlerTest method shouldConvertFromJson.

@Test
public void shouldConvertFromJson() throws RestAuthException {
    //Given
    ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[] { "1", "34", "66", "93" }, 0, true);
    JsonValue jsonNameCallback = json(object(field("input", array(object(field("value", 1)))), field("output", array(object(field("value", "Select choice:")), object(field("value", array("1", "34", "66", "93"))), object(field("value", "0")))), field("type", "ChoiceCallback")));
    //When
    ChoiceCallback convertedChoiceCallback = restAuthChoiceCallbackHandler.convertFromJson(choiceCallback, jsonNameCallback);
    //Then
    assertEquals(choiceCallback, convertedChoiceCallback);
    assertEquals("Select choice:", convertedChoiceCallback.getPrompt());
    assertEquals(new String[] { "1", "34", "66", "93" }, convertedChoiceCallback.getChoices());
    assertEquals(0, convertedChoiceCallback.getDefaultChoice());
    assertEquals(new int[] { 1 }, convertedChoiceCallback.getSelectedIndexes());
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 8 with ChoiceCallback

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

the class RestAuthChoiceCallbackHandlerTest method shouldNotUpdateCallbackFromRequest.

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

Example 9 with ChoiceCallback

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

the class RestAuthChoiceCallbackHandlerTest method shouldFailToConvertFromJsonWithInvalidValue.

@Test(expectedExceptions = JsonValueException.class)
public void shouldFailToConvertFromJsonWithInvalidValue() throws RestAuthException {
    //Given
    ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[] { "A", "B", "C", "D" }, 0, true);
    JsonValue jsonNameCallback = json(object(field("input", array(object(field("value", "A")))), field("output", array(object(field("value", "Select choice:")), object(field("value", array("A", "B", "C", "D"))), object(field("value", "0")))), field("type", "ChoiceCallback")));
    System.out.println("shouldFailToConvertFromJsonWithInvalidValue");
    System.out.println(jsonNameCallback.toString());
    //When
    restAuthChoiceCallbackHandler.convertFromJson(choiceCallback, jsonNameCallback);
    //Then
    fail();
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 10 with ChoiceCallback

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

the class RestAuthChoiceCallbackHandlerTest method shouldConvertToJsonWithPreSelectedIndexes.

@Test
public void shouldConvertToJsonWithPreSelectedIndexes() throws RestAuthException {
    //Given
    ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[] { "1", "34", "66", "93" }, 0, false);
    choiceCallback.setSelectedIndex(1);
    //When
    JsonValue jsonObject = restAuthChoiceCallbackHandler.convertToJson(choiceCallback, 1);
    //Then
    assertEquals("ChoiceCallback", jsonObject.get("type").asString());
    assertNotNull(jsonObject.get("output"));
    assertEquals(3, jsonObject.get("output").size());
    assertEquals("Select choice:", jsonObject.get("output").get(0).get("value").asString());
    assertEquals("1", jsonObject.get("output").get(1).get("value").get(0).asString());
    assertEquals("34", jsonObject.get("output").get(1).get("value").get(1).asString());
    assertEquals("66", jsonObject.get("output").get(1).get("value").get(2).asString());
    assertEquals("93", jsonObject.get("output").get(1).get("value").get(3).asString());
    assertEquals(0, (int) jsonObject.get("output").get(2).get("value").asInteger());
    assertNotNull(jsonObject.get("input"));
    assertEquals(1, jsonObject.get("input").size());
    assertEquals(1, (int) jsonObject.get("input").get(0).get("value").asInteger());
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Aggregations

ChoiceCallback (javax.security.auth.callback.ChoiceCallback)32 Callback (javax.security.auth.callback.Callback)19 Test (org.testng.annotations.Test)17 NameCallback (javax.security.auth.callback.NameCallback)15 PasswordCallback (javax.security.auth.callback.PasswordCallback)13 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)12 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)9 JsonValue (org.forgerock.json.JsonValue)8 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)5 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)5 TextInputCallback (javax.security.auth.callback.TextInputCallback)5 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)5 SSOException (com.iplanet.sso.SSOException)4 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)4 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)4 ArrayList (java.util.ArrayList)4 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LanguageCallback (javax.security.auth.callback.LanguageCallback)3