FileDocCategorySizeDatePackage
LoginAction_orig.javaAPI DocExample2196Tue Aug 03 10:31:00 BST 2004com.oreilly.strutsckbk.ch09

LoginAction_orig

public class LoginAction_orig extends org.apache.struts.action.Action

Fields Summary
Constructors Summary
Methods Summary
public org.apache.struts.action.ActionForwardexecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)


        String username = null;
        String password = null;
        
        ActionErrors errors = new ActionErrors();

        try {
            username = (String) PropertyUtils.getSimpleProperty(form, "username");
            password = (String) PropertyUtils.getSimpleProperty(form, "password");
        } catch (Exception e) {
            throw new IOException("Unable to retrieve username and password");
        }
        
        SecurityService service = new SecurityService();
        try {
            service.authenticate( username, password);
        } catch (UnknownUserException e1) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.unknown.user"));
            saveErrors(request, errors);
            return mapping.findForward("securityError");
        } catch (PasswordMatchException e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.password.match"));
        }        

        // Report any errors we have discovered back to the original form
        if (!errors.isEmpty()) {
            saveErrors(request, errors);
            return (mapping.getInputForward());
        }
        
        User user = new User();
        user.setUsername(username);
        request.getSession().setAttribute("user", user);

        return mapping.findForward("success");