001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/NTCredentials.java,v 1.10 2004/04/18 23:51:35 jsdever Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: *
006: * ====================================================================
007: *
008: * Licensed to the Apache Software Foundation (ASF) under one or more
009: * contributor license agreements. See the NOTICE file distributed with
010: * this work for additional information regarding copyright ownership.
011: * The ASF licenses this file to You under the Apache License, Version 2.0
012: * (the "License"); you may not use this file except in compliance with
013: * the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing, software
018: * distributed under the License is distributed on an "AS IS" BASIS,
019: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020: * See the License for the specific language governing permissions and
021: * limitations under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: */
030:
031: package org.apache.commons.httpclient;
032:
033: import org.apache.commons.httpclient.util.LangUtils;
034:
035: /** {@link Credentials} for use with the NTLM authentication scheme which requires additional
036: * information.
037: *
038: * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
039: * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
040: *
041: * @version $Revision: 480424 $ $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
042: *
043: * @since 2.0
044: */
045: public class NTCredentials extends UsernamePasswordCredentials {
046:
047: // ----------------------------------------------------- Instance Variables
048:
049: /** The Domain to authenticate with. */
050: private String domain;
051:
052: /** The host the authentication request is originating from. */
053: private String host;
054:
055: // ----------------------------------------------------------- Constructors
056:
057: /**
058: * Default constructor.
059: *
060: * @deprecated Do not use. Null user name, domain & host no longer allowed
061: */
062: public NTCredentials() {
063: super ();
064: }
065:
066: /**
067: * Constructor.
068: * @param userName The user name. This should not include the domain to authenticate with.
069: * For example: "user" is correct whereas "DOMAIN\\user" is not.
070: * @param password The password.
071: * @param host The host the authentication request is originating from. Essentially, the
072: * computer name for this machine.
073: * @param domain The domain to authenticate within.
074: */
075: public NTCredentials(String userName, String password, String host,
076: String domain) {
077: super (userName, password);
078: if (domain == null) {
079: throw new IllegalArgumentException("Domain may not be null");
080: }
081: this .domain = domain;
082: if (host == null) {
083: throw new IllegalArgumentException("Host may not be null");
084: }
085: this .host = host;
086: }
087:
088: // ------------------------------------------------------- Instance Methods
089:
090: /**
091: * Sets the domain to authenticate with. The domain may not be null.
092: *
093: * @param domain the NT domain to authenticate in.
094: *
095: * @see #getDomain()
096: *
097: * @deprecated Do not use. The NTCredentials objects should be immutable
098: */
099: public void setDomain(String domain) {
100: if (domain == null) {
101: throw new IllegalArgumentException("Domain may not be null");
102: }
103: this .domain = domain;
104: }
105:
106: /**
107: * Retrieves the name to authenticate with.
108: *
109: * @return String the domain these credentials are intended to authenticate with.
110: *
111: * @see #setDomain(String)
112: *
113: */
114: public String getDomain() {
115: return domain;
116: }
117:
118: /**
119: * Sets the host name of the computer originating the request. The host name may
120: * not be null.
121: *
122: * @param host the Host the user is logged into.
123: *
124: * @deprecated Do not use. The NTCredentials objects should be immutable
125: */
126: public void setHost(String host) {
127: if (host == null) {
128: throw new IllegalArgumentException("Host may not be null");
129: }
130: this .host = host;
131: }
132:
133: /**
134: * Retrieves the host name of the computer originating the request.
135: *
136: * @return String the host the user is logged into.
137: */
138: public String getHost() {
139: return this .host;
140: }
141:
142: /**
143: * Return a string representation of this object.
144: * @return A string represenation of this object.
145: */
146: public String toString() {
147: final StringBuffer sbResult = new StringBuffer(super .toString());
148:
149: sbResult.append("@");
150: sbResult.append(this .host);
151: sbResult.append(".");
152: sbResult.append(this .domain);
153:
154: return sbResult.toString();
155: }
156:
157: /**
158: * Computes a hash code based on all the case-sensitive parts of the credentials object.
159: *
160: * @return The hash code for the credentials.
161: */
162: public int hashCode() {
163: int hash = super .hashCode();
164: hash = LangUtils.hashCode(hash, this .host);
165: hash = LangUtils.hashCode(hash, this .domain);
166: return hash;
167: }
168:
169: /**
170: * Performs a case-sensitive check to see if the components of the credentials
171: * are the same.
172: *
173: * @param o The object to match.
174: *
175: * @return <code>true</code> if all of the credentials match.
176: */
177: public boolean equals(Object o) {
178: if (o == null)
179: return false;
180: if (this == o)
181: return true;
182: if (super .equals(o)) {
183: if (o instanceof NTCredentials) {
184: NTCredentials that = (NTCredentials) o;
185:
186: return LangUtils.equals(this .domain, that.domain)
187: && LangUtils.equals(this .host, that.host);
188: }
189: }
190:
191: return false;
192: }
193: }
|