use of javax.security.auth.callback.TextOutputCallback in project OpenAM by OpenRock.
the class RestAuthTextOutputCallbackHandlerTest method shouldNotUpdateCallbackFromRequest.
@Test
public void shouldNotUpdateCallbackFromRequest() throws RestAuthResponseException, RestAuthException {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
TextOutputCallback textOutputCallback = mock(TextOutputCallback.class);
//When
boolean updated = testOutputRestAuthCallbackHandler.updateCallbackFromRequest(request, response, textOutputCallback);
//Then
assertTrue(!updated);
}
use of javax.security.auth.callback.TextOutputCallback in project OpenAM by OpenRock.
the class RestAuthTextOutputCallbackHandlerTest method shouldConvertFromJson.
@Test
public void shouldConvertFromJson() throws RestAuthException {
//Given
TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "MESSAGE");
JsonValue jsonTextOutputCallback = JsonValueBuilder.jsonValue().array("output").add(JsonValueBuilder.jsonValue().put("value", "MESSAGE").build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "TextOutputCallback").build();
//When
TextOutputCallback convertedTextOutputCallback = testOutputRestAuthCallbackHandler.convertFromJson(textOutputCallback, jsonTextOutputCallback);
//Then
assertEquals(textOutputCallback, convertedTextOutputCallback);
assertEquals("MESSAGE", convertedTextOutputCallback.getMessage());
assertEquals(TextOutputCallback.INFORMATION, convertedTextOutputCallback.getMessageType());
}
use of javax.security.auth.callback.TextOutputCallback in project OpenAM by OpenRock.
the class RestAuthTextOutputCallbackHandlerTest method shouldFailToConvertFromJsonWithTypeLowerCase.
@Test
public void shouldFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException {
//Given
TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "MESSAGE");
JsonValue jsonTextOutputCallback = JsonValueBuilder.jsonValue().array("output").add(JsonValueBuilder.jsonValue().put("value", "MESSAGE").build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "tExtoUtputcallback").build();
//When
TextOutputCallback convertedTextOutputCallback = testOutputRestAuthCallbackHandler.convertFromJson(textOutputCallback, jsonTextOutputCallback);
//Then
assertEquals(textOutputCallback, convertedTextOutputCallback);
assertEquals("MESSAGE", convertedTextOutputCallback.getMessage());
assertEquals(TextOutputCallback.INFORMATION, convertedTextOutputCallback.getMessageType());
}
use of javax.security.auth.callback.TextOutputCallback in project OpenAM by OpenRock.
the class RestAuthTextOutputCallbackHandlerTest method shouldConvertToJsonAndEscapeCharacters.
@Test
public void shouldConvertToJsonAndEscapeCharacters() throws RestAuthException, JSONException {
//Given
final String script = "for (var i = 0; i < 10; i++) { alert(\"alert\"); }";
TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, script);
//When
JsonValue jsonObject = testOutputRestAuthCallbackHandler.convertToJson(textOutputCallback, 1);
//Then
assertEquals("TextOutputCallback", jsonObject.get("type").asString());
assertNotNull(jsonObject.get("output"));
assertEquals(2, jsonObject.get("output").size());
assertEquals(script, jsonObject.get("output").get(0).get("value").asString());
assertEquals(TextOutputCallback.INFORMATION, Integer.parseInt(jsonObject.get("output").get(1).get("value").asString()));
assertEquals(2, jsonObject.size());
// Round-trip via toString/parsing with JSONObject to verify correct escaping
JSONObject parsed = new JSONObject(jsonObject.toString());
assertEquals(script, parsed.getJSONArray("output").getJSONObject(0).getString("value"));
}
use of javax.security.auth.callback.TextOutputCallback in project OpenAM by OpenRock.
the class LDAPCallbacks method chgPwdCallback.
private void chgPwdCallback() throws LoginException {
char[] pwd = null;
if (callbackHandler == null) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
}
Callback[] callbacks = new Callback[4];
callbacks[0] = new TextOutputCallback(TextOutputCallback.INFORMATION, "Change Password");
callbacks[1] = new PasswordCallback("EnterOld Password", false);
callbacks[2] = new PasswordCallback("Enter New Password", false);
callbacks[3] = new PasswordCallback("Confirm Password", false);
try {
callbackHandler.handle(callbacks);
oldPassword = charToString(((PasswordCallback) callbacks[1]).getPassword(), callbacks[1]);
newPassword = charToString(((PasswordCallback) callbacks[2]).getPassword(), callbacks[2]);
confirmPassword = charToString(((PasswordCallback) callbacks[3]).getPassword(), callbacks[3]);
} catch (java.io.IOException ioe) {
throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
}
}
Aggregations