View Javadoc

1   /*
2    * $Id: UserImpl.java 124 2004-11-01 18:09:40Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.security;
24  
25  import java.io.Serializable;
26  import java.util.Collections;
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  /**
31   * Implementatio of <code>User</code> interface.
32   *
33   * @author  Jose M. Palomar
34   * @version $Revision: 124 $
35   */
36  public class UserImpl implements User, Serializable {
37  
38      // Fields
39      /**
40       * Login name of user.
41       */
42      private final String login;
43  
44      /**
45       * Real name of user.
46       */
47      private final String name;
48  
49      /**
50       * Roles of user.
51       */
52      private final Set roles;
53  
54      // Constructors
55      /**
56       * Creates a new <code>UserImpl</code> instance.
57       *
58       * @param login String login name of user.
59       * @param name String real name of user.
60       * @param roles Set roles of user.
61       */
62      public UserImpl(String login, String name, Set roles) {
63          this.login = login;
64          this.name = name;
65          this.roles = Collections.unmodifiableSet(new HashSet(roles));
66      }
67  
68      // Methods
69      /**
70       * Returns login name of user.
71       *
72       * @return String login name of user.
73       * @see org.talika.tarsis.security.User#getLogin()
74       */
75      public final String getLogin() {
76          return login;
77      }
78  
79      /**
80       * Returns real name of user.
81       *
82       * @return String real name of user.
83       * @see org.talika.tarsis.security.User#getRealName()
84       */
85      public final String getRealName() {
86          return name;
87      }
88  
89      /**
90       * Returns roles of user.
91       *
92       * @return Set roles of user.
93       * @see org.talika.tarsis.security.User#getRoles()
94       */
95      public final Set getRoles() {
96          return roles;
97      }
98  
99      /**
100      * Indicates whether some other object is "equal to" this one.
101      *
102      * @param obj Object the reference object with which to compare.
103      * @return boolean <code>true</code> if this object is the same as the obj
104      * argument; <code>false</code> otherwise.
105      */
106     public final boolean equals(Object obj) {
107         return ((obj instanceof User) && ((User) obj).getLogin().equals(this.login));
108     }
109 
110     /**
111      * Returns a hash code value for the object.
112      *
113      * @return int a hash code value for this object.
114      */
115     public final int hashCode() {
116         return this.login.hashCode();
117     }
118 
119     /**
120      * Returns a string representation of the object.
121      *
122      * @return String a string representation of the object.
123      */
124     public String toString() {
125 
126         StringBuffer str = new StringBuffer();
127         str.append("{");
128         str.append(this.login);
129         str.append(";");
130         str.append(this.name);
131         str.append(";");
132         str.append(roles);
133         str.append("}");
134 
135         return str.toString();
136     }
137 
138 }