001: /**
002: * Copyright (C) 2006, 2007 David Bulmore, Software Sensation Inc.
003: * All Rights Reserved.
004: *
005: * This file is part of jWebApp.
006: *
007: * jWebApp is free software; you can redistribute it and/or modify it under
008: * the terms of the GNU General Public License (Version 2) as published by
009: * the Free Software Foundation.
010: *
011: * jWebApp is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with jWebApp; if not, write to the Free Software Foundation,
018: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
019: */package jwebapp.controller;
020:
021: import java.io.Serializable;
022: import java.util.Hashtable;
023: import java.util.Iterator;
024: import java.util.Set;
025:
026: /**
027: * Remote user information.
028: */
029: public class RemoteUser implements Serializable {
030: private static final long serialVersionUID = 100L;
031: private String userId, salutation, firstName, lastName;
032: private Set<String> roles;
033:
034: RemoteUser(String userId, String salutation, String firstName,
035: String lastName, Set<String> roles) {
036: this .userId = userId;
037: this .salutation = salutation;
038: this .firstName = firstName;
039: this .lastName = lastName;
040: this .roles = roles;
041: }
042:
043: /**
044: * Returns the user Id.
045: * @return the user Id
046: */
047: public String getUserId() {
048: return userId;
049: }
050:
051: /**
052: * Returns the users salutation (Mr., Mrs., Miss, ...). May be null.
053: * @return the users salutation
054: */
055: public String getSalutation() {
056: return salutation;
057: }
058:
059: /**
060: * Returns the users first name. May be null.
061: * @return the users first name
062: */
063: public String getFirstName() {
064: return firstName;
065: }
066:
067: /**
068: * Returns the users last name. May be null.
069: * @return the users last name
070: */
071: public String getLastName() {
072: return lastName;
073: }
074:
075: /**
076: * Returns a hash set with all the roles the user is in.
077: * @return an instance of HashSet. May be empty.
078: */
079: public Set<String> getRoles() {
080: return roles;
081: }
082:
083: /**
084: * Returns a hashtable that's suitable for EL with all the roles the user is in.
085: * @return an instance of Hashtable. May be empty.
086: */
087: public Hashtable<String, Boolean> getRoleHash() {
088: Hashtable<String, Boolean> hash = new Hashtable<String, Boolean>();
089:
090: if (roles != null) {
091: Iterator<String> i = roles.iterator();
092:
093: while (i.hasNext())
094: hash.put(i.next(), Boolean.TRUE);
095: }
096:
097: return hash;
098: }
099:
100: public String toString() {
101: return "UserId=" + userId + ", Name=" + salutation + " "
102: + firstName + " " + lastName + ", Roles=" + roles;
103: }
104: }
|