Java Code Examples for org.apache.commons.httpclient.auth.AuthPolicy#registerAuthScheme()

The following examples show how to use org.apache.commons.httpclient.auth.AuthPolicy#registerAuthScheme() . 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: RestConsumer.java    From RestServices with Apache License 2.0 5 votes vote down vote up
public static void registerNTCredentials(String urlBasePath, String username, String password, String domain) throws MalformedURLException
{
	client.getParams().setAuthenticationPreemptive(true);
	URL url = new URL(urlBasePath);
	Core.getLogger("NTLM").info(url.getHost());
	Credentials defaultcreds = new NTCredentials(username, password, url.getHost(), domain);
	
	AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, restservices.util.JCIFS_NTLMScheme.class);
	
	List<String> authpref = new ArrayList<String>();
	authpref.add(AuthPolicy.NTLM);
	
	client.getParams().setParameter("http.auth.target-scheme-pref", authpref);
	client.getState().setCredentials(new AuthScope(AuthScope.ANY), defaultcreds);
}
 
Example 3
Source File: CredentialsUtils.java    From httpclientAuthHelper with Apache License 2.0 5 votes vote down vote up
private static void initNTLMv2() {
    if (!registeredNTLM) {
        try {
            logger.info(" adding NTLMv2 based   authentication schema for HttpClient");
            AuthPolicy.registerAuthScheme(AuthPolicy.NTLM,
                    com.jivesoftware.authHelper.customescheme.ntlm2.CustomNTLM2Scheme.class);
            registeredNTLM = true;
        } catch (Throwable e) {
            logger.log(java.util.logging.Level.SEVERE,
                    "Could not add NTLM based on JCIFS authentication schema for HttpClient.", e);

        }
    }
}
 
Example 4
Source File: CredentialsUtils.java    From httpclientAuthHelper with Apache License 2.0 5 votes vote down vote up
private static void initKERBEROS(HttpClient httpClient) {
    if (!registeredKERBEROS) {
        try {
            logger.info("Globally adding KERBEROS ");
            System.setProperty(USE_SUBJECT_CREDS, "false");

            AuthPolicy.registerAuthScheme(NEGOTIATE,
                    com.jivesoftware.authHelper.customescheme.negotiate.CustomNegotiateScheme.class);
            registeredKERBEROS = true;
        } catch (Throwable e) {
            logger.log(java.util.logging.Level.SEVERE, "Could not add KERBEROS  for HttpClient.", e);
        }

    }
}
 
Example 5
Source File: EsHadoopAuthPolicies.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
public synchronized static void registerAuthSchemes() {
    if (!REGISTERED) {
        REGISTERED = true;
        AuthPolicy.registerAuthScheme(NEGOTIATE, SpnegoAuthScheme.class);
        AuthPolicy.registerAuthScheme(APIKEY, EsApiKeyAuthScheme.class);
    }
}