KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > auth > ClientInfo


1 /*
2  * Copyright (C) 2005 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;
18
19 import org.alfresco.service.cmr.repository.NodeRef;
20
21 import net.sf.acegisecurity.Authentication;
22
23 /**
24  * Client Information Class
25  *
26  * <p>The client information class holds the details of a remote user from a session setup or tree
27  * connect request.
28  *
29  * @author GKSpencer
30  */

31 public class ClientInfo
32 {
33
34     // Logon types
35

36     public final static int LogonNormal = 0;
37     public final static int LogonGuest = 1;
38     public final static int LogonNull = 2;
39     public final static int LogonAdmin = 3;
40
41     // Logon type strings
42

43     private static final String JavaDoc[] _logonTypStr = { "Normal", "Guest", "Null", "Administrator" };
44
45     // User name and password
46

47     private String JavaDoc m_user;
48     private byte[] m_password;
49
50     // ANSI encrypted password
51

52     private byte[] m_ansiPwd;
53
54     // Logon type
55

56     private int m_logonType;
57
58     // User's domain
59

60     private String JavaDoc m_domain;
61
62     // Operating system type
63

64     private String JavaDoc m_opsys;
65
66     // Remote network address
67

68     private String JavaDoc m_ipAddr;
69
70     // Authentication token
71

72     private Authentication m_authToken;
73     
74     // Home folder node
75

76     private NodeRef m_homeNode;
77     
78     /**
79      * Class constructor
80      *
81      * @param user User name
82      * @param pwd Password
83      */

84     public ClientInfo(String JavaDoc user, byte[] pwd)
85     {
86         setUserName(user);
87         setPassword(pwd);
88     }
89
90     /**
91      * Get the remote users domain.
92      *
93      * @return String
94      */

95     public final String JavaDoc getDomain()
96     {
97         return m_domain;
98     }
99
100     /**
101      * Get the remote operating system
102      *
103      * @return String
104      */

105     public final String JavaDoc getOperatingSystem()
106     {
107         return m_opsys;
108     }
109
110     /**
111      * Get the password.
112      *
113      * @return String.
114      */

115     public final byte[] getPassword()
116     {
117         return m_password;
118     }
119
120     /**
121      * Return the password as a string
122      *
123      * @return String
124      */

125     public final String JavaDoc getPasswordAsString()
126     {
127         if (m_password != null)
128             return new String JavaDoc(m_password);
129         return null;
130     }
131
132     /**
133      * Return the password as a character array
134      *
135      * @return char[]
136      */

137     public final char[] getPasswordAsCharArray()
138     {
139         char[] cpwd = null;
140
141         if (m_password != null)
142         {
143             String JavaDoc pwd = new String JavaDoc(m_password);
144             cpwd = new char[pwd.length()];
145             pwd.getChars(0, pwd.length(), cpwd, 0);
146         }
147         return cpwd;
148     }
149
150     /**
151      * Determine if the client has specified an ANSI password
152      *
153      * @return boolean
154      */

155     public final boolean hasANSIPassword()
156     {
157         return m_ansiPwd != null ? true : false;
158     }
159
160     /**
161      * Return the ANSI encrypted password
162      *
163      * @return byte[]
164      */

165     public final byte[] getANSIPassword()
166     {
167         return m_ansiPwd;
168     }
169
170     /**
171      * Return the ANSI password as a string
172      *
173      * @return String
174      */

175     public final String JavaDoc getANSIPasswordAsString()
176     {
177         if (m_ansiPwd != null)
178             return new String JavaDoc(m_ansiPwd);
179         return null;
180     }
181
182     /**
183      * Get the user name.
184      *
185      * @return String
186      */

187     public final String JavaDoc getUserName()
188     {
189         return m_user;
190     }
191
192     /**
193      * Return the logon type
194      *
195      * @return int
196      */

197     public final int getLogonType()
198     {
199         return m_logonType;
200     }
201
202     /**
203      * Return the logon type as a string
204      *
205      * @return String
206      */

207     public final String JavaDoc getLogonTypeString()
208     {
209         return _logonTypStr[m_logonType];
210     }
211
212     /**
213      * Determine if the user is logged on as a guest
214      *
215      * @return boolean
216      */

217     public final boolean isGuest()
218     {
219         return m_logonType == LogonGuest ? true : false;
220     }
221
222     /**
223      * Determine if the session is a null session
224      *
225      * @return boolean
226      */

227     public final boolean isNullSession()
228     {
229         return m_logonType == LogonNull ? true : false;
230     }
231
232     /**
233      * Determine if the user if logged on as an administrator
234      *
235      * @return boolean
236      */

237     public final boolean isAdministrator()
238     {
239         return m_logonType == LogonAdmin ? true : false;
240     }
241
242     /**
243      * Determine if the client network address has been set
244      *
245      * @return boolean
246      */

247     public final boolean hasClientAddress()
248     {
249         return m_ipAddr != null ? true : false;
250     }
251
252     /**
253      * Return the client network address
254      *
255      * @return String
256      */

257     public final String JavaDoc getClientAddress()
258     {
259         return m_ipAddr;
260     }
261
262     /**
263      * Check if the client has an authentication token
264      *
265      * @return boolean
266      */

267     public final boolean hasAuthenticationToken()
268     {
269         return m_authToken != null ? true : false;
270     }
271     
272     /**
273      * Return the authentication token
274      *
275      * @return Authentication
276      */

277     public final Authentication getAuthenticationToken()
278     {
279         return m_authToken;
280     }
281     
282     /**
283      * Check if the client has a home folder node
284      *
285      * @return boolean
286      */

287     public final boolean hasHomeFolder()
288     {
289         return m_homeNode != null ? true : false;
290     }
291     
292     /**
293      * Return the home folder node
294      *
295      * @return NodeRef
296      */

297     public final NodeRef getHomeFolder()
298     {
299         return m_homeNode;
300     }
301     
302     /**
303      * Set the remote users domain
304      *
305      * @param domain Remote users domain
306      */

307     public final void setDomain(String JavaDoc domain)
308     {
309         m_domain = domain;
310     }
311
312     /**
313      * Set the remote users operating system type.
314      *
315      * @param opsys Remote operating system
316      */

317     public final void setOperatingSystem(String JavaDoc opsys)
318     {
319         m_opsys = opsys;
320     }
321
322     /**
323      * Set the password.
324      *
325      * @param pwd byte[]
326      */

327     public final void setPassword(byte[] pwd)
328     {
329         m_password = pwd;
330     }
331
332     /**
333      * Set the ANSI encrypted password
334      *
335      * @param pwd byte[]
336      */

337     public final void setANSIPassword(byte[] pwd)
338     {
339         m_ansiPwd = pwd;
340     }
341
342     /**
343      * Set the password
344      *
345      * @param pwd Password string.
346      */

347     public final void setPassword(String JavaDoc pwd)
348     {
349         if (pwd != null)
350             m_password = pwd.getBytes();
351         else
352             m_password = null;
353     }
354
355     /**
356      * Set the user name
357      *
358      * @param user User name string.
359      */

360     public final void setUserName(String JavaDoc user)
361     {
362         m_user = user;
363     }
364
365     /**
366      * Set the logon type
367      *
368      * @param logonType int
369      */

370     public final void setLogonType(int logonType)
371     {
372         m_logonType = logonType;
373     }
374
375     /**
376      * Set the guest logon flag
377      *
378      * @param guest boolean
379      */

380     public final void setGuest(boolean guest)
381     {
382         setLogonType(guest == true ? LogonGuest : LogonNormal);
383     }
384
385     /**
386      * Set the client network address
387      *
388      * @param addr String
389      */

390     public final void setClientAddress(String JavaDoc addr)
391     {
392         m_ipAddr = addr;
393     }
394
395     /**
396      * Set the authentication toekn
397      *
398      * @param token Authentication
399      */

400     public final void setAuthenticationToken(Authentication token)
401     {
402         m_authToken = token;
403     }
404     
405     /**
406      * Set the home folder node
407      *
408      * @param homeNode NodeRef
409      */

410     public final void setHomeFolder(NodeRef homeNode)
411     {
412         m_homeNode = homeNode;
413     }
414     
415     /**
416      * Display the client information as a string
417      *
418      * @return String
419      */

420     public String JavaDoc toString()
421     {
422         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
423         str.append("[");
424         str.append(getUserName());
425         str.append(":");
426         str.append(getPassword());
427         str.append(",");
428         str.append(getDomain());
429         str.append(",");
430         str.append(getOperatingSystem());
431
432         if (hasClientAddress())
433         {
434             str.append(",");
435             str.append(getClientAddress());
436         }
437
438         if ( hasAuthenticationToken())
439         {
440             str.append(",token=");
441             str.append(getAuthenticationToken());
442         }
443         
444         if (isGuest())
445             str.append(",Guest");
446         str.append("]");
447
448         return str.toString();
449     }
450 }
Popular Tags