1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
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
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
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 }