Updated AuthScope javadocs; added origin attribute
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1567925 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
60f0724533
commit
47e6f4590b
|
@ -34,10 +34,11 @@ import org.apache.http.util.Args;
|
||||||
import org.apache.http.util.LangUtils;
|
import org.apache.http.util.LangUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class represents an authentication scope consisting of a host name,
|
* <tt>AuthScope</tt> represents an authentication scope consisting of a host name,
|
||||||
* a port number, a realm name and an authentication scheme name which
|
* a port number, a realm name and an authentication scheme name.
|
||||||
* {@link Credentials Credentials} apply to.
|
* <p/>
|
||||||
*
|
* This class can also optionally contain a host of origin, if created in response
|
||||||
|
* to authentication challenge from a specific host.
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
@ -84,74 +85,89 @@ public class AuthScope {
|
||||||
/** The port the credentials apply to. */
|
/** The port the credentials apply to. */
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
/** Creates a new credentials scope for the given
|
/** The original host, if known */
|
||||||
* <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and
|
private final HttpHost origin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines auth scope with the given <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and
|
||||||
* <tt>authentication scheme</tt>.
|
* <tt>authentication scheme</tt>.
|
||||||
*
|
*
|
||||||
* @param host the host the credentials apply to. May be set
|
* @param host authentication host. May be {@link #ANY_HOST} if applies
|
||||||
* to <tt>null</tt> if credentials are applicable to
|
* to any host.
|
||||||
* any host.
|
* @param port authentication port. May be {@link #ANY_PORT} if applies
|
||||||
* @param port the port the credentials apply to. May be set
|
* to any port of the host.
|
||||||
* to negative value if credentials are applicable to
|
* @param realm authentication realm. May be {@link #ANY_REALM} if applies
|
||||||
* any port.
|
* to any realm on the host.
|
||||||
* @param realm the realm the credentials apply to. May be set
|
* @param scheme authentication scheme. May be {@link #ANY_SCHEME} if applies
|
||||||
* to <tt>null</tt> if credentials are applicable to
|
* to any scheme supported by the host.
|
||||||
* any realm.
|
|
||||||
* @param scheme the authentication scheme the credentials apply to.
|
|
||||||
* May be set to <tt>null</tt> if credentials are applicable to
|
|
||||||
* any authentication scheme.
|
|
||||||
*/
|
*/
|
||||||
public AuthScope(final String host, final int port,
|
public AuthScope(
|
||||||
final String realm, final String scheme)
|
final String host,
|
||||||
{
|
final int port,
|
||||||
this.host = (host == null) ? ANY_HOST: host.toLowerCase(Locale.ROOT);
|
final String realm,
|
||||||
this.port = (port < 0) ? ANY_PORT: port;
|
final String schemeName) {
|
||||||
this.realm = (realm == null) ? ANY_REALM: realm;
|
this.host = host == null ? ANY_HOST: host.toLowerCase(Locale.ROOT);
|
||||||
this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase(Locale.ROOT);
|
this.port = port < 0 ? ANY_PORT : port;
|
||||||
|
this.realm = realm == null ? ANY_REALM : realm;
|
||||||
|
this.scheme = schemeName == null ? ANY_SCHEME : schemeName.toUpperCase(Locale.ROOT);
|
||||||
|
this.origin = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 4.2
|
* Defines auth scope for a specific host of origin.
|
||||||
*/
|
|
||||||
public AuthScope(final HttpHost host, final String realm, final String schemeName) {
|
|
||||||
this(host.getHostName(), host.getPort(), realm, schemeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
public AuthScope(final HttpHost host) {
|
|
||||||
this(host, ANY_REALM, ANY_SCHEME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a new credentials scope for the given
|
|
||||||
* <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and any
|
|
||||||
* authentication scheme.
|
|
||||||
*
|
*
|
||||||
* @param host the host the credentials apply to. May be set
|
* @param origin host of origin
|
||||||
* to <tt>null</tt> if credentials are applicable to
|
* @param realm authentication realm. May be {@link #ANY_REALM} if applies
|
||||||
* any host.
|
* to any realm on the host.
|
||||||
* @param port the port the credentials apply to. May be set
|
* @param scheme authentication scheme. May be {@link #ANY_SCHEME} if applies
|
||||||
* to negative value if credentials are applicable to
|
* to any scheme supported by the host.
|
||||||
* any port.
|
*
|
||||||
* @param realm the realm the credentials apply to. May be set
|
* @since 4.2
|
||||||
* to <tt>null</tt> if credentials are applicable to
|
*/
|
||||||
* any realm.
|
public AuthScope(
|
||||||
|
final HttpHost origin,
|
||||||
|
final String realm,
|
||||||
|
final String schemeName) {
|
||||||
|
Args.notNull(origin, "Host");
|
||||||
|
this.host = origin.getHostName();
|
||||||
|
this.port = origin.getPort() < 0 ? ANY_PORT : origin.getPort();
|
||||||
|
this.realm = realm == null ? ANY_REALM : realm;
|
||||||
|
this.scheme = schemeName == null ? ANY_SCHEME : schemeName.toUpperCase(Locale.ROOT);
|
||||||
|
this.origin = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines auth scope for a specific host of origin.
|
||||||
|
*
|
||||||
|
* @param origin host of origin
|
||||||
|
*
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public AuthScope(final HttpHost origin) {
|
||||||
|
this(origin, ANY_REALM, ANY_SCHEME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines auth scope with the given <tt>host</tt>, <tt>port</tt> and <tt>realm</tt>.
|
||||||
|
*
|
||||||
|
* @param host authentication host. May be {@link #ANY_HOST} if applies
|
||||||
|
* to any host.
|
||||||
|
* @param port authentication port. May be {@link #ANY_PORT} if applies
|
||||||
|
* to any port of the host.
|
||||||
|
* @param realm authentication realm. May be {@link #ANY_REALM} if applies
|
||||||
|
* to any realm on the host.
|
||||||
*/
|
*/
|
||||||
public AuthScope(final String host, final int port, final String realm) {
|
public AuthScope(final String host, final int port, final String realm) {
|
||||||
this(host, port, realm, ANY_SCHEME);
|
this(host, port, realm, ANY_SCHEME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a new credentials scope for the given
|
/**
|
||||||
* <tt>host</tt>, <tt>port</tt>, any realm name, and any
|
* Defines auth scope with the given <tt>host</tt> and <tt>port</tt>.
|
||||||
* authentication scheme.
|
|
||||||
*
|
*
|
||||||
* @param host the host the credentials apply to. May be set
|
* @param host authentication host. May be {@link #ANY_HOST} if applies
|
||||||
* to <tt>null</tt> if credentials are applicable to
|
* to any host.
|
||||||
* any host.
|
* @param port authentication port. May be {@link #ANY_PORT} if applies
|
||||||
* @param port the port the credentials apply to. May be set
|
* to any port of the host.
|
||||||
* to negative value if credentials are applicable to
|
|
||||||
* any port.
|
|
||||||
*/
|
*/
|
||||||
public AuthScope(final String host, final int port) {
|
public AuthScope(final String host, final int port) {
|
||||||
this(host, port, ANY_REALM, ANY_SCHEME);
|
this(host, port, ANY_REALM, ANY_SCHEME);
|
||||||
|
@ -167,6 +183,16 @@ public class AuthScope {
|
||||||
this.port = authscope.getPort();
|
this.port = authscope.getPort();
|
||||||
this.realm = authscope.getRealm();
|
this.realm = authscope.getRealm();
|
||||||
this.scheme = authscope.getScheme();
|
this.scheme = authscope.getScheme();
|
||||||
|
this.origin = authscope.getOrigin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return host of origin. If unknown returns @null,
|
||||||
|
*
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
public HttpHost getOrigin() {
|
||||||
|
return this.origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue