NetrcAuthenticator(String netrcFile) { super(); this.netrc = new NetrcFile(netrcFile); }
/** * Read the users .netrc file and find credentials for the specified server. * * @param host name of the remote machine the credentials are to be used with * @param strict require a strict hostname match or also allow default value * @return authentication credentials or null */ public PasswordAuthentication getCredentials(String host, boolean strict) { return readFromCache(host, strict); }
NetrcFile f = new NetrcFile(); PasswordAuthentication pa = f.getCredentials(host, true); if (pa != null)
private void initCache() if (cache != null && timestamp == lastModified()) else cache.clear(); this.timestamp = lastModified(); c = readEntireFile(); log.warn("failed to read " + this.getAbsolutePath() + ": " + ex); clearCache();
private PasswordAuthentication readFromCache(String host, boolean strict) { try { initCache(); if (cache != null) { log.debug("looking for '" + host + "'"); Cred defaultCred = null; for (int i=0; i<cache.size(); i++) { Cred cred = (Cred) cache.get(i); log.debug("checking '" + cred + "'"); if (cred.machine.equals(host)) return new PasswordAuthentication(cred.login, cred.pword); if (DEFAULT_MACHINE.equals(cred.machine)) defaultCred = cred; } if (!strict && defaultCred != null) return new PasswordAuthentication(defaultCred.login, defaultCred.pword); } } finally { clearCache(); } return null; }
@Override protected PasswordAuthentication getPasswordAuthentication() { synchronized(this) // http library does not have to synchronize usage { log.debug("host: " + getTargetHost()); return netrc.getCredentials(getTargetHost(), true); } }
char[] c = new char[ (int) length() ]; try
private void checkNetrc() { LOGGER.debug("checkNetrc..."); if (!netrcBox1.isSelected()) { return; } LOGGER.debug("creating NetrcFile"); NetrcFile netrc = new NetrcFile(); // since this is for http only, onyl strict hostname matching makes sense PasswordAuthentication pw = netrc.getCredentials(host, true); if (pw != null) { unField.setText(pw.getUserName()); // TODO: SECURITY ISSUE // Doh! After all that work reading the .netrc and never making a password String, I have to // convert it to a String and cannot blank it out; hopefully setText(null) above will be // enough to get rid of that String (eventually) pwField.setText(new String(pw.getPassword())); } else { LOGGER.debug("failed to find " + host + " in NetrcFile"); } } }
public NetrcAuthenticator(boolean secureMode) { super(); this.netrc = new NetrcFile(secureMode); }