summaryrefslogtreecommitdiffstats
path: root/src/org/apache/http/auth
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:29:16 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:29:16 -0800
commit069490a5ca2fd1988d29daf45d892f47ad665115 (patch)
treeaea04c65769a1d9e3ca6fde36a7d23bd91dbeb98 /src/org/apache/http/auth
parente5d9544310b857f3ee9ec172bdbff8077323f9a1 (diff)
downloadandroid_external_apache-http-069490a5ca2fd1988d29daf45d892f47ad665115.tar.gz
android_external_apache-http-069490a5ca2fd1988d29daf45d892f47ad665115.tar.bz2
android_external_apache-http-069490a5ca2fd1988d29daf45d892f47ad665115.zip
auto import from //depot/cupcake/@135843
Diffstat (limited to 'src/org/apache/http/auth')
-rw-r--r--src/org/apache/http/auth/AUTH.java66
-rw-r--r--src/org/apache/http/auth/AuthScheme.java140
-rw-r--r--src/org/apache/http/auth/AuthSchemeFactory.java46
-rw-r--r--src/org/apache/http/auth/AuthSchemeRegistry.java149
-rw-r--r--src/org/apache/http/auth/AuthScope.java292
-rw-r--r--src/org/apache/http/auth/AuthState.java147
-rw-r--r--src/org/apache/http/auth/AuthenticationException.java73
-rw-r--r--src/org/apache/http/auth/BasicUserPrincipal.java90
-rw-r--r--src/org/apache/http/auth/Credentials.java49
-rw-r--r--src/org/apache/http/auth/InvalidCredentialsException.java71
-rw-r--r--src/org/apache/http/auth/MalformedChallengeException.java73
-rw-r--r--src/org/apache/http/auth/NTCredentials.java180
-rw-r--r--src/org/apache/http/auth/NTUserPrincipal.java113
-rw-r--r--src/org/apache/http/auth/UsernamePasswordCredentials.java126
-rw-r--r--src/org/apache/http/auth/package.html41
-rw-r--r--src/org/apache/http/auth/params/AuthPNames.java56
-rw-r--r--src/org/apache/http/auth/params/AuthParamBean.java47
-rw-r--r--src/org/apache/http/auth/params/AuthParams.java94
-rw-r--r--src/org/apache/http/auth/params/package.html40
19 files changed, 1893 insertions, 0 deletions
diff --git a/src/org/apache/http/auth/AUTH.java b/src/org/apache/http/auth/AUTH.java
new file mode 100644
index 0000000..8ab6dc2
--- /dev/null
+++ b/src/org/apache/http/auth/AUTH.java
@@ -0,0 +1,66 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AUTH.java $
+ * $Revision: 618365 $
+ * $Date: 2008-02-04 10:20:08 -0800 (Mon, 04 Feb 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+/**
+ * Constants and static helpers related to the HTTP authentication.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public final class AUTH {
+
+ /**
+ * The www authenticate challange header.
+ */
+ public static final String WWW_AUTH = "WWW-Authenticate";
+
+ /**
+ * The www authenticate response header.
+ */
+ public static final String WWW_AUTH_RESP = "Authorization";
+
+ /**
+ * The proxy authenticate challange header.
+ */
+ public static final String PROXY_AUTH = "Proxy-Authenticate";
+
+ /**
+ * The proxy authenticate response header.
+ */
+ public static final String PROXY_AUTH_RESP = "Proxy-Authorization";
+
+ private AUTH() {
+ }
+
+}
diff --git a/src/org/apache/http/auth/AuthScheme.java b/src/org/apache/http/auth/AuthScheme.java
new file mode 100644
index 0000000..bdaebdb
--- /dev/null
+++ b/src/org/apache/http/auth/AuthScheme.java
@@ -0,0 +1,140 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthScheme.java $
+ * $Revision: 537144 $
+ * $Date: 2007-05-11 02:30:13 -0700 (Fri, 11 May 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import org.apache.http.Header;
+import org.apache.http.HttpRequest;
+
+/**
+ * <p>
+ * This interface represents an abstract challenge-response oriented
+ * authentication scheme.
+ * </p>
+ * <p>
+ * An authentication scheme should be able to support the following
+ * functions:
+ * <ul>
+ * <li>Parse and process the challenge sent by the targer server
+ * in response to request for a protected resource
+ * <li>Provide its textual designation
+ * <li>Provide its parameters, if available
+ * <li>Provide the realm this authentication scheme is applicable to,
+ * if available
+ * <li>Generate authorization string for the given set of credentials,
+ * request method and URI as specificed in the HTTP request line
+ * in response to the actual authorization challenge
+ * </ul>
+ * </p>
+ * <p>
+ * Authentication schemes may ignore method name and URI parameters
+ * if they are not relevant for the given authentication mechanism
+ * </p>
+ * <p>
+ * Authentication schemes may be stateful involving a series of
+ * challenge-response exchanges
+ * </p>
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
+ *
+ * @since 4.0
+ */
+
+public interface AuthScheme {
+
+ /**
+ * Processes the given challenge token. Some authentication schemes
+ * may involve multiple challenge-response exchanges. Such schemes must be able
+ * to maintain the state information when dealing with sequential challenges
+ *
+ * @param header the challenge header
+ */
+ void processChallenge(final Header header) throws MalformedChallengeException;
+
+ /**
+ * Returns textual designation of the given authentication scheme.
+ *
+ * @return the name of the given authentication scheme
+ */
+ String getSchemeName();
+
+ /**
+ * Returns authentication parameter with the given name, if available.
+ *
+ * @param name The name of the parameter to be returned
+ *
+ * @return the parameter with the given name
+ */
+ String getParameter(final String name);
+
+ /**
+ * Returns authentication realm. If the concept of an authentication
+ * realm is not applicable to the given authentication scheme, returns
+ * <code>null</code>.
+ *
+ * @return the authentication realm
+ */
+ String getRealm();
+
+ /**
+ * Tests if the authentication scheme is provides authorization on a per
+ * connection basis instead of usual per request basis
+ *
+ * @return <tt>true</tt> if the scheme is connection based, <tt>false</tt>
+ * if the scheme is request based.
+ */
+ boolean isConnectionBased();
+
+ /**
+ * Authentication process may involve a series of challenge-response exchanges.
+ * This method tests if the authorization process has been completed, either
+ * successfully or unsuccessfully, that is, all the required authorization
+ * challenges have been processed in their entirety.
+ *
+ * @return <tt>true</tt> if the authentication process has been completed,
+ * <tt>false</tt> otherwise.
+ */
+ boolean isComplete();
+
+ /**
+ * Produces an authorization string for the given set of {@link Credentials}.
+ *
+ * @param credentials The set of credentials to be used for athentication
+ * @param request The request being authenticated
+ * @throws AuthenticationException if authorization string cannot
+ * be generated due to an authentication failure
+ *
+ * @return the authorization string
+ */
+ Header authenticate(Credentials credentials, HttpRequest request)
+ throws AuthenticationException;
+
+}
diff --git a/src/org/apache/http/auth/AuthSchemeFactory.java b/src/org/apache/http/auth/AuthSchemeFactory.java
new file mode 100644
index 0000000..8f985b0
--- /dev/null
+++ b/src/org/apache/http/auth/AuthSchemeFactory.java
@@ -0,0 +1,46 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthSchemeFactory.java $
+ * $Revision: 527900 $
+ * $Date: 2007-04-12 05:35:25 -0700 (Thu, 12 Apr 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import org.apache.http.params.HttpParams;
+
+/**
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public interface AuthSchemeFactory {
+
+ AuthScheme newInstance(HttpParams params);
+
+}
diff --git a/src/org/apache/http/auth/AuthSchemeRegistry.java b/src/org/apache/http/auth/AuthSchemeRegistry.java
new file mode 100644
index 0000000..62a5d4d
--- /dev/null
+++ b/src/org/apache/http/auth/AuthSchemeRegistry.java
@@ -0,0 +1,149 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthSchemeRegistry.java $
+ * $Revision: 652950 $
+ * $Date: 2008-05-02 16:49:48 -0700 (Fri, 02 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.http.params.HttpParams;
+
+/**
+ * Authentication scheme registry that can be used to obtain the corresponding
+ * authentication scheme implementation for a given type of authorization challenge.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ *
+ * @version $Revision: 652950 $
+ * @since 4.0
+ */
+public final class AuthSchemeRegistry {
+
+ private final Map<String,AuthSchemeFactory> registeredSchemes;
+
+ public AuthSchemeRegistry() {
+ super();
+ this.registeredSchemes = new LinkedHashMap<String,AuthSchemeFactory>();
+ }
+
+ /**
+ * Registers a {@link AuthSchemeFactory} with the given identifier. If a factory with the
+ * given name already exists it will be overridden. This name is the same one used to
+ * retrieve the {@link AuthScheme authentication scheme} from {@link #getAuthScheme}.
+ *
+ * <p>
+ * Please note that custom authentication preferences, if used, need to be updated accordingly
+ * for the new {@link AuthScheme authentication scheme} to take effect.
+ * </p>
+ *
+ * @param name the identifier for this scheme
+ * @param factory the {@link AuthSchemeFactory} class to register
+ *
+ * @see #getAuthScheme
+ */
+ public synchronized void register(
+ final String name,
+ final AuthSchemeFactory factory) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name may not be null");
+ }
+ if (factory == null) {
+ throw new IllegalArgumentException("Authentication scheme factory may not be null");
+ }
+ registeredSchemes.put(name.toLowerCase(Locale.ENGLISH), factory);
+ }
+
+ /**
+ * Unregisters the class implementing an {@link AuthScheme authentication scheme} with
+ * the given name.
+ *
+ * @param name the identifier of the class to unregister
+ */
+ public synchronized void unregister(final String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name may not be null");
+ }
+ registeredSchemes.remove(name.toLowerCase(Locale.ENGLISH));
+ }
+
+ /**
+ * Gets the {@link AuthScheme authentication scheme} with the given name.
+ *
+ * @param name the {@link AuthScheme authentication scheme} identifier
+ * @param params the {@link HttpParams HTTP parameters} for the authentication
+ * scheme.
+ *
+ * @return {@link AuthScheme authentication scheme}
+ *
+ * @throws IllegalStateException if a scheme with the given name cannot be found
+ */
+ public synchronized AuthScheme getAuthScheme(final String name, final HttpParams params)
+ throws IllegalStateException {
+
+ if (name == null) {
+ throw new IllegalArgumentException("Name may not be null");
+ }
+ AuthSchemeFactory factory = registeredSchemes.get(name.toLowerCase(Locale.ENGLISH));
+ if (factory != null) {
+ return factory.newInstance(params);
+ } else {
+ throw new IllegalStateException("Unsupported authentication scheme: " + name);
+ }
+ }
+
+ /**
+ * Obtains a list containing names of all registered {@link AuthScheme authentication
+ * schemes} in their default order.
+ *
+ * @return list of registered scheme names
+ */
+ public synchronized List<String> getSchemeNames() {
+ return new ArrayList<String>(registeredSchemes.keySet());
+ }
+
+ /**
+ * Populates the internal collection of registered {@link AuthScheme authentication schemes}
+ * with the content of the map passed as a parameter.
+ *
+ * @param map authentication schemes
+ */
+ public synchronized void setItems(final Map<String, AuthSchemeFactory> map) {
+ if (map == null) {
+ return;
+ }
+ registeredSchemes.clear();
+ registeredSchemes.putAll(map);
+ }
+
+}
diff --git a/src/org/apache/http/auth/AuthScope.java b/src/org/apache/http/auth/AuthScope.java
new file mode 100644
index 0000000..c9d7f56
--- /dev/null
+++ b/src/org/apache/http/auth/AuthScope.java
@@ -0,0 +1,292 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthScope.java $
+ * $Revision: 652950 $
+ * $Date: 2008-05-02 16:49:48 -0700 (Fri, 02 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import java.util.Locale;
+
+import org.apache.http.util.LangUtils;
+
+/**
+ * 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 <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:adrian@intencha.com">Adrian Sutton</a>
+ *
+ * @since 4.0
+ */
+public class AuthScope {
+
+ /**
+ * The <tt>null</tt> value represents any host. In the future versions of
+ * HttpClient the use of this parameter will be discontinued.
+ */
+ public static final String ANY_HOST = null;
+
+ /**
+ * The <tt>-1</tt> value represents any port.
+ */
+ public static final int ANY_PORT = -1;
+
+ /**
+ * The <tt>null</tt> value represents any realm.
+ */
+ public static final String ANY_REALM = null;
+
+ /**
+ * The <tt>null</tt> value represents any authentication scheme.
+ */
+ public static final String ANY_SCHEME = null;
+
+ /**
+ * Default scope matching any host, port, realm and authentication scheme.
+ * In the future versions of HttpClient the use of this parameter will be
+ * discontinued.
+ */
+ public static final AuthScope ANY = new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, ANY_SCHEME);
+
+ /** The authentication scheme the credentials apply to. */
+ private final String scheme;
+
+ /** The realm the credentials apply to. */
+ private final String realm;
+
+ /** The host the credentials apply to. */
+ private final String host;
+
+ /** The port the credentials apply to. */
+ private final int port;
+
+ /** Creates a new credentials scope for the given
+ * <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and
+ * <tt>authentication scheme</tt>.
+ *
+ * @param host the host the credentials apply to. May be set
+ * to <tt>null</tt> 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 <tt>null</tt> if credenticals are applicable to
+ * any realm.
+ * @param scheme the authentication scheme the credentials apply to.
+ * May be set to <tt>null</tt> if credenticals are applicable to
+ * any authentication scheme.
+ */
+ public AuthScope(final String host, int port,
+ final String realm, final String 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);
+ }
+
+ /** 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
+ * to <tt>null</tt> 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 <tt>null</tt> if credenticals are applicable to
+ * any realm.
+ */
+ public AuthScope(final String host, int port, final String realm) {
+ 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
+ * authentication scheme.
+ *
+ * @param host the host the credentials apply to. May be set
+ * to <tt>null</tt> 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.
+ */
+ public AuthScope(final String host, int port) {
+ this(host, port, ANY_REALM, ANY_SCHEME);
+ }
+
+ /**
+ * Creates a copy of the given credentials scope.
+ */
+ public AuthScope(final AuthScope authscope) {
+ 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();
+ }
+
+ /**
+ * @return the host
+ */
+ public String getHost() {
+ return this.host;
+ }
+
+ /**
+ * @return the port
+ */
+ public int getPort() {
+ return this.port;
+ }
+
+ /**
+ * @return the realm name
+ */
+ public String getRealm() {
+ return this.realm;
+ }
+
+ /**
+ * @return the scheme type
+ */
+ public String getScheme() {
+ return this.scheme;
+ }
+
+ /**
+ * 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.
+ */
+ public int match(final AuthScope that) {
+ 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;
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ @Override
+ public boolean equals(Object o) {
+ 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);
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String 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();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int 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;
+ }
+}
diff --git a/src/org/apache/http/auth/AuthState.java b/src/org/apache/http/auth/AuthState.java
new file mode 100644
index 0000000..f55bf86
--- /dev/null
+++ b/src/org/apache/http/auth/AuthState.java
@@ -0,0 +1,147 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthState.java $
+ * $Revision: 659971 $
+ * $Date: 2008-05-25 05:01:22 -0700 (Sun, 25 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+
+/**
+ * This class provides detailed information about the state of the
+ * authentication process.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class AuthState {
+
+ /** Actual authentication scheme */
+ private AuthScheme authScheme;
+
+ /** Actual authentication scope */
+ private AuthScope authScope;
+
+ /** Credentials selected for authentication */
+ private Credentials credentials;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public AuthState() {
+ super();
+ }
+
+ /**
+ * Invalidates the authentication state by resetting its parameters.
+ */
+ public void invalidate() {
+ this.authScheme = null;
+ this.authScope = null;
+ this.credentials = null;
+ }
+
+ public boolean isValid() {
+ return this.authScheme != null;
+ }
+
+ /**
+ * Assigns the given {@link AuthScheme authentication scheme}.
+ *
+ * @param authScheme the {@link AuthScheme authentication scheme}
+ */
+ public void setAuthScheme(final AuthScheme authScheme) {
+ if (authScheme == null) {
+ invalidate();
+ return;
+ }
+ this.authScheme = authScheme;
+ }
+
+ /**
+ * Returns the {@link AuthScheme authentication scheme}.
+ *
+ * @return {@link AuthScheme authentication scheme}
+ */
+ public AuthScheme getAuthScheme() {
+ return this.authScheme;
+ }
+
+
+ /**
+ * Returns user {@link Credentials} selected for authentication if available
+ *
+ * @return user credentials if available, <code>null</code otherwise
+ */
+ public Credentials getCredentials() {
+ return this.credentials;
+ }
+
+
+ /**
+ * Sets user {@link Credentials} to be used for authentication
+ *
+ * @param credentials User credentials
+ */
+ public void setCredentials(final Credentials credentials) {
+ this.credentials = credentials;
+ }
+
+
+ /**
+ * Returns actual {@link AuthScope} if available
+ *
+ * @return actual authentication scope if available, <code>null</code otherwise
+ */
+ public AuthScope getAuthScope() {
+ return this.authScope;
+ }
+
+ /**
+ * Sets actual {@link AuthScope}.
+ *
+ * @param authScope Authentication scope
+ */
+ public void setAuthScope(final AuthScope authScope) {
+ this.authScope = authScope;
+ }
+
+
+ @Override
+ public String toString() {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("auth scope [");
+ buffer.append(this.authScope);
+ buffer.append("]; credentials set [");
+ buffer.append(this.credentials != null ? "true" : "false");
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
diff --git a/src/org/apache/http/auth/AuthenticationException.java b/src/org/apache/http/auth/AuthenticationException.java
new file mode 100644
index 0000000..8b307be
--- /dev/null
+++ b/src/org/apache/http/auth/AuthenticationException.java
@@ -0,0 +1,73 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthenticationException.java $
+ * $Revision: 505684 $
+ * $Date: 2007-02-10 04:40:02 -0800 (Sat, 10 Feb 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import org.apache.http.ProtocolException;
+
+/**
+ * Signals a failure in authentication process
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class AuthenticationException extends ProtocolException {
+
+ private static final long serialVersionUID = -6794031905674764776L;
+
+ /**
+ * Creates a new AuthenticationException with a <tt>null</tt> detail message.
+ */
+ public AuthenticationException() {
+ super();
+ }
+
+ /**
+ * Creates a new AuthenticationException with the specified message.
+ *
+ * @param message the exception detail message
+ */
+ public AuthenticationException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new AuthenticationException with the specified detail message and cause.
+ *
+ * @param message the exception detail message
+ * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
+ * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
+ */
+ public AuthenticationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/src/org/apache/http/auth/BasicUserPrincipal.java b/src/org/apache/http/auth/BasicUserPrincipal.java
new file mode 100644
index 0000000..2485011
--- /dev/null
+++ b/src/org/apache/http/auth/BasicUserPrincipal.java
@@ -0,0 +1,90 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/BasicUserPrincipal.java $
+ * $Revision: 658430 $
+ * $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import java.security.Principal;
+
+import org.apache.http.util.LangUtils;
+
+/**
+ * Basic user principal used for HTTP authentication
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public final class BasicUserPrincipal implements Principal {
+
+ private final String username;
+
+ public BasicUserPrincipal(final String username) {
+ super();
+ if (username == null) {
+ throw new IllegalArgumentException("User name may not be null");
+ }
+ this.username = username;
+ }
+
+ public String getName() {
+ return this.username;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.username);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (this == o) return true;
+ if (o instanceof BasicUserPrincipal) {
+ BasicUserPrincipal that = (BasicUserPrincipal) o;
+ if (LangUtils.equals(this.username, that.username)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("[principal: ");
+ buffer.append(this.username);
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
+
diff --git a/src/org/apache/http/auth/Credentials.java b/src/org/apache/http/auth/Credentials.java
new file mode 100644
index 0000000..846a23b
--- /dev/null
+++ b/src/org/apache/http/auth/Credentials.java
@@ -0,0 +1,49 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/Credentials.java $
+ * $Revision: 658430 $
+ * $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import java.security.Principal;
+
+/**
+ * User name and password based authentication credentials.
+ *
+ * @author Unascribed
+ * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
+ *
+ * @version $Revision: 658430 $ $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
+ */
+public interface Credentials {
+
+ Principal getUserPrincipal();
+
+ String getPassword();
+
+}
diff --git a/src/org/apache/http/auth/InvalidCredentialsException.java b/src/org/apache/http/auth/InvalidCredentialsException.java
new file mode 100644
index 0000000..50155ec
--- /dev/null
+++ b/src/org/apache/http/auth/InvalidCredentialsException.java
@@ -0,0 +1,71 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/InvalidCredentialsException.java $
+ * $Revision: 505684 $
+ * $Date: 2007-02-10 04:40:02 -0800 (Sat, 10 Feb 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+/**
+ * Authentication credentials required to respond to a authentication
+ * challenge are invalid
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class InvalidCredentialsException extends AuthenticationException {
+
+ private static final long serialVersionUID = -4834003835215460648L;
+
+ /**
+ * Creates a new InvalidCredentialsException with a <tt>null</tt> detail message.
+ */
+ public InvalidCredentialsException() {
+ super();
+ }
+
+ /**
+ * Creates a new InvalidCredentialsException with the specified message.
+ *
+ * @param message the exception detail message
+ */
+ public InvalidCredentialsException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new InvalidCredentialsException with the specified detail message and cause.
+ *
+ * @param message the exception detail message
+ * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
+ * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
+ */
+ public InvalidCredentialsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/org/apache/http/auth/MalformedChallengeException.java b/src/org/apache/http/auth/MalformedChallengeException.java
new file mode 100644
index 0000000..8c7e373
--- /dev/null
+++ b/src/org/apache/http/auth/MalformedChallengeException.java
@@ -0,0 +1,73 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/MalformedChallengeException.java $
+ * $Revision: 505684 $
+ * $Date: 2007-02-10 04:40:02 -0800 (Sat, 10 Feb 2007) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import org.apache.http.ProtocolException;
+
+/**
+ * Signals that authentication challenge is in some way invalid or
+ * illegal in the given context
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class MalformedChallengeException extends ProtocolException {
+
+ private static final long serialVersionUID = 814586927989932284L;
+
+ /**
+ * Creates a new MalformedChallengeException with a <tt>null</tt> detail message.
+ */
+ public MalformedChallengeException() {
+ super();
+ }
+
+ /**
+ * Creates a new MalformedChallengeException with the specified message.
+ *
+ * @param message the exception detail message
+ */
+ public MalformedChallengeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new MalformedChallengeException with the specified detail message and cause.
+ *
+ * @param message the exception detail message
+ * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
+ * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
+ */
+ public MalformedChallengeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/org/apache/http/auth/NTCredentials.java b/src/org/apache/http/auth/NTCredentials.java
new file mode 100644
index 0000000..6800c42
--- /dev/null
+++ b/src/org/apache/http/auth/NTCredentials.java
@@ -0,0 +1,180 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTCredentials.java $
+ * $Revision: 658430 $
+ * $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import java.security.Principal;
+import java.util.Locale;
+
+import org.apache.http.util.LangUtils;
+
+/** {@link Credentials} specific to the Windows platform.
+ *
+ * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
+ * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 2.0
+ */
+public class NTCredentials implements Credentials {
+
+ /** The user principal */
+ private final NTUserPrincipal principal;
+
+ /** Password */
+ private final String password;
+
+ /** The host the authentication request is originating from. */
+ private final String workstation;
+
+ /**
+ * The constructor with the fully qualified username and password combined
+ * string argument.
+ *
+ * @param usernamePassword the domain/username:password formed string
+ */
+ public NTCredentials(String usernamePassword) {
+ super();
+ if (usernamePassword == null) {
+ throw new IllegalArgumentException("Username:password string may not be null");
+ }
+ String username;
+ int atColon = usernamePassword.indexOf(':');
+ if (atColon >= 0) {
+ username = usernamePassword.substring(0, atColon);
+ this.password = usernamePassword.substring(atColon + 1);
+ } else {
+ username = usernamePassword;
+ this.password = null;
+ }
+ int atSlash = username.indexOf('/');
+ if (atSlash >= 0) {
+ this.principal = new NTUserPrincipal(
+ username.substring(0, atSlash).toUpperCase(Locale.ENGLISH),
+ username.substring(atSlash + 1));
+ } else {
+ this.principal = new NTUserPrincipal(
+ null,
+ username.substring(atSlash + 1));
+ }
+ this.workstation = null;
+ }
+
+ /**
+ * Constructor.
+ * @param userName The user name. This should not include the domain to authenticate with.
+ * For example: "user" is correct whereas "DOMAIN\\user" is not.
+ * @param password The password.
+ * @param workstation The workstation the authentication request is originating from.
+ * Essentially, the computer name for this machine.
+ * @param domain The domain to authenticate within.
+ */
+ public NTCredentials(
+ final String userName,
+ final String password,
+ final String workstation,
+ final String domain) {
+ super();
+ if (userName == null) {
+ throw new IllegalArgumentException("User name may not be null");
+ }
+ this.principal = new NTUserPrincipal(domain, userName);
+ this.password = password;
+ if (workstation != null) {
+ this.workstation = workstation.toUpperCase(Locale.ENGLISH);
+ } else {
+ this.workstation = null;
+ }
+ }
+
+ public Principal getUserPrincipal() {
+ return this.principal;
+ }
+
+ public String getUserName() {
+ return this.principal.getUsername();
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
+ /**
+ * Retrieves the name to authenticate with.
+ *
+ * @return String the domain these credentials are intended to authenticate with.
+ */
+ public String getDomain() {
+ return this.principal.getDomain();
+ }
+
+ /**
+ * Retrieves the workstation name of the computer originating the request.
+ *
+ * @return String the workstation the user is logged into.
+ */
+ public String getWorkstation() {
+ return this.workstation;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.principal);
+ hash = LangUtils.hashCode(hash, this.workstation);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (this == o) return true;
+ if (o instanceof NTCredentials) {
+ NTCredentials that = (NTCredentials) o;
+ if (LangUtils.equals(this.principal, that.principal)
+ && LangUtils.equals(this.workstation, that.workstation)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("[principal: ");
+ buffer.append(this.principal);
+ buffer.append("][workstation: ");
+ buffer.append(this.workstation);
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
diff --git a/src/org/apache/http/auth/NTUserPrincipal.java b/src/org/apache/http/auth/NTUserPrincipal.java
new file mode 100644
index 0000000..ac91bb8
--- /dev/null
+++ b/src/org/apache/http/auth/NTUserPrincipal.java
@@ -0,0 +1,113 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTUserPrincipal.java $
+ * $Revision: 658430 $
+ * $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import java.security.Principal;
+import java.util.Locale;
+
+import org.apache.http.util.LangUtils;
+
+/** NT (MS Windows specific) user principal used for HTTP authentication
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 4.0
+ */
+public class NTUserPrincipal implements Principal {
+
+ private final String username;
+ private final String domain;
+ private final String ntname;
+
+ public NTUserPrincipal(
+ final String domain,
+ final String username) {
+ super();
+ if (username == null) {
+ throw new IllegalArgumentException("User name may not be null");
+ }
+ this.username = username;
+ if (domain != null) {
+ this.domain = domain.toUpperCase(Locale.ENGLISH);
+ } else {
+ this.domain = null;
+ }
+ if (this.domain != null && this.domain.length() > 0) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(this.domain);
+ buffer.append('/');
+ buffer.append(this.username);
+ this.ntname = buffer.toString();
+ } else {
+ this.ntname = this.username;
+ }
+ }
+
+ public String getName() {
+ return this.ntname;
+ }
+
+ public String getDomain() {
+ return this.domain;
+ }
+
+ public String getUsername() {
+ return this.username;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.username);
+ hash = LangUtils.hashCode(hash, this.domain);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (this == o) return true;
+ if (o instanceof NTUserPrincipal) {
+ NTUserPrincipal that = (NTUserPrincipal) o;
+ if (LangUtils.equals(this.username, that.username)
+ && LangUtils.equals(this.domain, that.domain)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return this.ntname;
+ }
+
+}
diff --git a/src/org/apache/http/auth/UsernamePasswordCredentials.java b/src/org/apache/http/auth/UsernamePasswordCredentials.java
new file mode 100644
index 0000000..f82608c
--- /dev/null
+++ b/src/org/apache/http/auth/UsernamePasswordCredentials.java
@@ -0,0 +1,126 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java $
+ * $Revision: 658430 $
+ * $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
+ *
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import java.security.Principal;
+
+import org.apache.http.util.LangUtils;
+
+/**
+ * Username and password {@link Credentials}
+ *
+ * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
+ * @author Sean C. Sullivan
+ * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 658430 $ $Date: 2008-05-20 14:04:27 -0700 (Tue, 20 May 2008) $
+ *
+ */
+public class UsernamePasswordCredentials implements Credentials {
+
+ private final BasicUserPrincipal principal;
+ private final String password;
+
+ /**
+ * The constructor with the username and password combined string argument.
+ *
+ * @param usernamePassword the username:password formed string
+ * @see #toString
+ */
+ public UsernamePasswordCredentials(String usernamePassword) {
+ super();
+ if (usernamePassword == null) {
+ throw new IllegalArgumentException("Username:password string may not be null");
+ }
+ int atColon = usernamePassword.indexOf(':');
+ if (atColon >= 0) {
+ this.principal = new BasicUserPrincipal(usernamePassword.substring(0, atColon));
+ this.password = usernamePassword.substring(atColon + 1);
+ } else {
+ this.principal = new BasicUserPrincipal(usernamePassword);
+ this.password = null;
+ }
+ }
+
+
+ /**
+ * The constructor with the username and password arguments.
+ *
+ * @param userName the user name
+ * @param password the password
+ */
+ public UsernamePasswordCredentials(String userName, String password) {
+ super();
+ if (userName == null) {
+ throw new IllegalArgumentException("Username may not be null");
+ }
+ this.principal = new BasicUserPrincipal(userName);
+ this.password = password;
+ }
+
+ public Principal getUserPrincipal() {
+ return this.principal;
+ }
+
+ public String getUserName() {
+ return this.principal.getName();
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ @Override
+ public int hashCode() {
+ return this.principal.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (this == o) return true;
+ if (o instanceof UsernamePasswordCredentials) {
+ UsernamePasswordCredentials that = (UsernamePasswordCredentials) o;
+ if (LangUtils.equals(this.principal, that.principal)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return this.principal.toString();
+ }
+
+}
+
diff --git a/src/org/apache/http/auth/package.html b/src/org/apache/http/auth/package.html
new file mode 100644
index 0000000..1493dfb
--- /dev/null
+++ b/src/org/apache/http/auth/package.html
@@ -0,0 +1,41 @@
+<html>
+<head>
+<!--
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/package.html $
+ * $Revision: 555193 $
+ * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+-->
+</head>
+<body>
+The API for client-side HTTP authentication against a server,
+commonly referred to as <i>HttpAuth</i>.
+
+</body>
+</html>
diff --git a/src/org/apache/http/auth/params/AuthPNames.java b/src/org/apache/http/auth/params/AuthPNames.java
new file mode 100644
index 0000000..a053435
--- /dev/null
+++ b/src/org/apache/http/auth/params/AuthPNames.java
@@ -0,0 +1,56 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/params/AuthPNames.java $
+ * $Revision: 578403 $
+ * $Date: 2007-09-22 03:56:04 -0700 (Sat, 22 Sep 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth.params;
+
+/**
+ * Parameter names for HttpAuth.
+ *
+ * @version $Revision: 578403 $
+ *
+ * @since 4.0
+ */
+public interface AuthPNames {
+
+ /**
+ * Defines the charset to be used when encoding
+ * {@link org.apache.http.auth.Credentials}.
+ * <p>
+ * This parameter expects a value of type {@link String}.
+ * If not defined, then
+ * {@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET
+ * HttpProtocolParams.HTTP_ELEMENT_CHARSET}
+ * should be used.
+ * </p>
+ */
+ public static final String CREDENTIAL_CHARSET = "http.auth.credential-charset";
+
+}
diff --git a/src/org/apache/http/auth/params/AuthParamBean.java b/src/org/apache/http/auth/params/AuthParamBean.java
new file mode 100644
index 0000000..5b27328
--- /dev/null
+++ b/src/org/apache/http/auth/params/AuthParamBean.java
@@ -0,0 +1,47 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/params/AuthParamBean.java $
+ * $Revision: 632313 $
+ * $Date: 2008-02-29 05:19:50 -0800 (Fri, 29 Feb 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth.params;
+
+import org.apache.http.params.HttpAbstractParamBean;
+import org.apache.http.params.HttpParams;
+
+public class AuthParamBean extends HttpAbstractParamBean {
+
+ public AuthParamBean (final HttpParams params) {
+ super(params);
+ }
+
+ public void setCredentialCharset (final String charset) {
+ AuthParams.setCredentialCharset(params, charset);
+ }
+
+}
diff --git a/src/org/apache/http/auth/params/AuthParams.java b/src/org/apache/http/auth/params/AuthParams.java
new file mode 100644
index 0000000..a724a8c
--- /dev/null
+++ b/src/org/apache/http/auth/params/AuthParams.java
@@ -0,0 +1,94 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/params/AuthParams.java $
+ * $Revision: 618365 $
+ * $Date: 2008-02-04 10:20:08 -0800 (Mon, 04 Feb 2008) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth.params;
+
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HTTP;
+
+/**
+ * This class implements an adaptor around the {@link HttpParams} interface
+ * to simplify manipulation of the HTTP authentication specific parameters.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: 618365 $
+ *
+ * @since 4.0
+ *
+ * @see AuthPNames
+ */
+public final class AuthParams {
+
+ private AuthParams() {
+ super();
+ }
+
+ /**
+ * Obtains the charset for encoding
+ * {@link org.apache.http.auth.Credentials}.
+ * If not configured,
+ * {@link HTTP#DEFAULT_PROTOCOL_CHARSET HTTP.DEFAULT_PROTOCOL_CHARSET}
+ * is used instead.
+ *
+ * @return The charset
+ *
+ * @see AuthPNames#CREDENTIAL_CHARSET
+ */
+ public static String getCredentialCharset(final HttpParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ String charset = (String) params.getParameter
+ (AuthPNames.CREDENTIAL_CHARSET);
+ //@@@ TODO: inconsistent with JavaDoc in AuthPNames,
+ //@@@ TODO: check HTTP_ELEMENT_CHARSET first, or fix JavaDocs
+ if (charset == null) {
+ charset = HTTP.DEFAULT_PROTOCOL_CHARSET;
+ }
+ return charset;
+ }
+
+
+ /**
+ * Sets the charset to be used when encoding
+ * {@link org.apache.http.auth.Credentials}.
+ *
+ * @param charset The charset
+ */
+ public static void setCredentialCharset(final HttpParams params, final String charset) {
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ params.setParameter(AuthPNames.CREDENTIAL_CHARSET, charset);
+ }
+
+}
diff --git a/src/org/apache/http/auth/params/package.html b/src/org/apache/http/auth/params/package.html
new file mode 100644
index 0000000..f9258fd
--- /dev/null
+++ b/src/org/apache/http/auth/params/package.html
@@ -0,0 +1,40 @@
+<html>
+<head>
+<!--
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/params/package.html $
+ * $Revision: 555193 $
+ * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+-->
+</head>
+<body>
+Parameters for configuring <i>HttpAuth</i>.
+
+</body>
+</html>