View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.web.forms;
20  
21  import org.apache.struts.action.ActionErrors;
22  import org.apache.struts.action.ActionMapping;
23  import org.apache.struts.validator.ValidatorForm;
24  
25  import javax.servlet.http.HttpServletRequest;
26  
27  /**
28   * This is the LoginForm Struts Form. It is used by Login form.
29   *
30   * @author ready
31   */
32  public class LoginForm extends ValidatorForm {
33      /**
34       *
35       */
36      private static final long serialVersionUID = 1L;
37      private String login = null;
38      private String password = null;
39      private boolean saveLogin;
40  
41      public String getLogin() {
42          return login;
43      }
44  
45      public void setLogin(String login) {
46          this.login = login;
47      }
48  
49      public String getPassword() {
50          return password;
51      }
52  
53      public void setPassword(String password) {
54          this.password = password;
55      }
56  
57  
58      public boolean isSaveLogin() {
59          return saveLogin;
60      }
61  
62      public void setSaveLogin(boolean saveLogin) {
63          this.saveLogin = saveLogin;
64      }
65  
66      public void reset(ActionMapping mapping, HttpServletRequest request) {
67          login = null;
68          password = null;
69  
70      }
71  
72      public ActionErrors validate(ActionMapping mapping,
73                                   HttpServletRequest request) {
74          Boolean skipLogin = (Boolean) request.getSession().getAttribute(
75                  "loginForwarded");
76          if (null == skipLogin) {
77              skipLogin = false;
78          }
79          skipLogin |= (null == getLogin() && null == getPassword());
80  
81          ActionErrors errors;
82          /*
83             * SKIP credentials validation when forwarded to login.
84             */
85          if (skipLogin == null || !skipLogin.booleanValue()) {
86              // log.debug("execute: forwarded, skip login.");
87              errors = super.validate(mapping, request);
88          } else {
89              request.getSession().removeAttribute("loginForwarded");
90              return new ActionErrors();
91          }
92          return errors;
93      }
94  
95  }