Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/gateway/UserGateway.java


1   /*
2    * UserGateway.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:29 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.gateway;
12  
13  import java.util.Hashtable;
14  
15  import com.flexstor.common.data.ejb.role.RoleData;
16  import com.flexstor.common.data.ejb.user.UserData;
17  import com.flexstor.common.exceptions.ejb.AuthenticationFailedException;
18  import com.flexstor.common.exceptions.ejb.NotFoundException;
19  import com.flexstor.common.gateway.debug.GatewayDebugOutput;
20  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
21  import com.flexstor.common.util.Encrypt;
22  import com.flexstor.ejb.EjbObject;
23  import com.flexstor.ejb.user.User;
24  import com.flexstor.ejb.user.UserHome;
25  
26  /**
27   * Retrieves information from the server for a specific user.
28   * @author Dan Schroeder
29   * @version 3.0
30   */
31  public class UserGateway
32     extends Gateway
33  {
34     // MKS macro expander
35     public final static String IDENTIFIER = "$Id: UserGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
36  
37     private User user = null;
38     
39     protected String getHomeName ( )
40     {
41        return USER_HOME;
42     }
43  
44     protected EjbObject getBeanObject ( )
45     {
46        return user;
47     }
48  
49     /**
50      * Sends the request for user data to the server.
51      * WARNING: This method does NOT perform user authentication!!
52      * @param sUserID The user id for this user
53      * @throws TransactionFailedException Throws if this transaction fails.
54      */
55     public void connect ( String sUserID )
56        throws TransactionFailedException
57     {
58        try
59        {
60           if ( canLoadObject() )
61              return;
62           
63           UserHome home = (UserHome)getHome ( );
64              
65           GatewayDebugOutput.println ( 3, "Getting User object" );
66           user = home.create ( sUserID );
67        }
68        catch ( NotFoundException e )
69        {
70           throw new TransactionFailedException ( e );  
71        }
72        catch ( Throwable e )
73        {
74           throw buildException(e, "Connecting to User", IDENTIFIER );
75        }
76     }
77  
78  
79     /**
80      * Sends the request for user authentication and user data to the server.
81      * @param sUserID The user id for this user
82      * @param sPassword The UNENCRYPTED password for this user
83      * @throws TransactionFailedException Throws if this transaction fails.
84      */
85     public void connect ( String sUserID, String sPassword )
86        throws TransactionFailedException
87     {
88        try
89        {
90           if ( canLoadObject() )
91              return;
92  
93           UserHome home = (UserHome)getHome ( ) ;
94  
95           GatewayDebugOutput.println ( 3, "Authenticating and getting User object" );
96           user = home.create ( sUserID, Encrypt.encrypt(sPassword) );
97        }
98        catch ( AuthenticationFailedException e )
99        {
100          throw new TransactionFailedException ( e );
101       }
102       catch ( NotFoundException e )
103       {
104          throw new TransactionFailedException ( e );
105       }
106       catch ( Throwable e )
107       {
108          throw buildException(e, "Connecting to User", IDENTIFIER );
109       }
110    }
111    
112 
113    /**
114     * Changes the password for the current user.
115     * @param The UNENCRYPTED password for this user
116     * @throws TransactionFailedException Throws if this transaction fails.
117     */
118    public void changePassword ( String sNewPassword )
119       throws TransactionFailedException
120    {
121       try
122       {
123          GatewayDebugOutput.println ( 3, "Change user password" );
124       
125          if ( canLoadObject() )
126             return;
127 
128          user.changePassword ( Encrypt.encrypt(sNewPassword) );
129       }
130       catch ( Throwable e )
131       {
132          throw buildException(e, "Changing Password", IDENTIFIER );
133       }
134    }
135 
136    /**
137     * Changes the password for the current user.
138     * @param The UNENCRYPTED password for this user
139     * @throws TransactionFailedException Throws if this transaction fails.
140     */
141    public void changePassword ( String sUserID, String sPassword, String sNewPassword )
142       throws TransactionFailedException
143    {
144       try
145       {
146          GatewayDebugOutput.println ( 3, "Change user password" );
147          
148          if ( canLoadObject() )
149             return;
150          
151          user.changePassword (sUserID,Encrypt.encrypt(sPassword), Encrypt.encrypt(sNewPassword) );
152       }
153       catch ( Throwable e )
154       {
155          throw buildException(e, "Changing Password", IDENTIFIER );
156       }
157    }
158 
159    /**
160     * Gets the role data for this user.
161     * @return the user's role data.
162     * @throws TransactionFailedException Throws if this transaction fails.
163     */
164    public RoleData getRoleData ( )
165       throws TransactionFailedException
166    {
167       try
168       {
169          GatewayDebugOutput.println ( 3, "Get user role data" );
170 
171          if ( canLoadObject() )
172             return (RoleData)retrieveObject ( "User_getRole" );
173 
174          RoleData data = user.getRole();
175 
176          if ( canSaveObject() )
177             storeObject ( "User_getRole", data );
178 
179          return data;
180       }
181       catch ( Throwable e )
182       {
183          throw buildException(e, "Getting Role Data", IDENTIFIER );
184       }
185    }
186 
187 
188    /**
189     * Updates the role data for this user.
190     * @param data the user's role data.
191     * @throws TransactionFailedException Throws if this transaction fails.
192     */
193    public void updateRoleData ( RoleData data )
194       throws TransactionFailedException 
195    {
196       try
197       {
198          if ( canLoadObject() )
199             return;
200       
201          GatewayDebugOutput.println ( 3, "Update user role data" );
202       
203          user.updateRole ( data );
204       }
205       catch ( Throwable e )
206       {
207          throw buildException(e, "Updating Role Data", IDENTIFIER );
208       }
209    }
210 
211 
212    /**
213     * Updates the preferences for this role.
214     * @param h hashtable of preferences
215     * @throws TransactionFailedException Throws if this transaction fails.
216     */
217    public void updateRolePreferences ( Hashtable h )
218       throws TransactionFailedException 
219    {
220       try
221       {
222          if ( canLoadObject() )
223             return;
224       
225          GatewayDebugOutput.println ( 3, "Update role preferences" );
226       
227          user.updateRolePreferences ( h );
228       }
229       catch ( Throwable e )
230       {
231          throw buildException(e, "Updating Role Preferences", IDENTIFIER );
232       }
233    }
234 
235    
236    /**
237     * Gets the user data for this user.
238     * @return the user's user data.
239     * @throws TransactionFailedException Throws if this transaction fails.
240     */
241    public UserData getUserData ( )
242       throws TransactionFailedException 
243    {
244       try
245       {
246          GatewayDebugOutput.println ( 3, "Get user data" );
247       
248          if ( canLoadObject() )
249             return (UserData)retrieveObject ( "User_getUser" );
250             
251          UserData data = user.getUser();
252 
253          if ( canSaveObject() )
254             storeObject ( "User_getUser", data );
255             
256          return data;
257       }
258       catch ( Throwable e )
259       {
260          throw buildException(e, "Getting User Data", IDENTIFIER );
261       }
262    }
263 
264 
265    /**
266     * Updates the user data for this user.
267     * @param data the user's user data.
268     * @throws TransactionFailedException Throws if this transaction fails.
269     */
270    public void updateUserData ( UserData data )
271       throws TransactionFailedException 
272    {
273       try
274       {
275          if ( canLoadObject() )
276             return;
277       
278          GatewayDebugOutput.println ( 3, "Update user data" );
279       
280          user.update ( data );
281       }
282       catch ( Throwable e )
283       {
284          throw buildException(e, "Updating User Data", IDENTIFIER );
285       }
286    }
287    
288    /**
289     * Returns a list of disguises for this user.
290     * @return a list of disguises.
291     * @throws TransactionFailedException Throws if this transaction fails.
292     */
293    public Hashtable getDisguiseList ( )
294       throws TransactionFailedException 
295    {
296       try
297       {
298          GatewayDebugOutput.println ( 3, "Get user disguise list" );
299       
300          if ( canLoadObject() )
301             return (Hashtable)retrieveObject ( "User_getDisguises" );
302             
303          Hashtable h = user.getDisguises();
304          
305          if ( canSaveObject() )
306             storeObject ( "User_getDisguises", h );
307             
308          return h;
309       }
310       catch ( Throwable e )
311       {
312          throw buildException(e, "Getting Disguise List", IDENTIFIER );
313       }
314    }
315 
316 
317    /**
318     * Returns a list of saved searches for this user.
319     * @return a list of seved searches.
320     * @throws TransactionFailedException Throws if this transaction fails.
321     */
322 /*   public Vector getSavedSearchList ( )
323       throws TransactionFailedException 
324    {
325       try
326       {
327          GatewayDebugOutput.println ( 3, "Get user saved search list" );
328       
329          if ( canLoadObject() )
330             return (Vector)retrieveObject ( "User_getSavedSearches" );
331             
332          Vector v = user.getSavedSearches();
333          
334          if ( canSaveObject() )
335             storeObject ( "User_getSavedSearches", v );
336             
337          return v;
338       }
339       catch ( Throwable e )
340       {
341          throw buildException(e, "Getting Saved Search List", IDENTIFIER );
342       }
343    }
344 */
345 }