@Override
    public Credentials configure(final Host host) {
        if(StringUtils.isNotBlank(host.getHostname())) {
            final Credentials credentials = new Credentials(host.getCredentials());
            configuration.refresh();
            // Update this host credentials from the OpenSSH configuration file in ~/.ssh/config
            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 {
                    // No custom public key authentication configuration
                    if(new HostPreferences(host).getBoolean("ssh.authentication.publickey.default.enable")) {
                        final Local rsa = LocalFactory.get(new HostPreferences(host).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(new HostPreferences(host).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;
        }
        return CredentialsConfigurator.DISABLED.configure(host);
    }
@Test
    public void testConfigureDefaultKey() {
        OpenSSHCredentialsConfigurator c = new OpenSSHCredentialsConfigurator(
            new OpenSshConfig(
                new Local("src/main/test/resources", "openssh/config")));
        final Credentials credentials = c.configure(new Host(new TestProtocol(Scheme.sftp), "t"));
        // ssh.authentication.publickey.default.enable
        assertNull(credentials.getIdentity());
    }