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

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

Introduction

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

Prototype

String getPassword();

Source Link

Usage

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

/**
 * {@inheritDoc}//from www . j a  va2  s  .  co 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   w  w  w  .ja v a 2 s . co  m*/
        username = domainAndUsername;
        domain = null;
    }
    return new NTCredentials(username, config.getPassword(), null, domain);
}