use of javax.security.auth.callback.ChoiceCallback in project Payara by payara.
the class DefaultGUICallbackHandlerTest method run.
private void run() throws IOException, UnsupportedCallbackException {
CallbackHandler ch = new DefaultGUICallbackHandler();
ChoiceCallback choiceCB = new ChoiceCallback("Choose one", new String[] { "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh" }, 0, false);
ConfirmationCallback confirmationCB = new ConfirmationCallback("Decide", ConfirmationCallback.INFORMATION, ConfirmationCallback.OK_CANCEL_OPTION, ConfirmationCallback.OK);
NameCallback nameCB = new NameCallback("Username", "who");
PasswordCallback passwordCB = new PasswordCallback("Password", false);
TextInputCallback textInCB = new TextInputCallback("Enter something interesting", "Good stuff to start with...");
TextOutputCallback textOutCB = new TextOutputCallback(TextOutputCallback.WARNING, "Some fascinating text of great interest to the user goes here");
LanguageCallback langCB = new LanguageCallback();
Callback[] callbacks = new Callback[] { choiceCB, confirmationCB, nameCB, passwordCB, textInCB, textOutCB, langCB };
ch.handle(callbacks);
System.out.println("ChoiceCallback choice(s):");
for (int index : choiceCB.getSelectedIndexes()) {
if (index > 0) {
System.out.println(" " + choiceCB.getChoices()[index]);
} else {
System.out.println(" Selection not made");
}
}
System.out.print("ConfirmationCallback result: ");
if (confirmationCB.getOptions() == null) {
System.out.println(confirmationResultToString(confirmationCB.getSelectedIndex()));
} else {
System.out.println(confirmationCB.getOptions()[confirmationCB.getSelectedIndex()]);
}
System.out.println("NameCallback result: " + nameCB.getName());
System.out.println("PasswordCallback result: " + new String(passwordCB.getPassword()));
System.out.println("TextInputCallback result: " + textInCB.getText());
System.out.println("LanguageCallback result: " + langCB.getLocale().getDisplayName());
}
use of javax.security.auth.callback.ChoiceCallback in project kafka by apache.
the class JaasBasicAuthFilterTest method testUnsupportedCallback.
@Test
public void testUnsupportedCallback() {
String authHeader = authHeader("basic", "user", "pwd");
CallbackHandler callbackHandler = new JaasBasicAuthFilter.BasicAuthCallBackHandler(authHeader);
Callback unsupportedCallback = new ChoiceCallback("You take the blue pill... the story ends, you wake up in your bed and believe whatever you want to believe. " + "You take the red pill... you stay in Wonderland, and I show you how deep the rabbit hole goes.", new String[] { "blue pill", "red pill" }, 1, true);
assertThrows(ConnectException.class, () -> callbackHandler.handle(new Callback[] { unsupportedCallback }));
}
Aggregations