Java Code Examples for java.net.PasswordAuthentication#getPassword()

The following examples show how to use java.net.PasswordAuthentication#getPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NegotiateCallbackHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void getAnswer() {
    if (!answered) {
        answered = true;

        if (LoginConfigImpl.HTTP_USE_GLOBAL_CREDS) {
            PasswordAuthentication passAuth =
                    Authenticator.requestPasswordAuthentication(
                            hci.host, hci.addr, hci.port, hci.protocol,
                            hci.prompt, hci.scheme, hci.url, hci.authType);
            /**
             * To be compatible with existing callback handler implementations,
             * when the underlying Authenticator is canceled, username and
             * password are assigned null. No exception is thrown.
             */
            if (passAuth != null) {
                username = passAuth.getUserName();
                password = passAuth.getPassword();
            }
        }
    }
}
 
Example 2
Source File: NTLMAuthentication.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
Example 3
Source File: NTLMAuthentication.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
Example 4
Source File: NegotiateCallbackHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void getAnswer() {
    if (!answered) {
        answered = true;

        if (LoginConfigImpl.HTTP_USE_GLOBAL_CREDS) {
            PasswordAuthentication passAuth =
                    Authenticator.requestPasswordAuthentication(
                            hci.host, hci.addr, hci.port, hci.protocol,
                            hci.prompt, hci.scheme, hci.url, hci.authType);
            /**
             * To be compatible with existing callback handler implementations,
             * when the underlying Authenticator is canceled, username and
             * password are assigned null. No exception is thrown.
             */
            if (passAuth != null) {
                username = passAuth.getUserName();
                password = passAuth.getPassword();
            }
        }
    }
}
 
Example 5
Source File: NegotiateCallbackHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void getAnswer() {
    if (!answered) {
        answered = true;
        PasswordAuthentication passAuth =
                Authenticator.requestPasswordAuthentication(
                hci.authenticator,
                hci.host, hci.addr, hci.port, hci.protocol,
                hci.prompt, hci.scheme, hci.url, hci.authType);
        /**
         * To be compatible with existing callback handler implementations,
         * when the underlying Authenticator is canceled, username and
         * password are assigned null. No exception is thrown.
         */
        if (passAuth != null) {
            username = passAuth.getUserName();
            password = passAuth.getPassword();
        }
    }
}
 
Example 6
Source File: NTLMAuthentication.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
Example 7
Source File: NegotiateCallbackHandler.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void getAnswer() {
    if (!answered) {
        answered = true;
        PasswordAuthentication passAuth =
                Authenticator.requestPasswordAuthentication(
                hci.host, hci.addr, hci.port, hci.protocol,
                hci.prompt, hci.scheme, hci.url, hci.authType);
        /**
         * To be compatible with existing callback handler implementations,
         * when the underlying Authenticator is canceled, username and
         * password are assigned null. No exception is thrown.
         */
        if (passAuth != null) {
            username = passAuth.getUserName();
            password = passAuth.getPassword();
        }
    }
}
 
Example 8
Source File: NTLMAuthentication.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
Example 9
Source File: NTLMAuthentication.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
Example 10
Source File: XDMApp.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
public boolean promptCredential(String id, String msg, boolean proxy) {
	DownloadEntry ent = getEntry(id);
	if (ent == null)
		return false;
	if (!ent.isStartedByUser())
		return false;
	PasswordAuthentication pauth = getCredential(msg, proxy);
	if (pauth == null) {
		return false;
	}
	if (proxy) {
		Config.getInstance().setProxyUser(pauth.getUserName());
		if (pauth.getPassword() != null) {
			Config.getInstance().setProxyPass(new String(pauth.getPassword()));
		}
	} else {
		Logger.log("saving password for: " + msg);
		CredentialManager.getInstance().addCredentialForHost(msg, pauth);
	}
	return true;
}
 
Example 11
Source File: NTLMAuthentication.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
Example 12
Source File: NegotiateCallbackHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void getAnswer() {
    if (!answered) {
        answered = true;

        if (LoginConfigImpl.HTTP_USE_GLOBAL_CREDS) {
            PasswordAuthentication passAuth =
                    Authenticator.requestPasswordAuthentication(
                            hci.host, hci.addr, hci.port, hci.protocol,
                            hci.prompt, hci.scheme, hci.url, hci.authType);
            /**
             * To be compatible with existing callback handler implementations,
             * when the underlying Authenticator is canceled, username and
             * password are assigned null. No exception is thrown.
             */
            if (passAuth != null) {
                username = passAuth.getUserName();
                password = passAuth.getPassword();
            }
        }
    }
}
 
Example 13
Source File: NTLMAuthentication.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void init (PasswordAuthentication pw) {
    this.pw = pw;
    if (pw != null) {
        String s = pw.getUserName();
        int i = s.indexOf ('\\');
        if (i == -1) {
            username = s;
            ntdomain = defaultDomain;
        } else {
            ntdomain = s.substring (0, i).toUpperCase();
            username = s.substring (i+1);
        }
        password = new String (pw.getPassword());
    } else {
        /* credentials will be acquired from OS */
        username = null;
        ntdomain = null;
        password = null;
    }
    init0();
}
 
Example 14
Source File: Subversion.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public SvnClient getClient(SVNUrl repositoryUrl, SvnProgressSupport progressSupport) throws SVNClientException {
    Parameters.notNull("repositoryUrl", repositoryUrl); //NOI18N
    String username = ""; // NOI18N
    char[] password = null;

    SvnKenaiAccessor kenaiSupport = SvnKenaiAccessor.getInstance();
    if(kenaiSupport.isKenai(repositoryUrl.toString())) {
        PasswordAuthentication pa = kenaiSupport.getPasswordAuthentication(repositoryUrl.toString(), false);
        if(pa != null) {
            username = pa.getUserName();
            password = pa.getPassword();
        }
    } else {
        RepositoryConnection rc = SvnModuleConfig.getDefault().getRepositoryConnection(repositoryUrl.toString());
        if(rc != null) {
            username = rc.getUsername();
            password = rc.getPassword();
        } else if(!Utilities.isWindows()) {
            PasswordFile pf = PasswordFile.findFileForUrl(repositoryUrl);
            if(pf != null) {
                username = pf.getUsername();
                String psswdString = pf.getPassword();
                password = psswdString != null ? psswdString.toCharArray() : null;
            }
        }
    }
    return getClient(repositoryUrl, username, password, progressSupport);
}
 
Example 15
Source File: SvnClientCallback.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void getKenaiAuthData(SvnKenaiAccessor support) {
    final String urlString = url.toString();
    
    PasswordAuthentication pa = support.getPasswordAuthentication(urlString, true);
    if(pa == null) {
        throw new RuntimeException(new InterruptedException(org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "MSG_ActionCanceledByUser"))); //NOI18N
    }
    String user = pa.getUserName();
    char[] psswd = pa.getPassword();

    username = user != null ? user : "";
    password = psswd;
}
 
Example 16
Source File: KenaiRepository.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean authenticate(String errroMsg) {
    PasswordAuthentication pa = TeamAccessorUtils.getPasswordAuthentication(kenaiProject.getWebLocation().toString(), true);
    if(pa == null) {
        return false;
    }
    
    String user = pa.getUserName();
    char[] password = pa.getPassword();

    setTaskRepository(user, password);

    return true;
}
 
Example 17
Source File: KenaiRepository.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static char[] getKenaiPassword(TeamProject kenaiProject) {
    PasswordAuthentication pa = TeamAccessorUtils.getPasswordAuthentication(kenaiProject.getWebLocation().toString(), false);
    if(pa != null) {
        return pa.getPassword();
    }
    return new char[0];                                                     // NOI18N
}
 
Example 18
Source File: KenaiRepository.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if(evt.getPropertyName().equals(TeamAccessor.PROP_LOGIN)) {

        // XXX move to spi?
        // get kenai credentials
        String user;
        char[] psswd;
        PasswordAuthentication pa = 
                TeamAccessorUtils.getPasswordAuthentication(kenaiProject.getWebLocation().toString(), false); // do not force login
        if(pa != null) {
            user = pa.getUserName();
            psswd = pa.getPassword();
        } else {
            user = "";                                                      // NOI18N
            psswd = new char[0];                                            // NOI18N
        }

        setTaskRepository(user, psswd);

        synchronized(KenaiRepository.this) {
            if(evt.getNewValue() != null) {
                if(myIssues != null) {
                    // XXX this is a mess - setting the controller and the query
                    KenaiQueryController c = (KenaiQueryController) myIssues.getController();
                    String url = getMyIssuesQueryUrl();
                    c.populate(url);
                    myIssues.setUrlParameters(url);
                }
            } 
        }
    }
}
 
Example 19
Source File: BasicAuthentication.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static String authValueFrom(PasswordAuthentication pw, boolean isUTF8) {
    String plain = pw.getUserName() + ":";
    char[] password = pw.getPassword();
    CharBuffer cbuf = CharBuffer.allocate(plain.length() + password.length);
    cbuf.put(plain).put(password).flip();
    Charset charset = isUTF8 ? UTF_8.INSTANCE : ISO_8859_1.INSTANCE;
    ByteBuffer buf = charset.encode(cbuf);
    ByteBuffer enc = Base64.getEncoder().encode(buf);
    String ret = "Basic " + new String(enc.array(), enc.position(), enc.remaining(),
            ISO_8859_1.INSTANCE);
    Arrays.fill(buf.array(), (byte) 0);
    Arrays.fill(enc.array(), (byte) 0);
    Arrays.fill(cbuf.array(), (char) 0);
    return ret;
}
 
Example 20
Source File: HttpUtil.java    From milkman with MIT License 4 votes vote down vote up
public static String authorizationHeaderValue(PasswordAuthentication creds) {
	String value = creds.getUserName() + ":" + new String(creds.getPassword());
	return "Basic " + Base64.getEncoder().encodeToString(value.getBytes());
}