Search in sources :

Example 36 with ChoiceCallback

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());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) LanguageCallback(javax.security.auth.callback.LanguageCallback) TextInputCallback(javax.security.auth.callback.TextInputCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) TextInputCallback(javax.security.auth.callback.TextInputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) LanguageCallback(javax.security.auth.callback.LanguageCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 37 with ChoiceCallback

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 }));
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) CallbackHandler(javax.security.auth.callback.CallbackHandler) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) Callback(javax.security.auth.callback.Callback) Test(org.junit.jupiter.api.Test)

Aggregations

ChoiceCallback (javax.security.auth.callback.ChoiceCallback)37 Callback (javax.security.auth.callback.Callback)24 NameCallback (javax.security.auth.callback.NameCallback)18 Test (org.testng.annotations.Test)17 PasswordCallback (javax.security.auth.callback.PasswordCallback)16 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)13 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)9 JsonValue (org.forgerock.json.JsonValue)8 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)5 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)5 TextInputCallback (javax.security.auth.callback.TextInputCallback)5 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)5 SSOException (com.iplanet.sso.SSOException)4 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)4 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)4 ArrayList (java.util.ArrayList)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)3 IOException (java.io.IOException)3 Map (java.util.Map)3