@Test public void testConfigureKnownHost() { OpenSSHCredentialsConfigurator c = new OpenSSHCredentialsConfigurator( new OpenSshConfig( new Local("src/test/resources", "openssh/config"))); final Host host = new Host(new TestProtocol(Scheme.sftp), "alias"); final Credentials credentials = c.configure(host); assertNotNull(credentials.getIdentity()); assertEquals(new Local("~/.ssh/version.cyberduck.ch-rsa"), credentials.getIdentity()); assertEquals("root", credentials.getUsername()); }
@Override public Credentials configure(final Host host) { final Credentials credentials = new Credentials(host.getCredentials()); if(StringUtils.isNotBlank(host.getHostname())) { configuration.refresh(); final OpenSshConfig.Host entry = configuration.lookup(host.getHostname()); if(StringUtils.isNotBlank(entry.getUser())) { if(!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) { if(log.isInfoEnabled()) { log.info(String.format("Using username %s from %s", entry, configuration)); } credentials.setUsername(entry.getUser()); } } if(!credentials.isPublicKeyAuthentication()) { if(null != entry.getIdentityFile()) { if(log.isInfoEnabled()) { log.info(String.format("Using identity %s from %s", entry, configuration)); } credentials.setIdentity(entry.getIdentityFile()); } else { if(preferences.getBoolean("ssh.authentication.publickey.default.enable")) { final Local rsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.rsa")); if(rsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using RSA default host key %s from %s", rsa, configuration)); } credentials.setIdentity(rsa); } else { final Local dsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.dsa")); if(dsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using DSA default host key %s from %s", dsa, configuration)); } credentials.setIdentity(dsa); } } } } } } return credentials; }
OpenSSHCredentialsConfigurator implements CredentialsConfigurator { @Override public Credentials configure(final Host host) { final Credentials credentials = new Credentials(host.getCredentials()); if(StringUtils.isNotBlank(host.getHostname())) { configuration.refresh(); final OpenSshConfig.Host entry = configuration.lookup(host.getHostname()); if(StringUtils.isNotBlank(entry.getUser())) { if(!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) { if(log.isInfoEnabled()) { log.info(String.format("Using username %s from %s", entry, configuration)); } credentials.setUsername(entry.getUser()); } } if(!credentials.isPublicKeyAuthentication()) { if(null != entry.getIdentityFile()) { if(log.isInfoEnabled()) { log.info(String.format("Using identity %s from %s", entry, configuration)); } credentials.setIdentity(entry.getIdentityFile()); } else { if(preferences.getBoolean("ssh.authentication.publickey.default.enable")) { final Local rsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.rsa")); if(rsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using RSA default host key %s from %s", rsa, configuration)); } credentials.setIdentity(rsa); } else { final Local dsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.dsa")); if(dsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using DSA default host key %s from %s", dsa, configuration)); } credentials.setIdentity(dsa); } } } } } } return credentials; } }
OpenSSHCredentialsConfigurator implements CredentialsConfigurator { @Override public Credentials configure(final Host host) { final Credentials credentials = new Credentials(host.getCredentials()); if(StringUtils.isNotBlank(host.getHostname())) { configuration.refresh(); final OpenSshConfig.Host entry = configuration.lookup(host.getHostname()); if(StringUtils.isNotBlank(entry.getUser())) { if(!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) { if(log.isInfoEnabled()) { log.info(String.format("Using username %s from %s", entry, configuration)); } credentials.setUsername(entry.getUser()); } } if(!credentials.isPublicKeyAuthentication()) { if(null != entry.getIdentityFile()) { if(log.isInfoEnabled()) { log.info(String.format("Using identity %s from %s", entry, configuration)); } credentials.setIdentity(entry.getIdentityFile()); } else { if(preferences.getBoolean("ssh.authentication.publickey.default.enable")) { final Local rsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.rsa")); if(rsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using RSA default host key %s from %s", rsa, configuration)); } credentials.setIdentity(rsa); } else { final Local dsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.dsa")); if(dsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using DSA default host key %s from %s", dsa, configuration)); } credentials.setIdentity(dsa); } } } } } } return credentials; } OpenSSHCredentialsConfigurator();  OpenSSHCredentialsConfigurator(final OpenSshConfig configuration); }
OpenSSHCredentialsConfigurator implements CredentialsConfigurator { @Override public Credentials configure(final Host host) { final Credentials credentials = new Credentials(host.getCredentials()); if(StringUtils.isNotBlank(host.getHostname())) { configuration.refresh(); final OpenSshConfig.Host entry = configuration.lookup(host.getHostname()); if(StringUtils.isNotBlank(entry.getUser())) { if(!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) { if(log.isInfoEnabled()) { log.info(String.format("Using username %s from %s", entry, configuration)); } credentials.setUsername(entry.getUser()); } } if(!credentials.isPublicKeyAuthentication()) { if(null != entry.getIdentityFile()) { if(log.isInfoEnabled()) { log.info(String.format("Using identity %s from %s", entry, configuration)); } credentials.setIdentity(entry.getIdentityFile()); } else { if(preferences.getBoolean("ssh.authentication.publickey.default.enable")) { final Local rsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.rsa")); if(rsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using RSA default host key %s from %s", rsa, configuration)); } credentials.setIdentity(rsa); } else { final Local dsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.dsa")); if(dsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using DSA default host key %s from %s", dsa, configuration)); } credentials.setIdentity(dsa); } } } } } } return credentials; } OpenSSHCredentialsConfigurator();  OpenSSHCredentialsConfigurator(final OpenSshConfig configuration); @Override Credentials configure(final Host host); @Override void reload(); @Override String toString(); }
OpenSSHCredentialsConfigurator implements CredentialsConfigurator { @Override public Credentials configure(final Host host) { final Credentials credentials = new Credentials(host.getCredentials()); if(StringUtils.isNotBlank(host.getHostname())) { configuration.refresh(); final OpenSshConfig.Host entry = configuration.lookup(host.getHostname()); if(StringUtils.isNotBlank(entry.getUser())) { if(!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) { if(log.isInfoEnabled()) { log.info(String.format("Using username %s from %s", entry, configuration)); } credentials.setUsername(entry.getUser()); } } if(!credentials.isPublicKeyAuthentication()) { if(null != entry.getIdentityFile()) { if(log.isInfoEnabled()) { log.info(String.format("Using identity %s from %s", entry, configuration)); } credentials.setIdentity(entry.getIdentityFile()); } else { if(preferences.getBoolean("ssh.authentication.publickey.default.enable")) { final Local rsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.rsa")); if(rsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using RSA default host key %s from %s", rsa, configuration)); } credentials.setIdentity(rsa); } else { final Local dsa = LocalFactory.get(preferences.getProperty("ssh.authentication.publickey.default.dsa")); if(dsa.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Using DSA default host key %s from %s", dsa, configuration)); } credentials.setIdentity(dsa); } } } } } } return credentials; } OpenSSHCredentialsConfigurator();  OpenSSHCredentialsConfigurator(final OpenSshConfig configuration); @Override Credentials configure(final Host host); @Override void reload(); @Override String toString();  }