Java 8 PasswordAuthentication - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PasswordAuthentication class.

This code example shows how to use the following methods:getPassword, getUserName
This code example shows how to use the following methods:
     * @return the PasswordAuthentication instance 
     */ 
    protected PasswordAuthentication getPasswordAuthentication() {
        if ( m_auth == null ) {
            m_auth = new PasswordAuthentication(
                        m_username, m_password.toCharArray());
        } 
        return m_auth;
    } 
 
    // ------------------------------------------------------------------------ 
     
    /** 
     * Creates a new PasswordAuthenticator for the given name and password and 
     * sets it as the default Authenticator for use within Java networking. 
     */ 
    public static void setAuthentication(String username, String password) {
        Authenticator.setDefault(new PasswordAuthenticator(username,password));
    } 
     
6
CodeRank
This code example shows how to use the following methods:
     * Saves contents to preferences. 
     */ 
    public void saveToPreferences() { 
        CredentialsAgent cm = CredentialsManager.getInstance();
        try { 
            PasswordAuthentication pa = new PasswordAuthentication(
                    tfOsmUserName.getText().trim(),
                    tfOsmPassword.getPassword()
            ); 
            cm.store(RequestorType.SERVER, OsmApi.getOsmApi().getHost(), pa);
        } catch (CredentialsAgentException e) {
            Main.error(e);
            Main.warn(tr("Failed to save OSM credentials to credential manager.")); 
            Main.warn(tr("Current credential manager is of type ''{0}''", cm.getClass().getName()));
        } 
    } 
 
    /** 
     * Clears the password field. 
     */ 
6
CodeRank
This code example shows how to use the following methods:
            boolean tried = credentialsTried.get(getRequestorType()) != null;
            CredentialsAgentResponse response = CredentialsManager.getInstance().getCredentials(getRequestorType(), getRequestingHost(), tried);
            if (response == null || response.isCanceled())
                return null; 
            credentialsTried.put(getRequestorType(), true);
            return new PasswordAuthentication(response.getUsername(), response.getPassword());
        } catch(CredentialsAgentException e) {
            Main.error(e);
            return null; 
        } 
    } 
 
    public boolean isEnabled() { 
        return enabled;
    } 
 
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
                    System.out.println("::::: PROVIDING Kerberos PASSWORD AND USERNAME " + kuser +":"+kpass+" :::::");
                return (new PasswordAuthentication (kuser, kpass.toCharArray()));
            } else { 
                if(showhint != null)
                    System.out.println("::::: PROVIDING PASSWORD AND USERNAME " + user +":"+pass+" :::::");
                return (new PasswordAuthentication (user, pass.toCharArray()));
            } 
        } 
    } 
 
    /** 
     * Creates a new instance of WebGet 
     */ 
    static void url(String urls) throws Exception {
        Authenticator.setDefault (new MyAuthenticator ());
        //Security.setProperty("auth.login.defaultCallbackHandler", "WebGet$Handler"); 
        URL url = new URL(urls);
        InputStream ins = url.openConnection().getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
        String str;
5
CodeRank
This code example shows how to use the following methods:
        try { 
            factory = ConnectionFactory.newInstance();
            factory.setProperties(scoutProperties);
            connection = factory.createConnection();
 
            PasswordAuthentication passwdAuth = new PasswordAuthentication(userid,
                    passwd.toCharArray());
            Set<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
            creds.add(passwdAuth);
 
            connection.setCredentials(creds);
            System.out.println("\n*********Connection established with UDDI Registry************");
        } catch (JAXRException e) {
            e.printStackTrace();
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
        @Override 
        public PasswordAuthentication getPasswordAuthentication () {
            if (!getRequestingPrompt().equals(REALM)) {
                BasicLongCredentials.error = true;
            } 
            return new PasswordAuthentication (USERNAME, PASSWORD.toCharArray());
        } 
    } 
 
    static class Handler implements HttpHandler { 
        public void handle (HttpExchange t) throws IOException {
            InputStream is = t.getRequestBody();
            while (is.read () != -1) ;
            is.close();
            t.sendResponseHeaders(200, -1);
            HttpPrincipal p = t.getPrincipal();
            if (!p.getUsername().equals(USERNAME)) {
                error = true;
            } 
            if (!p.getRealm().equals(REALM)) {
5
CodeRank
This code example shows how to use the following methods:getUserName
        case SERVER:
            user = Main.pref.get("osm-server.username", null);
            password = Main.pref.get("osm-server.password", null);
            if (user == null)
                return null; 
            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray());
        case PROXY:
            throw new UnsupportedOperationException();
//            user = Main.pref.get(ProxyPreferencesPanel.PROXY_USER, null); 
//            password = Main.pref.get(ProxyPreferencesPanel.PROXY_PASS, null); 
//            if (user == null) 
//                return null; 
//            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray()); 
        } 
        return null; 
    } 
 
    /** 
     * @see CredentialsManager#store(RequestorType, PasswordAuthentication) 
     */ 

5
CodeRank
This code example shows how to use the following methods:
      //String hostname = getRequestingHost(); 
      //InetAddress ipaddr = getRequestingSite(); 
      //int port = getRequestingPort(); 
    System.out.println("Authenticating: user="+username);
    // Return the information 
    return new PasswordAuthentication(username, password.toCharArray());
  } 
   
} 
4
CodeRank
This code example shows how to use the following methods:
        this.userName = userName;
        this.passWord = passWord;
    } 
 
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(userName, passWord.toCharArray());
    } 
} 
4
CodeRank

Related Java 8 PasswordAuthentication Questions & Answers:

See Code Examples for Java 8 PasswordAuthentication Methods: