Search in sources :

Example 11 with TextInputCallback

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

the class AuthXMLUtils method createTextInputCallback.

static TextInputCallback createTextInputCallback(Node childNode, Callback callback) {
    TextInputCallback textInputCallback = null;
    if (callback != null) {
        if (callback instanceof TextInputCallback) {
            textInputCallback = (TextInputCallback) callback;
        }
    }
    if (textInputCallback == null) {
        String prompt = getPrompt(childNode);
        String defaultValue = getDefaultValue(childNode);
        if (defaultValue == null) {
            textInputCallback = new TextInputCallback(prompt);
        } else {
            textInputCallback = new TextInputCallback(prompt, defaultValue);
        }
    }
    String value = getValue(childNode);
    if (value != null) {
        textInputCallback.setText(value);
    }
    return textInputCallback;
}
Also used : TextInputCallback(javax.security.auth.callback.TextInputCallback)

Example 12 with TextInputCallback

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

the class RestAuthTextInputCallbackHandlerTest method shouldFailToConvertFromJsonWithInvalidType.

@Test(expectedExceptions = RestAuthException.class)
public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException {
    //Given
    TextInputCallback textInputCallback = new TextInputCallback("Enter text:", "DEFAULT_VALUE");
    JsonValue jsonTextInputCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", "TEXT_VALUE").build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Enter text:").build()).addLast(JsonValueBuilder.jsonValue().put("value", "DEFAULT_VALUE").build()).put("type", "PasswordCallback").build();
    //When
    restAuthTextInputCallbackHandler.convertFromJson(textInputCallback, jsonTextInputCallback);
    //Then
    fail();
}
Also used : JsonValue(org.forgerock.json.JsonValue) TextInputCallback(javax.security.auth.callback.TextInputCallback) Test(org.testng.annotations.Test)

Example 13 with TextInputCallback

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

the class RestAuthTextInputCallbackHandlerTest method shouldHandleCallback.

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

Example 14 with TextInputCallback

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

the class RestAuthTextInputCallbackHandlerTest method shouldConvertToJson.

@Test
public void shouldConvertToJson() throws RestAuthException {
    //Given
    TextInputCallback textInputCallback = new TextInputCallback("Enter text:", "DEFAULT_VALUE");
    //When
    JsonValue jsonObject = restAuthTextInputCallbackHandler.convertToJson(textInputCallback, 1);
    //Then
    assertEquals("TextInputCallback", jsonObject.get("type").asString());
    assertNotNull(jsonObject.get("output"));
    assertEquals(2, jsonObject.get("output").size());
    assertEquals("Enter text:", jsonObject.get("output").get(0).get("value").asString());
    assertEquals("DEFAULT_VALUE", jsonObject.get("output").get(1).get("value").asString());
    assertNotNull(jsonObject.get("input"));
    assertEquals(1, jsonObject.get("input").size());
    assertEquals("", jsonObject.get("input").get(0).get("value").asString());
}
Also used : JsonValue(org.forgerock.json.JsonValue) TextInputCallback(javax.security.auth.callback.TextInputCallback) Test(org.testng.annotations.Test)

Example 15 with TextInputCallback

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

the class RestAuthTextInputCallbackHandlerTest method shouldConvertFromJson.

@Test
public void shouldConvertFromJson() throws RestAuthException {
    //Given
    TextInputCallback textInputCallback = new TextInputCallback("Enter text:", "DEFAULT_VALUE");
    JsonValue jsonTextInputCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", "TEXT_VALUE").build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Enter text:").build()).addLast(JsonValueBuilder.jsonValue().put("value", "DEFAULT_VALUE").build()).put("type", "TextInputCallback").build();
    //When
    TextInputCallback convertedTextInputCallback = restAuthTextInputCallbackHandler.convertFromJson(textInputCallback, jsonTextInputCallback);
    //Then
    assertEquals(textInputCallback, convertedTextInputCallback);
    assertEquals("Enter text:", convertedTextInputCallback.getPrompt());
    assertEquals("DEFAULT_VALUE", convertedTextInputCallback.getDefaultText());
    assertEquals("TEXT_VALUE", convertedTextInputCallback.getText());
}
Also used : JsonValue(org.forgerock.json.JsonValue) TextInputCallback(javax.security.auth.callback.TextInputCallback) Test(org.testng.annotations.Test)

Aggregations

TextInputCallback (javax.security.auth.callback.TextInputCallback)15 NameCallback (javax.security.auth.callback.NameCallback)7 PasswordCallback (javax.security.auth.callback.PasswordCallback)7 Test (org.testng.annotations.Test)6 Callback (javax.security.auth.callback.Callback)5 JsonValue (org.forgerock.json.JsonValue)5 IOException (java.io.IOException)4 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)4 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)4 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)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 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FailedLoginException (javax.security.auth.login.FailedLoginException)2 LoginException (javax.security.auth.login.LoginException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2