KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > auth > ntlm > NTLMLogonDetails


1 /*
2  * Copyright (C) 2006 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server.auth.ntlm;
18
19 import java.util.Date JavaDoc;
20
21 import net.sf.acegisecurity.Authentication;
22
23 /**
24  * NTLM Logon Details Class
25  *
26  * <p>Contains the details from the NTLM authentication session that was used to authenticate a user.
27  *
28  * @author GKSpencer
29  */

30 public class NTLMLogonDetails
31 {
32     // User name, workstation name and domain
33

34     private String JavaDoc m_user;
35     private String JavaDoc m_workstation;
36     private String JavaDoc m_domain;
37     
38     // Authentication server name/address
39

40     private String JavaDoc m_authSrvAddr;
41     
42     // Date/time the user was authenticated
43

44     private long m_authTime;
45     
46     // User logged on via guest access
47

48     private boolean m_guestAccess;
49     
50     // Cached type 2 NTLM message and copy of the NTLM hash used to successfully logon
51

52     private Type2NTLMMessage m_type2Msg;
53     private byte[] m_ntlmHash;
54     
55     // Authentication token, used for passthru mode
56

57     private Authentication m_authToken;
58     
59     /**
60      * Default constructor
61      */

62     public NTLMLogonDetails()
63     {
64     }
65     
66     /**
67      * Class constructor
68      *
69      * @param user String
70      * @param wks String
71      * @param domain String
72      * @param guest boolean
73      * @param authSrv String
74      */

75     public NTLMLogonDetails(String JavaDoc user, String JavaDoc wks, String JavaDoc domain, boolean guest, String JavaDoc authSrv)
76     {
77         setDetails(user, wks, domain, guest, authSrv);
78     }
79     
80     /**
81      * Return the user name
82      *
83      * @return String
84      */

85     public final String JavaDoc getUserName()
86     {
87         return m_user;
88     }
89     
90     /**
91      * Return the workstation name
92      *
93      * @return String
94      */

95     public final String JavaDoc getWorkstation()
96     {
97         return m_workstation;
98     }
99     
100     /**
101      * Return the domain name
102      *
103      * @return String
104      */

105     public final String JavaDoc getDomain()
106     {
107         return m_domain;
108     }
109     
110     /**
111      * Return the authentication server name/address
112      *
113      * @return String
114      */

115     public final String JavaDoc getAuthenticationServer()
116     {
117         return m_authSrvAddr;
118     }
119
120     /**
121      * Return the date/time the user was authenticated
122      *
123      * @return long
124      */

125     public final long authenticatedAt()
126     {
127         return m_authTime;
128     }
129     
130     /**
131      * Determine if the type 2 NTLM message has been cached
132      *
133      * @return boolean
134      */

135     public final boolean hasType2Message()
136     {
137         return m_type2Msg != null ? true : false;
138     }
139     
140     /**
141      * Return the cached type 2 NTLM message
142      *
143      * @return Type2NTLMMessage
144      */

145     public final Type2NTLMMessage getType2Message()
146     {
147         return m_type2Msg;
148     }
149     
150     /**
151      * Determine if there is a cached NTLM hashed password
152      *
153      * @return boolean
154      */

155     public final boolean hasNTLMHashedPassword()
156     {
157         return m_ntlmHash != null ? true : false;
158     }
159     
160     /**
161      * Return the cached NTLM hashed password
162      *
163      * @return byte[]
164      */

165     public final byte[] getNTLMHashedPassword()
166     {
167         return m_ntlmHash;
168     }
169     
170     /**
171      * Return the challenge key from the type2 message
172      *
173      * @return byte[]
174      */

175     public final byte[] getChallengeKey()
176     {
177         if ( m_type2Msg != null)
178             return m_type2Msg.getChallenge();
179         return null;
180     }
181     
182     /**
183      * Determine if the passthru authentication token is valid
184      *
185      * @return boolean
186      */

187     public final boolean hasAuthenticationToken()
188     {
189         return m_authToken != null ? true : false;
190     }
191     
192     /**
193      * Return the authentication token
194      *
195      * @return Authentication
196      */

197     public final Authentication getAuthenticationToken()
198     {
199         return m_authToken;
200     }
201     
202     /**
203      * Set the authentication date/time
204      *
205      * @param authTime long
206      */

207     public final void setAuthenticatedAt(long authTime)
208     {
209         m_authTime = authTime;
210     }
211
212     /**
213      * Set the client details
214      *
215      * @param user String
216      * @param wks String
217      * @param domain String
218      * @param guest boolean
219      * @param authSrv String
220      */

221     public final void setDetails(String JavaDoc user, String JavaDoc wks, String JavaDoc domain, boolean guest, String JavaDoc authSrv)
222     {
223         m_user = user;
224         m_workstation = wks;
225         m_domain = domain;
226
227         m_authSrvAddr = authSrv;
228         
229         m_guestAccess = guest;
230         
231         m_authTime = System.currentTimeMillis();
232     }
233     
234     /**
235      * Set the type 2 NTLM message
236      *
237      * @param type2 Type2NTLMMessage
238      */

239     public final void setType2Message(Type2NTLMMessage type2)
240     {
241         m_type2Msg = type2;
242     }
243     
244     /**
245      * Set the cached NTLM hashed password
246      *
247      * @param ntlmHash byte[]
248      */

249     public final void setNTLMHashedPassword(byte[] ntlmHash)
250     {
251         m_ntlmHash = ntlmHash;
252     }
253     
254     /**
255      * Set the passthru authentication token
256      *
257      * @param token Authentication
258      */

259     public final void setAuthenticationToken(Authentication token)
260     {
261         m_authToken = token;
262     }
263     
264     /**
265      * Return the NTLM logon details as a string
266      *
267      * @return String
268      */

269     public String JavaDoc toString()
270     {
271         StringBuilder JavaDoc str = new StringBuilder JavaDoc();
272         
273         str.append("[");
274         str.append(getUserName());
275         str.append(",Wks:");
276         str.append(getWorkstation());
277         str.append(",Dom:");
278         str.append(getDomain());
279         str.append(",AuthSrv:");
280         str.append(getAuthenticationServer());
281         str.append(",");
282         str.append(new Date JavaDoc(authenticatedAt()));
283         
284         if ( hasAuthenticationToken())
285         {
286             str.append(",token=");
287             str.append(getAuthenticationToken());
288         }
289         
290         str.append("]");
291         
292         return str.toString();
293     }
294 }
295
Popular Tags