class OpenSSHCredentialsConfigurator implements CredentialsConfigurator {

    @Override
    public Credentials configure(final Host host) {
        final Credentials credentials = new Credentials(host.getCredentials());
        if(StringUtils.isNotBlank(host.getHostname())) {
            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(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;
    }

    public  OpenSSHCredentialsConfigurator();
    public  OpenSSHCredentialsConfigurator(final OpenSshConfig configuration);

}