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;
}
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();
}
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);
}
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());
}
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());
}
Aggregations