KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > webwork > action > signon > LoginAction


1 /*
2  * Created on 24-Feb-2003
3  */

4 package xpetstore.web.webwork.action.signon;
5
6 import javax.servlet.http.HttpServletResponse JavaDoc;
7
8 import cirrus.hibernate.ObjectNotFoundException;
9 import cirrus.hibernate.Session;
10
11 import webwork.action.ServletResponseAware;
12
13 import xpetstore.domain.Customer;
14
15 import xpetstore.web.webwork.action.BaseAction;
16
17
18 /**
19  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
20  *
21  * @webwork.action
22  * name="login"
23  * success="index.action"
24  * error="signon.vm"
25  */

26 public class LoginAction
27     extends BaseAction
28     implements ServletResponseAware
29 {
30     //~ Instance fields --------------------------------------------------------
31

32     private String JavaDoc _password;
33     private HttpServletResponse JavaDoc _response;
34     private String JavaDoc _userId;
35
36     //~ Methods ----------------------------------------------------------------
37

38     /**
39      * @see webwork.action.ActionSupport#doExecute()
40      */

41     protected String JavaDoc doExecute( )
42         throws Exception JavaDoc
43     {
44         Session s = getHibernateSession( );
45
46         try
47         {
48             Customer c = ( Customer ) s.load( Customer.class, _userId );
49
50             if ( c.getAccount( ).matchPassword( _password ) )
51             {
52                 initSession( c );
53
54                 /* Redirect */
55                 if ( ( _redirectUri != null ) && ( _redirectUri.length( ) > 0 ) )
56                 {
57                     _response.sendRedirect( _redirectUri );
58                     return NONE;
59                 }
60
61                 /* Normal flow */
62                 return SUCCESS;
63             }
64             else
65             {
66                 addError( "login", getText( "authentication_failed" ) );
67                 return ERROR;
68             }
69         }
70         catch ( ObjectNotFoundException o )
71         {
72             addError( "login", getText( "authentication_failed" ) );
73
74             return ERROR;
75         }
76         finally
77         {
78             s.close( );
79         }
80     }
81
82     /**
83      * @return String
84      */

85     public String JavaDoc getPassword( )
86     {
87         return _password;
88     }
89
90     /**
91      * @return String
92      */

93     public String JavaDoc getUserId( )
94     {
95         return _userId;
96     }
97
98     /**
99      * Sets the password.
100      * @param password The password to set
101      */

102     public void setPassword( String JavaDoc password )
103     {
104         _password = password;
105     }
106
107     /**
108      * @see webwork.action.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
109      */

110     public void setServletResponse( HttpServletResponse JavaDoc response )
111     {
112         _response = response;
113     }
114
115     /**
116      * Sets the login.
117      * @param login The login to set
118      */

119     public void setUserId( String JavaDoc login )
120     {
121         _userId = login;
122     }
123 }
124
Popular Tags