001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * UserData.java
020: *
021: * This object stores the user data retrieve from the XML user store.
022: */
023:
024: // the package that this object will reside in
025: package com.rift.coad.lib.security.user.xml;
026:
027: // the java imports
028: import java.util.Set;
029: import java.util.HashSet;
030: import com.rift.coad.lib.security.UserSession;
031: import com.rift.coad.lib.security.user.UserException;
032:
033: /**
034: * This object stores the user data retrieve from the XML user store.
035: *
036: * @author Brett Chaldecott
037: */
038: public class UserData {
039:
040: // The classes private member variables
041: private String username = null;
042: private String password = null;
043: private Set principals = null;
044:
045: /**
046: * Creates a new instance of UserData
047: *
048: * @param username The name of the user that this user data object will be
049: * associated with.
050: * @param password The password value for the user object.
051: */
052: public UserData(String username, String password) {
053: this .username = username;
054: this .password = password;
055: principals = new HashSet();
056: }
057:
058: /**
059: * This method sets the username to the value supplied.
060: *
061: * @param username The string object containing the new username of the
062: * object.
063: */
064: public void setUsername(String username) {
065: this .username = username;
066: }
067:
068: /**
069: * This method retrieves the username value for the user.
070: *
071: * @return The string containing the username information.
072: */
073: public String getUsername() {
074: return username;
075: }
076:
077: /**
078: * Set the password value assigned to this user object.
079: *
080: * @param password The string containing the new password value to assign.
081: */
082: public void setPassword(String password) {
083: this .password = password;
084: }
085:
086: /**
087: * This method retrieves the password value held within.
088: *
089: * @return The string containing the password information.
090: */
091: public String getPassword() {
092: return password;
093: }
094:
095: /**
096: * This method adds the principal to the list of principals.
097: *
098: * @param principal The string object containing the principal value.
099: */
100: public void addPrincipal(String principal) {
101: principals.add(principal);
102: }
103:
104: /**
105: * This method retrieves the list of principals from within the user data
106: * object.
107: *
108: * @return The list of principals.
109: */
110: public Set getPrincipals() {
111: return principals;
112: }
113:
114: /**
115: * This method will return TRUE if this object has been initialized.
116: *
117: * @return TRUE if initialized FALSE if not.
118: */
119: public boolean isInitialized() {
120: if ((username == null) || (password == null)) {
121: return false;
122: }
123: return true;
124: }
125:
126: /**
127: * This method returns the reference to the user object.
128: *
129: * @return The reference to the user object.
130: */
131: public UserSession getUser() throws UserException {
132: try {
133: return new UserSession(username, principals);
134: } catch (Exception ex) {
135: throw new UserException(
136: "Failed to instanciate the user exception : "
137: + ex.getMessage(), ex);
138: }
139: }
140: }
|