org.apache.commons.httpclient.auth.CredentialsProvider Java Examples

The following examples show how to use org.apache.commons.httpclient.auth.CredentialsProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Http3Util.java    From httpsig-java with The Unlicense 6 votes vote down vote up
public static void enableAuth(HttpClient client, Keychain keychain, KeyId keyId) {
    Signer signer = new Signer(keychain, keyId);
    CredentialsProvider credProvider =
        (CredentialsProvider) client.getParams()
                .getParameter(CredentialsProvider.PROVIDER);

    CredentialsProvider newProvider;
    if (credProvider instanceof SignerCredentialsProvider) {
        newProvider = new SignerCredentialsProvider(signer,
                                                    ((SignerCredentialsProvider) credProvider).getDelegatee());
    } else {
        newProvider = new SignerCredentialsProvider(signer, credProvider);
    }

    client.getParams().setParameter(CredentialsProvider.PROVIDER, newProvider);
    AuthPolicy.registerAuthScheme(Constants.SCHEME, Http3SignatureAuthScheme.class);
    List<String> schemes = new ArrayList<String>();
    schemes.add(Constants.SCHEME);

    Collection authSchemePriority = (Collection) DefaultHttpParams.getDefaultParams().getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY);
    if (authSchemePriority != null) {
        schemes.addAll(authSchemePriority);
    }
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);
}
 
Example #2
Source File: HttpMethodDirector.java    From http4e with Apache License 2.0 5 votes vote down vote up
private Credentials promptForCredentials(
    final AuthScheme authScheme,
    final HttpParams params, 
    final AuthScope authscope)
{
    LOG.debug("Credentials required");
    Credentials creds = null;
    CredentialsProvider credProvider = 
        (CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
    if (credProvider != null) {
        try {
            creds = credProvider.getCredentials(
                authScheme, authscope.getHost(), authscope.getPort(), false);
        } catch (CredentialsNotAvailableException e) {
            LOG.warn(e.getMessage());
        }
        if (creds != null) {
            this.state.setCredentials(authscope, creds);
            if (LOG.isDebugEnabled()) {
                LOG.debug(authscope + " new credentials given");
            }
        }
    } else {
        LOG.debug("Credentials provider not available");
    }
    return creds;
}
 
Example #3
Source File: HttpMethodDirector.java    From http4e with Apache License 2.0 5 votes vote down vote up
private Credentials promptForProxyCredentials(
    final AuthScheme authScheme,
    final HttpParams params,
    final AuthScope authscope) 
{
    LOG.debug("Proxy credentials required");
    Credentials creds = null;
    CredentialsProvider credProvider = 
        (CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
    if (credProvider != null) {
        try {
            creds = credProvider.getCredentials(
                authScheme, authscope.getHost(), authscope.getPort(), true);
        } catch (CredentialsNotAvailableException e) {
            LOG.warn(e.getMessage());
        }
        if (creds != null) {
            this.state.setProxyCredentials(authscope, creds);
            if (LOG.isDebugEnabled()) {
                LOG.debug(authscope + " new credentials given");
            }
        }
    } else {
        LOG.debug("Proxy credentials provider not available");
    }
    return creds;
}
 
Example #4
Source File: HttpMethodDirector.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Credentials promptForCredentials(
    final AuthScheme authScheme,
    final HttpParams params, 
    final AuthScope authscope)
{
    LOG.debug("Credentials required");
    Credentials creds = null;
    CredentialsProvider credProvider = 
        (CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
    if (credProvider != null) {
        try {
            creds = credProvider.getCredentials(
                authScheme, authscope.getHost(), authscope.getPort(), false);
        } catch (CredentialsNotAvailableException e) {
            LOG.warn(e.getMessage());
        }
        if (creds != null) {
            this.state.setCredentials(authscope, creds);
            if (LOG.isDebugEnabled()) {
                LOG.debug(authscope + " new credentials given");
            }
        }
    } else {
        LOG.debug("Credentials provider not available");
    }
    return creds;
}
 
Example #5
Source File: HttpMethodDirector.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Credentials promptForProxyCredentials(
    final AuthScheme authScheme,
    final HttpParams params,
    final AuthScope authscope) 
{
    LOG.debug("Proxy credentials required");
    Credentials creds = null;
    CredentialsProvider credProvider = 
        (CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER);
    if (credProvider != null) {
        try {
            creds = credProvider.getCredentials(
                authScheme, authscope.getHost(), authscope.getPort(), true);
        } catch (CredentialsNotAvailableException e) {
            LOG.warn(e.getMessage());
        }
        if (creds != null) {
            this.state.setProxyCredentials(authscope, creds);
            if (LOG.isDebugEnabled()) {
                LOG.debug(authscope + " new credentials given");
            }
        }
    } else {
        LOG.debug("Proxy credentials provider not available");
    }
    return creds;
}
 
Example #6
Source File: SignerCredentialsProvider.java    From httpsig-java with The Unlicense 4 votes vote down vote up
public SignerCredentialsProvider(Signer signer, CredentialsProvider delegatee) {
    this.signer = signer;
    this.delegatee = delegatee;
}
 
Example #7
Source File: SignerCredentialsProvider.java    From httpsig-java with The Unlicense 4 votes vote down vote up
public CredentialsProvider getDelegatee() {
    return delegatee;
}