FileDocCategorySizeDatePackage
AuthScope.javaAPI DocAndroid 1.5 API9446Wed May 06 22:41:10 BST 2009org.apache.http.auth

AuthScope

public class AuthScope extends Object
The class represents an authentication scope consisting of a host name, a port number, a realm name and an authentication scheme name which {@link Credentials Credentials} apply to.
author
Oleg Kalnichevski
author
Adrian Sutton
since
4.0

Fields Summary
public static final String
ANY_HOST
The null value represents any host. In the future versions of HttpClient the use of this parameter will be discontinued.
public static final int
ANY_PORT
The -1 value represents any port.
public static final String
ANY_REALM
The null value represents any realm.
public static final String
ANY_SCHEME
The null value represents any authentication scheme.
public static final AuthScope
ANY
Default scope matching any host, port, realm and authentication scheme. In the future versions of HttpClient the use of this parameter will be discontinued.
private final String
scheme
The authentication scheme the credentials apply to.
private final String
realm
The realm the credentials apply to.
private final String
host
The host the credentials apply to.
private final int
port
The port the credentials apply to.
Constructors Summary
public AuthScope(String host, int port, String realm, String scheme)
Creates a new credentials scope for the given host, port, realm, and authentication scheme.

param
host the host the credentials apply to. May be set to null if credenticals are applicable to any host.
param
port the port the credentials apply to. May be set to negative value if credenticals are applicable to any port.
param
realm the realm the credentials apply to. May be set to null if credenticals are applicable to any realm.
param
scheme the authentication scheme the credentials apply to. May be set to null if credenticals are applicable to any authentication scheme.

        
                                                                                                                                   
          
             
    
        this.host =   (host == null)   ? ANY_HOST: host.toLowerCase(Locale.ENGLISH);
        this.port =   (port < 0)       ? ANY_PORT: port;
        this.realm =  (realm == null)  ? ANY_REALM: realm;
        this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase(Locale.ENGLISH);
    
public AuthScope(String host, int port, String realm)
Creates a new credentials scope for the given host, port, realm, and any authentication scheme.

param
host the host the credentials apply to. May be set to null if credenticals are applicable to any host.
param
port the port the credentials apply to. May be set to negative value if credenticals are applicable to any port.
param
realm the realm the credentials apply to. May be set to null if credenticals are applicable to any realm.

        this(host, port, realm, ANY_SCHEME);
    
public AuthScope(String host, int port)
Creates a new credentials scope for the given host, port, any realm name, and any authentication scheme.

param
host the host the credentials apply to. May be set to null if credenticals are applicable to any host.
param
port the port the credentials apply to. May be set to negative value if credenticals are applicable to any port.

        this(host, port, ANY_REALM, ANY_SCHEME);
    
public AuthScope(AuthScope authscope)
Creates a copy of the given credentials scope.

        super();
        if (authscope == null) {
            throw new IllegalArgumentException("Scope may not be null");
        }
        this.host = authscope.getHost();
        this.port = authscope.getPort();
        this.realm = authscope.getRealm();
        this.scheme = authscope.getScheme();
    
Methods Summary
public booleanequals(java.lang.Object o)

see
java.lang.Object#equals(Object)

        if (o == null) {
            return false;
        }
        if (o == this) {
            return true;
        }
        if (!(o instanceof AuthScope)) {
            return super.equals(o);
        }
        AuthScope that = (AuthScope) o;
        return 
        LangUtils.equals(this.host, that.host) 
          && this.port == that.port
          && LangUtils.equals(this.realm, that.realm)
          && LangUtils.equals(this.scheme, that.scheme);
    
public java.lang.StringgetHost()

return
the host

        return this.host;
    
public intgetPort()

return
the port

        return this.port;
    
public java.lang.StringgetRealm()

return
the realm name

        return this.realm;
    
public java.lang.StringgetScheme()

return
the scheme type

        return this.scheme;
    
public inthashCode()

see
java.lang.Object#hashCode()

        int hash = LangUtils.HASH_SEED;
        hash = LangUtils.hashCode(hash, this.host);
        hash = LangUtils.hashCode(hash, this.port);
        hash = LangUtils.hashCode(hash, this.realm);
        hash = LangUtils.hashCode(hash, this.scheme);
        return hash;
    
public intmatch(org.apache.http.auth.AuthScope that)
Tests if the authentication scopes match.

return
the match factor. Negative value signifies no match. Non-negative signifies a match. The greater the returned value the closer the match.

        int factor = 0;
        if (LangUtils.equals(this.scheme, that.scheme)) {
            factor += 1;
        } else {
            if (this.scheme != ANY_SCHEME && that.scheme != ANY_SCHEME) {
                return -1;
            }
        }
        if (LangUtils.equals(this.realm, that.realm)) {
            factor += 2;
        } else {
            if (this.realm != ANY_REALM && that.realm != ANY_REALM) {
                return -1;
            }
        }
        if (this.port == that.port) {
            factor += 4;
        } else {
            if (this.port != ANY_PORT && that.port != ANY_PORT) {
                return -1;
            }
        }
        if (LangUtils.equals(this.host, that.host)) {
            factor += 8;
        } else {
            if (this.host != ANY_HOST && that.host != ANY_HOST) {
                return -1;
            }
        }
        return factor;
    
public java.lang.StringtoString()

see
java.lang.Object#toString()

        StringBuffer buffer = new StringBuffer();
        if (this.scheme != null) {
            buffer.append(this.scheme.toUpperCase(Locale.ENGLISH));
            buffer.append(' ");
        }
        if (this.realm != null) {
            buffer.append('\'");
            buffer.append(this.realm);
            buffer.append('\'");
        } else {
            buffer.append("<any realm>");
        }
        if (this.host != null) {
            buffer.append('@");
            buffer.append(this.host);
            if (this.port >= 0) {
                buffer.append(':");
                buffer.append(this.port);
            }
        }
        return buffer.toString();