Example usage for org.apache.http.osgi.services ProxyConfiguration getUsername

List of usage examples for org.apache.http.osgi.services ProxyConfiguration getUsername

Introduction

In this page you can find the example usage for org.apache.http.osgi.services ProxyConfiguration getUsername.

Prototype

String getUsername();

Source Link

Usage

From source file:org.apache.http.osgi.impl.OSGiCredentialsProvider.java

/**
 * {@inheritDoc}/*from  www.j  a v a 2  s. c o  m*/
 */
@Override
public Credentials getCredentials(final AuthScope authScope) {
    // iterate over all active proxy configurations at the moment of getting the credential
    for (final ProxyConfiguration config : proxyConfigurations) {
        if (config.isEnabled() && isSuitable(config, authScope)) {
            final String scheme = authScope.getScheme();
            if (BASIC_SCHEME_NAME.equals(scheme)) {
                return new UsernamePasswordCredentials(config.getUsername(), config.getPassword());
            } else if (NTLM_SCHEME_NAME.equals(scheme)) {
                return createNTCredentials(config);
            } else {
                log.debug("credentials requested for unsupported authentication scheme " + scheme);
            }
        }
    }
    // credentials no longer available!
    return null;
}

From source file:org.apache.http.osgi.impl.OSGiCredentialsProvider.java

private static Credentials createNTCredentials(final ProxyConfiguration config) {
    final String domainAndUsername = config.getUsername();
    final String username;
    final String domain;
    final int index = domainAndUsername.indexOf("\\");
    if (index > -1) {
        username = domainAndUsername.substring(index + 1);
        domain = domainAndUsername.substring(0, index);
    } else {//from ww  w .  j a  v a2  s  . c  om
        username = domainAndUsername;
        domain = null;
    }
    return new NTCredentials(username, config.getPassword(), null, domain);
}