KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > user > xml > UserData


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * UserData.java
20  *
21  * This object stores the user data retrieve from the XML user store.
22  */

23
24 // the package that this object will reside in
25
package com.rift.coad.lib.security.user.xml;
26
27 // the java imports
28
import java.util.Set JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import com.rift.coad.lib.security.UserSession;
31 import com.rift.coad.lib.security.user.UserException;
32
33 /**
34  * This object stores the user data retrieve from the XML user store.
35  *
36  * @author Brett Chaldecott
37  */

38 public class UserData {
39     
40     // The classes private member variables
41
private String JavaDoc username = null;
42     private String JavaDoc password = null;
43     private Set JavaDoc principals = null;
44     
45     
46     /**
47      * Creates a new instance of UserData
48      *
49      * @param username The name of the user that this user data object will be
50      * associated with.
51      * @param password The password value for the user object.
52      */

53     public UserData(String JavaDoc username, String JavaDoc password) {
54         this.username = username;
55         this.password = password;
56         principals = new HashSet JavaDoc();
57     }
58     
59     
60     /**
61      * This method sets the username to the value supplied.
62      *
63      * @param username The string object containing the new username of the
64      * object.
65      */

66     public void setUsername(String JavaDoc username) {
67         this.username = username;
68     }
69     
70     
71     /**
72      * This method retrieves the username value for the user.
73      *
74      * @return The string containing the username information.
75      */

76     public String JavaDoc getUsername() {
77         return username;
78     }
79     
80     
81     /**
82      * Set the password value assigned to this user object.
83      *
84      * @param password The string containing the new password value to assign.
85      */

86     public void setPassword(String JavaDoc password) {
87         this.password = password;
88     }
89     
90     
91     /**
92      * This method retrieves the password value held within.
93      *
94      * @return The string containing the password information.
95      */

96     public String JavaDoc getPassword() {
97         return password;
98     }
99     
100     
101     /**
102      * This method adds the principal to the list of principals.
103      *
104      * @param principal The string object containing the principal value.
105      */

106     public void addPrincipal(String JavaDoc principal) {
107         principals.add(principal);
108     }
109     
110     
111     /**
112      * This method retrieves the list of principals from within the user data
113      * object.
114      *
115      * @return The list of principals.
116      */

117     public Set JavaDoc getPrincipals() {
118         return principals;
119     }
120     
121     
122     /**
123      * This method will return TRUE if this object has been initialized.
124      *
125      * @return TRUE if initialized FALSE if not.
126      */

127     public boolean isInitialized() {
128         if ((username == null) || (password == null)) {
129             return false;
130         }
131         return true;
132     }
133     
134     
135     /**
136      * This method returns the reference to the user object.
137      *
138      * @return The reference to the user object.
139      */

140     public UserSession getUser() throws UserException {
141         try {
142             return new UserSession(username,principals);
143         } catch (Exception JavaDoc ex) {
144             throw new UserException (
145                     "Failed to instanciate the user exception : " +
146                     ex.getMessage(),ex);
147         }
148     }
149 }
150
Popular Tags