public class PreemptiveBasicAuthenticator extends Object implements HttpAuthenticator
It is important to note that preemptive basic authentication is less secure because it can expose credentials to servers that do not require them.
Doing preemptive authentication requires knowing in advance whether you will be doing standard or proxy authentication i.e. whether the remote server will challenge with 401 or 407. If you need both you can take advantage of this being a decorator and simply layer multiple instances of this.
Constructor and Description |
---|
PreemptiveBasicAuthenticator(HttpAuthenticator authenticator)
Creates a new decorator over the given authenticator
|
PreemptiveBasicAuthenticator(HttpAuthenticator authenticator,
boolean forProxy)
Creates a new decorator over the given authenticator
|
public PreemptiveBasicAuthenticator(HttpAuthenticator authenticator)
authenticator
- Authenticator to decoratepublic PreemptiveBasicAuthenticator(HttpAuthenticator authenticator, boolean forProxy)
authenticator
- Authenticator to decorateforProxy
- Whether preemptive authentication is for a proxypublic void apply(org.apache.http.impl.client.AbstractHttpClient client, org.apache.http.protocol.HttpContext httpContext, URI target)
HttpAuthenticator
The target
parameter indicates the URI to which the request is
being made and so may be used by an authenticator to determine whether it
actually needs to apply any authentication or to scope authentication
appropriately.
apply
in interface HttpAuthenticator
client
- HTTP ClienthttpContext
- HTTP Contexttarget
- Target URI to which code wants to authenticateLicenced under the Apache License, Version 2.0