View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program 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.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.businessobjects.security;
16  
17  import org.figure8.join.core.EntityObject;
18  
19  import java.security.Principal;
20  /**
21   * This is en entity representing a User within Join system.
22   * @author  <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
23   * @version $Revision: 1.2 $
24   *
25   * @hibernate.class table="join_users"
26   *
27   * @hibernate.query name="join.user_findByLogin" query="from User user where user.login = :userLogin"
28   * @hibernate.query name="join.user_findByLastnameWild" query="from User user where user.lastname like :lastname"
29   */
30  public class User extends EntityObject implements Principal{
31     
32     // Attributes ---------------------------------------------------------------
33  
34     /** The unique identifier of this object. */
35     private long id = 0;
36  
37     /** This user login : its unique business identifier */
38     private String login;
39     /** This user password */
40     private String password;
41     /** This user lastname */
42     private String lastname;
43     /** This user firstname */
44     private String firstname;
45     /** This user mail address */
46     private String mail;
47     /** This user phone number */
48     private String phone;
49     /** This user team description */
50     private String team;
51  
52  
53     // Constructors -------------------------------------------------------------
54  
55     /** Creates a new instance of User. */
56     public User(){
57     }
58  
59     /**
60      * Creates a new instance of User with mandatory fields.
61      * @param login This user login (must be unique)
62      * @param password This user password (encoded)
63      * @param lastname This user last name
64      * @param firstname This user first name
65      */
66     public User(String login, String password, String lastname, String firstname){
67        this.login = login;
68        this.password = password;
69        this.lastname = lastname;
70        this.firstname = firstname;
71     }
72  
73  
74     // Override of EntityObject -------------------------------------------------
75  
76     /**
77      * Set this user unique identifier. This is necessary because User may be
78      * retrieved from non Join managed datasources and thus id initialized by
79      * different means (other than Hibernate)
80      * @param id Long identifier to set
81      */
82     public void setId(long id){
83        this.id = id;
84     }
85  
86     /**
87      * Get this entity unique identifier.
88      * @return The long identifier
89      */
90     public long getId(){
91        return id;
92     }
93  
94     /**
95      * Tell if this entity has already been persisted into datastore.
96      * @return false if entity has already been persisted, true otherwise
97      */
98     public boolean isTransient(){
99        return (id == 0L);
100    }
101 
102 
103    // Public -------------------------------------------------------------------
104 
105    /**
106     * @hibernate.property column="s_login"
107     *    not-null="true" unique="true"
108     *    length="20" update="false"
109     * @return This user login
110     */
111    public String getLogin(){
112       return login;
113    }
114    /** @param login This user login */
115    public void setLogin(String login){
116       this.login = login;
117    }
118 
119    /**
120     * @hibernate.property column="s_password"
121     *    not-null="true" length="40"
122     * @return This user password
123     */
124    public String getPassword(){
125       return password;
126    }
127    /** @param password New password for this user */
128    public void setPassword(String password){
129       this.password = password;
130    }
131 
132    /**
133     * @hibernate.property column="s_lastname"
134     *    not-null="true" length="30"
135     * @return This user lastname
136     */
137    public String getLastname(){
138       return lastname;
139    }
140    /** @param lastname New lastname for this user */
141    public void setLastname(String lastname){
142       this.lastname = lastname;
143    }
144 
145    /**
146     * @hibernate.property column="s_firstname"
147     *    not-null="true" length="30"
148     * @return This user firstname
149     */
150    public String getFirstname(){
151       return firstname;
152    }
153    /** @param firstname New firstname for this user */
154    public void setFirstname(String firstname){
155       this.firstname = firstname;
156    }
157 
158    /**
159     * @hibernate.property column="s_mail" length="70"
160     * @return This user mail address
161     */
162    public String getMail(){
163       return mail;
164    }
165    /** @param mail New mail address for this user */
166    public void setMail(String mail){
167       this.mail = mail;
168    }
169 
170    /**
171     * @hibernate.property column="s_phone" length="14"
172     * @return This user phone number
173     */
174    public String getPhone(){
175       return phone;
176    }
177    /** @param phone New phone number for this user */
178    public void setPhone(String phone){
179       this.phone = phone;
180    }
181 
182    /**
183     * @hibernate.property column="s_team" length="60"
184     * @return This user team description
185     */
186    public String getTeam(){
187       return team;
188    }
189    /** @param team New team description for this user */
190    public void setTeam(String team){
191       this.team = team;
192    }
193 
194 
195    // Implementation of Principal ----------------------------------------------
196 
197    /**
198     * Implementation of <code>java.security.Principal</code> getName()
199     * method. This implementation returns this user uniques identifier : its login.
200     * @return The user login (business unique identifier)
201     */
202    public String getName(){
203       return login;
204    }
205 
206    /**
207     * Implementation of <code>java.security.Principal</code> toString()
208     * method. This implementation return this user summary : "lastname firstname"
209     */
210    public String toString(){
211       return (lastname + " " + firstname);
212    }
213 }