Code example for PasswordAuthentication

Methods: getUserName

0
        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) 
     */ 
    public void store(RequestorType requestorType, PasswordAuthentication credentials) throws CredentialsManagerException {
        if (requestorType == null)
            return; 
        switch(requestorType) {
        case SERVER:
            Main.pref.put("osm-server.username", credentials.getUserName());
            if (credentials.getPassword() == null) {
                Main.pref.put("osm-server.password", null); 
            } else { 
                Main.pref.put("osm-server.password", String.valueOf(credentials.getPassword()));
            } 
            break; 
        case PROXY:
            throw new UnsupportedOperationException();
//            Main.pref.put(ProxyPreferencesPanel.PROXY_USER, credentials.getUserName()); 
//            if (credentials.getPassword() == null) { 
//                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, null); 
//            } else { 
//                Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, String.valueOf(credentials.getPassword())); 
//            } 
//            break; 
        } 
    } 
 
    /** 
     * @see CredentialsManager#getCredentials(RequestorType, boolean) 
     */ 
    public CredentialsManagerResponse getCredentials(RequestorType requestorType, boolean noSuccessWithLastResponse) throws CredentialsManagerException{
        if (requestorType == null)
            return null; 
        PasswordAuthentication credentials =  lookup(requestorType);
        String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();
        String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
 
        CredentialsManagerResponse response = new CredentialsManagerResponse();
 
        /* 
Connect your IDE to all the code out there  Get Codota for Java