Package java.net

Examples of java.net.PasswordAuthentication


    }

    protected PasswordAuthentication getPasswordAuthentication() {
    // username, password
    // sets http authentication
    return new PasswordAuthentication(username, password.toCharArray());
    }
View Full Code Here


  private static void setProxyAuthenticator(boolean isProxyAuth) {
    if (isProxyAuth) {
        class SimpleAuthenticator extends Authenticator {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(Configuration.getProxyUser(), Configuration.getProxyPassword().toCharArray());
            }               
        }
        Authenticator.setDefault(new SimpleAuthenticator());
    } else {
        Authenticator.setDefault(null);
View Full Code Here

  private static void setProxyAuthenticator(boolean isProxyAuth) {
    if (isProxyAuth) {
        class SimpleAuthenticator extends Authenticator {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(Configuration.getProxyUser(), Configuration.getProxyPassword().toCharArray());
            }               
View Full Code Here

        final String userPassword = creditionals.getPassword();
        Authenticator.setDefault(new Authenticator() {

            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                PasswordAuthentication pa = new PasswordAuthentication(userName, userPassword.toCharArray());
                return pa;
            }
           
        });
    }
View Full Code Here

    this.password = password;
  }

  @Override
  protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(user, password.toCharArray());
  }
View Full Code Here

              throw new ConfigurationException("Could not retrieve password from file", e);
            }
        }

        if(user != null && password != null) {
            PasswordAuthentication passwdAuth = new PasswordAuthentication(user, password.toCharArray());
            creds.add(passwdAuth);
        } else {
            throw new ConfigurationException("ESB property '" + Environment.REGISTRY_USER + "' or '" + Environment.REGISTRY_PASSWORD + "' not set.  ESB properties load may have failed.");
        }
    }
View Full Code Here

  if (authScheme == null) {
      return null;
  }

  if (authUser == null) {
      PasswordAuthentication pa = getPassword(protocol);
      if (pa == null) {
    return null;
      }
      String user = pa.getUserName();
      char[] password = pa.getPassword();
      if (user == null || password == null) {
    return null;
      }
      authUser = user;
      authPassword = new String(password);
View Full Code Here

                    String protocol = url.getProtocol();
                    int port = url.getPort();
                    if (port == -1) {
                        port = "https".equalsIgnoreCase(protocol) ? 443 : 80;
                    }
                    PasswordAuthentication auth =
                            Authenticator.requestPasswordAuthentication(null,
                                    port, protocol, "", authMethod);
                    if (auth == null) return null;
                    user = auth.getUserName();
                    password = new String(auth.getPassword());
                } catch (Exception ex) { }
            }
            Type2Message type2 = (Type2Message) message;
            message = new Type3Message(type2, password, domain, user,
                    Type3Message.getDefaultWorkstation(), 0);
View Full Code Here

        this.now = System.currentTimeMillis();

        if (p_user != null && p_pass != null)
            Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication
                        (p_user, p_pass.toCharArray());
                } });
    }
View Full Code Here

        // possibly supply credentials that were stored in the keyring
        if (state == State.Keyring) {
            char[] password = getPasswordFromKeyring(lastUsername);
            if (password != null)
                return new PasswordAuthentication(lastUsername, password);
            else
                state = State.UserEntry1;
        }

        // create user interface components to prompt for username and password
        JTextField username = new JTextField(2);
        JPasswordField password = new JPasswordField(2);
        JComponent focus = username;
        if (StringUtils.hasValue(lastUsername)) {
            username.setText(lastUsername);
            focus = password;
        }
        JLabel usernameLabel = new JLabel(resources.getString("Username"),
                SwingConstants.RIGHT);
        JLabel passwordLabel = new JLabel(resources.getString("Password"),
                SwingConstants.RIGHT);
        Dimension d = usernameLabel.getPreferredSize();
        d.width = Math.max(d.width, passwordLabel.getPreferredSize().width);
        usernameLabel.setPreferredSize(d);
        passwordLabel.setPreferredSize(d);

        // if "remember me" support is enabled, create a checkbox
        JCheckBox rememberMe = null;
        if (rememberMeDays > 0) {
            rememberMe = new JCheckBox(
                    resources.getString("Remember_Me.Prompt"));
            rememberMe.setToolTipText(resources.format(
                "Remember_Me.Tooltip_FMT", rememberMeDays));
            Font f = rememberMe.getFont();
            f = f.deriveFont(f.getSize2D() * 0.8f);
            rememberMe.setFont(f);
        }

        // prompt the user for credentials
        final String title = (StringUtils.hasValue(this.title) ? this.title
                : resources.getString("Title"));
        final Object[] message = new Object[] {
                resources.formatStrings("Prompt_FMT", getRequestingPrompt()),
                BoxUtils.vbox(5),
                BoxUtils.hbox(15, usernameLabel, 5, username),
                BoxUtils.hbox(15, passwordLabel, 5, password),
                BoxUtils.hbox(BoxUtils.GLUE, rememberMe),
                new JOptionPaneTweaker.GrabFocus(focus) };
        final int[] userChoice = new int[1];

        try {
            Runnable r = new Runnable() {
                public void run() {
                    userChoice[0] = JOptionPane.showConfirmDialog(
                        parentComponent, message, title,
                        JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.PLAIN_MESSAGE);
                }
            };
            if (SwingUtilities.isEventDispatchThread())
                r.run();
            else
                SwingUtilities.invokeAndWait(r);
        } catch (Exception e) {
        }

        // record metadata about this password request
        lastUrl = getEffectiveURL();
        lastTimestamp = System.currentTimeMillis();
        lastUsername = username.getText().trim();
        prefs.put(prefsKey(LAST_USERNAME), lastUsername);

        if (userChoice[0] == JOptionPane.OK_OPTION) {
            // if the user entered credentials, return them.
            if (rememberMe != null && rememberMe.isSelected())
                savePasswordToKeyring(lastUsername, password.getPassword());
            return new PasswordAuthentication(lastUsername,
                    password.getPassword());
        } else {
            // if the user cancelled the operation, abort.
            state = State.Cancelled;
            return null;
View Full Code Here

TOP

Related Classes of java.net.PasswordAuthentication

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.