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 apex-core by apache.
the class DefaultCallbackHandler method processCallback.
protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof NameCallback) {
NameCallback namecb = (NameCallback) callback;
namecb.setName(context.getValue(SecurityContext.USER_NAME));
} else if (callback instanceof PasswordCallback) {
PasswordCallback passcb = (PasswordCallback) callback;
passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
} else if (callback instanceof RealmCallback) {
RealmCallback realmcb = (RealmCallback) callback;
realmcb.setText(context.getValue(SecurityContext.REALM));
} else if (callback instanceof TextOutputCallback) {
TextOutputCallback textcb = (TextOutputCallback) callback;
if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
logger.info(textcb.getMessage());
} else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
logger.warn(textcb.getMessage());
} else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
logger.error(textcb.getMessage());
} else {
logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
}
} else {
throw new UnsupportedCallbackException(callback);
}
}
use of javax.security.auth.callback.TextOutputCallback in project OpenAM by OpenRock.
the class LDAPCallbacks method messageCallback.
private void messageCallback(int msgType, String msg) throws LoginException {
if (callbackHandler == null) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
}
try {
Callback[] callbacks = new Callback[1];
callbacks[0] = new TextOutputCallback(msgType, msg);
callbackHandler.handle(callbacks);
} catch (java.io.IOException ioe) {
throw new LoginException(ioe.toString());
} catch (UnsupportedCallbackException uce) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
} catch (IllegalArgumentException ill) {
debug.message("message type missing");
throw new LoginException(bundle.getString("IllegalArgs"));
}
}
use of javax.security.auth.callback.TextOutputCallback in project OpenAM by OpenRock.
the class LDAPCallbacks method loginCallbacks.
private void loginCallbacks() throws LoginException {
if (callbackHandler == null) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
}
Callback[] callbacks = new Callback[3];
callbacks[0] = new TextOutputCallback(TextOutputCallback.INFORMATION, "LDAP Authentication");
callbacks[1] = new NameCallback("Enter Username :");
callbacks[2] = new PasswordCallback("Enter Password :", false);
try {
callbackHandler.handle(callbacks);
username = ((NameCallback) callbacks[1]).getName();
passwd = charToString(((PasswordCallback) callbacks[2]).getPassword(), callbacks[2]);
} catch (java.io.IOException ioe) {
throw new LoginException(bundle.getString("NoCallbackHandler"));
} catch (UnsupportedCallbackException uce) {
throw new LoginException();
}
}
Aggregations