1069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/* 2069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthScope.java $ 3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Revision: 652950 $ 4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Date: 2008-05-02 16:49:48 -0700 (Fri, 02 May 2008) $ 5069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 6069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ==================================================================== 7069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 8069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Licensed to the Apache Software Foundation (ASF) under one or more 9069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * contributor license agreements. See the NOTICE file distributed with 10069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * this work for additional information regarding copyright ownership. 11069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The ASF licenses this file to You under the Apache License, Version 2.0 12069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * (the "License"); you may not use this file except in compliance with 13069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * the License. You may obtain a copy of the License at 14069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 15069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 16069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 17069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 18069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 19069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * See the License for the specific language governing permissions and 21069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * limitations under the License. 22069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ==================================================================== 23069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 24069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This software consists of voluntary contributions made by many 25069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * individuals on behalf of the Apache Software Foundation. For more 26069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * information on the Apache Software Foundation, please see 27069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <http://www.apache.org/>. 28069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 29069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 30069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 31069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpackage org.apache.http.auth; 32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport java.util.Locale; 34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 35069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.util.LangUtils; 36069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 37069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/** 38069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The class represents an authentication scope consisting of a host name, 39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * a port number, a realm name and an authentication scheme name which 40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * {@link Credentials Credentials} apply to. 41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> 43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:adrian@intencha.com">Adrian Sutton</a> 44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @since 4.0 46d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * 47d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * @deprecated Please use {@link java.net.URL#openConnection} instead. 48d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 49d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * for further details. 50069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 51d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath@Deprecated 52069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpublic class AuthScope { 53069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 54069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 55069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The <tt>null</tt> value represents any host. In the future versions of 56069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * HttpClient the use of this parameter will be discontinued. 57069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public static final String ANY_HOST = null; 59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The <tt>-1</tt> value represents any port. 62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public static final int ANY_PORT = -1; 64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The <tt>null</tt> value represents any realm. 67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 68069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public static final String ANY_REALM = null; 69069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 70069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 71069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The <tt>null</tt> value represents any authentication scheme. 72069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 73069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public static final String ANY_SCHEME = null; 74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 75069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Default scope matching any host, port, realm and authentication scheme. 77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * In the future versions of HttpClient the use of this parameter will be 78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * discontinued. 79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public static final AuthScope ANY = new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, ANY_SCHEME); 81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The authentication scheme the credentials apply to. */ 83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project private final String scheme; 84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The realm the credentials apply to. */ 86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project private final String realm; 87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The host the credentials apply to. */ 89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project private final String host; 90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The port the credentials apply to. */ 92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project private final int port; 93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** Creates a new credentials scope for the given 95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and 96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <tt>authentication scheme</tt>. 97069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 98069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param host the host the credentials apply to. May be set 99069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to <tt>null</tt> if credenticals are applicable to 100069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any host. 101069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param port the port the credentials apply to. May be set 102069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to negative value if credenticals are applicable to 103069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any port. 104069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param realm the realm the credentials apply to. May be set 105069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to <tt>null</tt> if credenticals are applicable to 106069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any realm. 107069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param scheme the authentication scheme the credentials apply to. 108069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * May be set to <tt>null</tt> if credenticals are applicable to 109069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any authentication scheme. 110069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 111069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public AuthScope(final String host, int port, 112069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project final String realm, final String scheme) 113069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project { 114069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.host = (host == null) ? ANY_HOST: host.toLowerCase(Locale.ENGLISH); 115069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.port = (port < 0) ? ANY_PORT: port; 116069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.realm = (realm == null) ? ANY_REALM: realm; 117069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase(Locale.ENGLISH); 118069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 119069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 120069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** Creates a new credentials scope for the given 121069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and any 122069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * authentication scheme. 123069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 124069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param host the host the credentials apply to. May be set 125069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to <tt>null</tt> if credenticals are applicable to 126069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any host. 127069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param port the port the credentials apply to. May be set 128069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to negative value if credenticals are applicable to 129069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any port. 130069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param realm the realm the credentials apply to. May be set 131069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to <tt>null</tt> if credenticals are applicable to 132069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any realm. 133069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 134069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public AuthScope(final String host, int port, final String realm) { 135069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this(host, port, realm, ANY_SCHEME); 136069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 137069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 138069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** Creates a new credentials scope for the given 139069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <tt>host</tt>, <tt>port</tt>, any realm name, and any 140069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * authentication scheme. 141069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 142069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param host the host the credentials apply to. May be set 143069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to <tt>null</tt> if credenticals are applicable to 144069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any host. 145069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param port the port the credentials apply to. May be set 146069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to negative value if credenticals are applicable to 147069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * any port. 148069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 149069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public AuthScope(final String host, int port) { 150069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this(host, port, ANY_REALM, ANY_SCHEME); 151069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 152069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 153069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 154069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Creates a copy of the given credentials scope. 155069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 156069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public AuthScope(final AuthScope authscope) { 157069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project super(); 158069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (authscope == null) { 159069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException("Scope may not be null"); 160069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 161069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.host = authscope.getHost(); 162069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.port = authscope.getPort(); 163069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.realm = authscope.getRealm(); 164069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.scheme = authscope.getScheme(); 165069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 166069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 167069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 168069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the host 169069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 170069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public String getHost() { 171069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return this.host; 172069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 173069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 174069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 175069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the port 176069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 177069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public int getPort() { 178069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return this.port; 179069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 180069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 181069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 182069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the realm name 183069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 184069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public String getRealm() { 185069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return this.realm; 186069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 187069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 188069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 189069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the scheme type 190069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 191069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public String getScheme() { 192069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return this.scheme; 193069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 194069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 195069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 196069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Tests if the authentication scopes match. 197069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 198069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return the match factor. Negative value signifies no match. 199069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Non-negative signifies a match. The greater the returned value 200069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * the closer the match. 201069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 202069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public int match(final AuthScope that) { 203069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project int factor = 0; 204069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (LangUtils.equals(this.scheme, that.scheme)) { 205069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project factor += 1; 206069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } else { 207069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.scheme != ANY_SCHEME && that.scheme != ANY_SCHEME) { 208069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return -1; 209069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 210069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 211069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (LangUtils.equals(this.realm, that.realm)) { 212069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project factor += 2; 213069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } else { 214069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.realm != ANY_REALM && that.realm != ANY_REALM) { 215069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return -1; 216069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 217069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 218069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.port == that.port) { 219069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project factor += 4; 220069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } else { 221069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.port != ANY_PORT && that.port != ANY_PORT) { 222069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return -1; 223069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 224069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 225069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (LangUtils.equals(this.host, that.host)) { 226069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project factor += 8; 227069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } else { 228069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.host != ANY_HOST && that.host != ANY_HOST) { 229069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return -1; 230069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 231069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 232069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return factor; 233069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 234069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 235069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 236069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @see java.lang.Object#equals(Object) 237069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 238069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project @Override 239069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public boolean equals(Object o) { 240069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (o == null) { 241069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return false; 242069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 243069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (o == this) { 244069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return true; 245069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 246069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (!(o instanceof AuthScope)) { 247069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return super.equals(o); 248069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 249069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project AuthScope that = (AuthScope) o; 250069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return 251069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project LangUtils.equals(this.host, that.host) 252069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project && this.port == that.port 253069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project && LangUtils.equals(this.realm, that.realm) 254069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project && LangUtils.equals(this.scheme, that.scheme); 255069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 256069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 257069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 258069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @see java.lang.Object#toString() 259069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 260069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project @Override 261069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public String toString() { 262069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project StringBuffer buffer = new StringBuffer(); 263069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.scheme != null) { 264069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(this.scheme.toUpperCase(Locale.ENGLISH)); 265069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(' '); 266069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 267069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.realm != null) { 268069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append('\''); 269069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(this.realm); 270069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append('\''); 271069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } else { 272069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append("<any realm>"); 273069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 274069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.host != null) { 275069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append('@'); 276069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(this.host); 277069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.port >= 0) { 278069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(':'); 279069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project buffer.append(this.port); 280069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 281069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 282069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return buffer.toString(); 283069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 284069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 285069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 286069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @see java.lang.Object#hashCode() 287069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 288069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project @Override 289069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public int hashCode() { 290069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project int hash = LangUtils.HASH_SEED; 291069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project hash = LangUtils.hashCode(hash, this.host); 292069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project hash = LangUtils.hashCode(hash, this.port); 293069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project hash = LangUtils.hashCode(hash, this.realm); 294069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project hash = LangUtils.hashCode(hash, this.scheme); 295069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return hash; 296069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 297069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project} 298