KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > NTCredentials


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NTCredentials.java,v 1.6.2.2 2004/02/22 18:21:13 olegk Exp $
3  * $Revision: 1.6.2.2 $
4  * $Date: 2004/02/22 18:21:13 $
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  * [Additional notices, if required by prior licensing conditions]
29  *
30  */

31
32 package org.apache.commons.httpclient;
33
34 /** {@link Credentials} for use with the NTLM authentication scheme which requires additional
35  * information.
36  *
37  * @author <a HREF="mailto:adrian@ephox.com">Adrian Sutton</a>
38  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
39  *
40  * @version $Revision: 1.6.2.2 $ $Date: 2004/02/22 18:21:13 $
41  *
42  * @since 2.0
43  */

44 public class NTCredentials extends UsernamePasswordCredentials {
45
46     // ----------------------------------------------------- Instance Variables
47

48     /** The Domain to authenticate with. */
49     private String JavaDoc domain;
50
51     /** The host the authentication request is originating from. */
52     private String JavaDoc host;
53
54
55     // ----------------------------------------------------------- Constructors
56

57     /**
58      * Default constructor.
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 JavaDoc userName, String JavaDoc password, String JavaDoc host,
74             String JavaDoc domain) {
75         super(userName, password);
76         this.domain = domain;
77         this.host = host;
78     }
79     // ------------------------------------------------------- Instance Methods
80

81
82     /**
83      * Sets the domain to authenticate with.
84      *
85      * @param domain the NT domain to authenticate in.
86      *
87      * @see #getDomain()
88      *
89      */

90     public void setDomain(String JavaDoc domain) {
91         this.domain = domain;
92     }
93
94     /**
95      * Retrieves the name to authenticate with.
96      *
97      * @return String the domain these credentials are intended to authenticate with.
98      *
99      * @see #setDomain(String)
100      *
101      */

102     public String JavaDoc getDomain() {
103         return domain;
104     }
105
106     /** Sets the host name of the computer originating the request.
107      *
108      * @param host the Host the user is logged into.
109      */

110     public void setHost(String JavaDoc host) {
111         this.host = host;
112     }
113
114     /**
115      * Retrieves the host name of the computer originating the request.
116      *
117      * @return String the host the user is logged into.
118      */

119     public String JavaDoc getHost() {
120         return this.host;
121     }
122     
123     /**
124      * Return a string representation of this object.
125      * @return A string represenation of this object.
126      */

127     public String JavaDoc toString() {
128         final StringBuffer JavaDoc sbResult = new StringBuffer JavaDoc(super.toString());
129         
130         sbResult.append(":");
131         sbResult.append(this.host == null ? "null" : this.host);
132         sbResult.append(this.domain == null ? "null" : this.domain);
133
134         return sbResult.toString();
135     }
136
137 }
138
Popular Tags