View Javadoc

1   /*
2    * $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 $
3    * $Revision: 155418 $
4    * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
5    *
6    * ====================================================================
7    *
8    *  Copyright 2002-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   */
29  
30  package org.apache.commons.httpclient;
31  
32  /*** {@link Credentials} for use with the NTLM authentication scheme which requires additional
33   * information.
34   *
35   * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
36   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
37   * 
38   * @version $Revision: 155418 $ $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
39   * 
40   * @since 2.0
41   */
42  public class NTCredentials extends UsernamePasswordCredentials {
43  
44      // ----------------------------------------------------- Instance Variables
45  
46      /*** The Domain to authenticate with.  */
47      private String domain;
48  
49      /*** The host the authentication request is originating from.  */
50      private String host;
51  
52  
53      // ----------------------------------------------------------- Constructors
54  
55      /***
56       * Default constructor.
57       * 
58       * @deprecated Do not use. Null user name, domain & host no longer allowed
59       */
60      public NTCredentials() {
61          super();
62      }
63  
64      /***
65       * Constructor.
66       * @param userName The user name.  This should not include the domain to authenticate with.
67       * For example: "user" is correct whereas "DOMAIN//user" is not.
68       * @param password The password.
69       * @param host The host the authentication request is originating from.  Essentially, the
70       * computer name for this machine.
71       * @param domain The domain to authenticate within.
72       */
73      public NTCredentials(String userName, String password, String host,
74              String domain) {
75          super(userName, password);
76          if (domain == null) {
77              throw new IllegalArgumentException("Domain may not be null");
78          }
79          this.domain = domain;
80          if (host == null) {
81              throw new IllegalArgumentException("Host may not be null");
82          }
83          this.host = host;
84      }
85      // ------------------------------------------------------- Instance Methods
86  
87  
88      /***
89       * Sets the domain to authenticate with. The domain may not be null.
90       *
91       * @param domain the NT domain to authenticate in.
92       * 
93       * @see #getDomain()
94       * 
95       * @deprecated Do not use. The NTCredentials objects should be immutable
96       */
97      public void setDomain(String domain) {
98          if (domain == null) {
99              throw new IllegalArgumentException("Domain may not be null");
100         }
101         this.domain = domain;
102     }
103 
104     /***
105      * Retrieves the name to authenticate with.
106      *
107      * @return String the domain these credentials are intended to authenticate with.
108      * 
109      * @see #setDomain(String)
110      * 
111      */
112     public String getDomain() {
113         return domain;
114     }
115 
116     /*** 
117      * Sets the host name of the computer originating the request. The host name may
118      * not be null.
119      *
120      * @param host the Host the user is logged into.
121      * 
122      * @deprecated Do not use. The NTCredentials objects should be immutable
123      */
124     public void setHost(String host) {
125         if (host == null) {
126             throw new IllegalArgumentException("Host may not be null");
127         }
128         this.host = host;
129     }
130 
131     /***
132      * Retrieves the host name of the computer originating the request.
133      *
134      * @return String the host the user is logged into.
135      */
136     public String getHost() {
137         return this.host;
138     }
139     
140     /***
141      * Return a string representation of this object.
142      * @return A string represenation of this object.
143      */
144     public String toString() {
145         final StringBuffer sbResult = new StringBuffer(super.toString());
146         
147         sbResult.append("@");
148         sbResult.append(this.host);
149         sbResult.append(".");
150         sbResult.append(this.domain);
151 
152         return sbResult.toString();
153     }
154 
155 }