Package net.oauth.client.httpclient4
Class PreemptiveAuthorizer
- java.lang.Object
-
- net.oauth.client.httpclient4.PreemptiveAuthorizer
-
- All Implemented Interfaces:
org.apache.http.HttpRequestInterceptor
public class PreemptiveAuthorizer extends Object implements org.apache.http.HttpRequestInterceptor
An interceptor that initiates authorization without waiting for a challenge from the server. This avoids a response/request exchange (for the challenge), but it doesn't give the server a chance to select the authorization scheme or realm.To make this work:
- In your HttpContext attributes, set a list of preferred auth scheme names.
- In your DigestHttpClient auth schemes, register an AuthSchemeFactory for at least one of those schemes.
- In your DigestHttpClient credentials provider, set Credentials for an AuthScope that will match your request.
- In your DigestHttpClient params, register any parameters the AuthSchemeFactory requires.
- In your DigestHttpClient, add an instance of this interceptor.
context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_SCHEME_PREF, Arrays.asList(OAuthSchemeFactory.SCHEME_NAME)); client = new DefaultHttpClient(); client.getAuthSchemes().register(OAuthSchemeFactory.SCHEME_NAME, new OAuthSchemeFactory()); client.getCredentialsProvider().setCredentials(new AuthScope("server.com", 80), new OAuthCredentials(accessor)); client.getParams().setParameter(OAuthSchemeFactory.DEFAULT_REALM, ProtectedResource.REALM); client.addRequestInterceptor(new PreemptiveAuthorizer(), 0);
- Author:
- John Kristian
-
-
Constructor Summary
Constructors Constructor Description PreemptiveAuthorizer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
process(org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)
If no auth scheme has been selected for the given context, consider each of the preferred auth schemes and select the first one for which an AuthScheme and matching Credentials are available.
-
-
-
Method Detail
-
process
public void process(org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context) throws org.apache.http.HttpException, IOException
If no auth scheme has been selected for the given context, consider each of the preferred auth schemes and select the first one for which an AuthScheme and matching Credentials are available.- Specified by:
process
in interfaceorg.apache.http.HttpRequestInterceptor
- Throws:
org.apache.http.HttpException
IOException
-
-