Example usage for javax.security.auth.callback NameCallback getPrompt

List of usage examples for javax.security.auth.callback NameCallback getPrompt

Introduction

In this page you can find the example usage for javax.security.auth.callback NameCallback getPrompt.

Prototype

public String getPrompt() 

Source Link

Document

Get the prompt.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.jaas.DialogAuthenticationCallbackHandler.java

/** Implementation of the handle method specified by
 * <code> javax.security.auth.callback.CallbackHandler </code>
 * @param callbacks <code>Array of javax.security.auth.callback.CallbackHandler</code>
 *
 *///w w w. j a  v  a2s . c  om
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
    int result = showDialog();

    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof TextOutputCallback) {
            // Ignore this section for now. This will be used when a generic callback handler
            // is being implemented. In our current implementation, we are only expecting the
            //login type callback handler.
        } else if (callbacks[i] instanceof NameCallback) {
            // prompt the user for a username
            NameCallback nc = (NameCallback) callbacks[i];
            String strPrompt = nc.getPrompt();
            String strName = "";

            //                if (strPrompt.equals(authResBundle.getString("Keystore alias: "))) {
            if (strPrompt.equals(authResBundle.getString("Keystore.alias."))) {
                strName = txtAlias.getText();
            }

            nc.setName(strName);
        } else if (callbacks[i] instanceof PasswordCallback) {
            // prompt the user for sensitive information
            PasswordCallback pc = (PasswordCallback) callbacks[i];
            String strPrompt = pc.getPrompt();
            char[] chrPass = new char[0];

            //                if (strPrompt.equals(authResBundle.getString("Keystore password: "))) {
            if (strPrompt.equals(authResBundle.getString("Keystore.password."))) {
                /* As of now hide the Keystore password part from the user and
                   read directly from the properties file
                   chrPass = txtStorepass.getPassword() ; */
                chrPass = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storepass")
                        .toCharArray();

                if ((chrPass == null) || (chrPass.length == 0)) {
                    log.error("Property jaxr-ebxml.security.storepass is undefined");
                }
                //                } else if (strPrompt.equals(authResBundle.getString("Private key password (optional): "))) {
            } else if (strPrompt.equals(authResBundle.getString("Private.key.password.optional."))) {
                chrPass = txtKeypass.getPassword();
            }

            pc.setPassword(chrPass);
        } else if (callbacks[i] instanceof ConfirmationCallback) {
            ConfirmationCallback cc = (ConfirmationCallback) callbacks[i];

            if (result == OK) {
                cc.setSelectedIndex(ConfirmationCallback.OK);
            } else {
                cc.setSelectedIndex(ConfirmationCallback.CANCEL);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i],
                    JAXRResourceBundle.getInstance().getString("message.error.unrecognized.callback"));
        }
    }
}

From source file:org.forgerock.openam.forgerockrest.authn.callbackhandlers.RestAuthNameCallbackHandler.java

/**
 * {@inheritDoc}/*from   w ww  .  j a v a  2  s . c om*/
 */
public JsonValue convertToJson(NameCallback callback, int index) {

    String prompt = callback.getPrompt();
    String name = callback.getName();

    JsonValue jsonValue = JsonValueBuilder.jsonValue().put("type", CALLBACK_NAME).array("output")
            .addLast(createOutputField("prompt", prompt)).array("input").addLast(createInputField(index, name))
            .build();

    return jsonValue;
}

From source file:org.kalypso.test.bsu.wfs.SingleSignonTest.java

public void testSigngleSignon() throws Exception {
    try {/*from   w ww  .ja v  a  2  s  .  c  o  m*/
        copy(new File("D:/eclipse3.1/tmp/web_FlowsAStestLogin.html"));
        LoginContext loginContext = null;
        System.setProperty("java.security.auth.login.config", "D:/eclipse3.1/tmp/jaasConf.txt");
        // Login-Kontext fr die Konfiguration "Demo" erzeugen
        // loginContext = new LoginContext( "Demo" );
        loginContext = new LoginContext("Demo", new CallbackHandler() {

            public void handle(Callback[] callbacks) {
                for (int i = 0; i < callbacks.length; i++) {
                    Callback callback = callbacks[i];
                    if (callback instanceof NameCallback) {
                        final NameCallback nCall = (NameCallback) callback;
                        System.out.println(nCall.getPrompt());
                        nCall.setName("Flowsad");
                    } else if (callback instanceof PasswordCallback) {
                        final PasswordCallback call = (PasswordCallback) callback;
                        System.out.println(call.getPrompt());
                        call.setPassword(new char[] { ' ', ' ', });
                    } else
                        System.out.println("unknown Callback: " + callback.getClass().getName());
                }
            }

        });
        // Durchfhrung des Logins
        loginContext.login();
        System.out.println("authentication succeeded");

        // Die Principals ermitteln...
        Set principals = loginContext.getSubject().getPrincipals();
        // ...und in einer Iteration ausgeben
        Iterator it = principals.iterator();
        Principal p;
        while (it.hasNext()) {
            p = (Principal) it.next();
            System.out.println(p);
        }
        System.out.println("logging out...");
        copy(new File("D:/eclipse3.1/tmp/web_FlowsAdmitLogin.html"));

        loginContext.logout();
    } catch (Exception e) {
        System.out.println("authentication failed");
        throw e;
    }
}