1 package xpetstore.web.struts.action.signon; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 6 import org.apache.struts.action.ActionForm; 7 import org.apache.struts.action.ActionForward; 8 import org.apache.struts.action.ActionMapping; 9 10 import xpetstore.domain.customer.ejb.Customer; 11 import xpetstore.domain.signon.ejb.Account; 12 13 import xpetstore.services.petstore.ejb.Petstore; 14 15 import xpetstore.web.struts.action.BaseAction; 16 17 18 36 public class LoginAction 37 extends BaseAction 38 { 39 41 public ActionForward doExecute( ActionMapping mapping, 42 ActionForm form, 43 HttpServletRequest request, 44 HttpServletResponse response ) 45 throws Exception 46 { 47 SignonForm frm = ( SignonForm ) form; 48 Account account = frm.getAccount( ); 49 String redirectUri = frm.getRedirectUri( ); 50 Petstore petstore = getPetstore( ); 51 52 if ( petstore.authenticate( account.getUserId( ), account.getPassword( ) ) ) 53 { 54 Customer cust = petstore.getCustomer( account.getUserId( ) ); 55 initSession( cust, request ); 56 57 if ( ( redirectUri == null ) || ( redirectUri.length( ) == 0 ) ) 58 { 59 return mapping.findForward( SUCCESS ); 60 } 61 else 62 { 63 _log.info( "...redirecting to: " + redirectUri ); 64 response.sendRedirect( redirectUri ); 65 return null; 66 } 67 } 68 else 69 { 70 request.setAttribute( MESSAGE_KEY, getString( "authentication_failed" ) ); 71 72 return mapping.findForward( ERROR ); 73 } 74 } 75 } 76 | Popular Tags |