Package javax.security.auth.callback

Examples of javax.security.auth.callback.PasswordCallback


      throws LoginException
   {
      try
      {
         NameCallback cbName = new NameCallback("Enter username");
         PasswordCallback cbPassword = new PasswordCallback("Enter password", false);
  
         // Get the username and password from the callback handler
         callbackHandler.handle(new Callback[] { cbName, cbPassword });
         username = cbName.getName();
      }
View Full Code Here


                // may later add a Callback to obtain the server info to verify is a server was identified with
                // the specified username.

                for (Callback current : callbacks) {
                    if (current instanceof PasswordCallback) {
                        PasswordCallback pcb = (PasswordCallback) current;
                        char[] password = pcb.getPassword();
                        return (password != null && password.length > 0);
                    } else if (current instanceof VerifyPasswordCallback) {
                        return ((VerifyPasswordCallback) current).isVerified();
                    } else if (current instanceof DigestHashCallback) {
                        return ((DigestHashCallback) current).getHash() != null;
View Full Code Here

//                    } else {
//                        logger.fine("cb.getPrompt(): " + cb.getPrompt());
//                        throw new UnsupportedCallbackException(callbacks[i]);
//                    }
                } else if (callbacks[i] instanceof PasswordCallback) {
                    PasswordCallback cb = (PasswordCallback) callbacks[i];
                    if (usePW) {
                        // TODO: replace by native func to suppress password echo
                        System.out.print(cb.getPrompt() + " ");
                        System.out.flush();
                        String pw = new BufferedReader(new InputStreamReader(System.in)).readLine();
                        cb.setPassword(pw.toCharArray());
                        pw = null;
                    } else {
                        cb.setPassword(new char[0]);
                    }
                } else if (callbacks[i] instanceof ConfirmationCallback) {
                    ConfirmationCallback cb = (ConfirmationCallback) callbacks[i];
                    cb.setSelectedIndex(cb.getDefaultOption());
                } else {
                    throw new UnsupportedCallbackException(callbacks[i]);
                }
            }
        }
View Full Code Here

            }
            String host = args[0];
            int port = Integer.parseInt(args[1]);
            logger.info("connect to host(" + host + ":" + port + ")");
            NameCallback ncb = new NameCallback("user:");
            PasswordCallback pwcb = new PasswordCallback("password:", false);
            Callback[] callbacks = {ncb, pwcb};
            MyCallbackHandler cb = new MyCallbackHandler();
            usePW = true;
            cb.handle(callbacks);
            String username = ncb.getName();
            String userpw = pwcb.getPassword().toString();
            if (useKS) {
                PasswordCallback kspw = new PasswordCallback("keystore password:", true);
                Callback[] kcallbacks = {kspw};
                cb.handle(kcallbacks);
                File caTop = new File(caTopPath);
                File keyStore = new File(keystorePath);
                JGDIProxy.setupSSL(host, port, caTop, keyStore, kspw.getPassword());
                kspw.clearPassword();
                kspw = null;
            }
            Object credentials = new String[]{username, userpw};
            JGDIProxy jgdiProxy = JGDIFactory.newJMXInstance(host, port, credentials);
View Full Code Here

                case TYPE_USER:
                case TYPE_SGE_DAEMON:   
                    if(pwFile == null) {
                        CallbackHandler cbh = new TextCallbackHandler();
                       
                        PasswordCallback keystorePWCallback = new PasswordCallback("keystore password: ", false);
                       
                        Callback [] cb = new Callback [] {
                            keystorePWCallback,
                        };
                       
                        cbh.handle(cb);
                        pw = keystorePWCallback.getPassword();
                        if(pw == null) {
                            pw = new char[0];
                        }
                    } else {
                        FileReader fr = new FileReader(pwFile);
View Full Code Here

            }
           
            nc.setName(result);
           
         } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callbacks[i];
           
            System.err.print(pc.getPrompt());
            System.err.flush();
           
            pc.setPassword(readPassword(System.in));
           
         } else if (callbacks[i] instanceof ConfirmationCallback) {
            confirmation = (ConfirmationCallback) callbacks[i];
           
         } else {
View Full Code Here

            log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
            return loginSucceeded;
        }
       
        NameCallback usernameCallback = new NameCallback("username");
        PasswordCallback passwordCallback = new PasswordCallback("password", true);

        try {
            callbackHandler.handle(new Callback[]{usernameCallback, passwordCallback});
        } catch (UnsupportedCallbackException ex) {
            LoginException le = new LoginException("callback is not supported");
            le.initCause(ex);
            throw le;
        } catch (IOException ex) {
            LoginException le = new LoginException("io error in callback handler");
            le.initCause(ex);
            throw le;
        }

        String password = new String(passwordCallback.getPassword());
        Properties props = new Properties();
        try {
            props.load(new ByteArrayInputStream(password.getBytes()));
        } catch (IOException ex) {
            // Can not happen we are reading from a byte array
View Full Code Here

        log.entering("UnixLoginModule", "login");

        if (confError != null) {
            throw RB.newLoginException("unixlogin.error.conf", new Object[]{confError});
        }
        PasswordCallback pwCallback = new PasswordCallback(RB.getString("unixlogin.userprompt"), false);
        NameCallback nameCallback = new NameCallback(RB.getString("unixlogin.pwprompt"));

        try {
            callbackHandler.handle(new Callback[]{nameCallback, pwCallback});
        } catch (IOException ex) {
            throw RB.newLoginException("unixlogin.error.iocb", ex,
                    new Object[]{ex.getLocalizedMessage()});
        } catch (UnsupportedCallbackException ex) {
            throw RB.newLoginException("unixlogin.error.invalidcb", ex,
                    new Object[]{ex.getLocalizedMessage()});
        }

        String username = nameCallback.getName();
        if (username == null || username.length() == 0) {
            loginSucceded = false;
            log.exiting("UnixLoginModule", "login", Boolean.FALSE);
            return loginSucceded;
        }

        char[] pw = pwCallback.getPassword();
        if (pw == null) {
            loginSucceded = false;
            log.exiting("UnixLoginModule", "login", Boolean.FALSE);
            return loginSucceded;
        }
View Full Code Here

     * @return <code>true</code> on successfull authentication. <code>false</code>
     *         if username of password is invalid.
     */
    public boolean login() throws LoginException {
        log.entering("TestLoginModule", "login");
        PasswordCallback pwCallback = new PasswordCallback(RB.getString("unixlogin.userprompt"), false);
        NameCallback nameCallback = new NameCallback(RB.getString("unixlogin.pwprompt"));

        try {
            callbackHandler.handle(new Callback[]{nameCallback, pwCallback});
        } catch (IOException ex) {
View Full Code Here

                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                } else if (callbacks[i] instanceof PasswordCallback) {

                    PasswordCallback cb = (PasswordCallback) callbacks[i];

                    String prompt = cb.getPrompt().toLowerCase();
                    logger.fine("handle password callback " + prompt);
                    if (prompt.indexOf("keystore password") >= 0) {
                        logger.fine("found keystore password callback");
                        cb.setPassword(cluster.getKeystorePassword());
                    } else if (prompt.indexOf("key password") >= 0) {
                        logger.fine("found key password callback");
                        cb.setPassword(cluster.getPrivateKeyPassword());
                    } else {
                        throw new UnsupportedCallbackException(callbacks[i]);
                    }
                } else if (callbacks[i] instanceof ConfirmationCallback) {
                    logger.fine("handle confirm callback");
                    ConfirmationCallback cb = (ConfirmationCallback) callbacks[i];
                    cb.setSelectedIndex(cb.getDefaultOption());
                } else {
                    throw new UnsupportedCallbackException(callbacks[i]);
                }
            }
        }
View Full Code Here

TOP

Related Classes of javax.security.auth.callback.PasswordCallback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.