1   package ch.ige.edossier.web.struts;
2   
3   import javax.servlet.http.HttpServletRequest;
4   import javax.servlet.http.HttpServletResponse;
5   import javax.servlet.http.HttpSession;
6   import org.apache.log4j.Logger;
7   import org.apache.struts.action.*;
8   import ch.ige.edossier.web.server.EDossierControl;
9   import ch.ige.edossier.web.vo.AccountVO;
10  import ch.ige.edossier.web.vo.DossierOverviewVO;
11  
12  /**
13   * B32.03 - eDossier-Interceptions - Diplomarbeit an der Software-Schule Schweiz<br>
14   * MUSS-ZIEL [M1] - Login Authentifizierung (Pflichtenheft b32.03_PF_eDossier.pdf, Seite 16)<br>
15   * MUSS-ZIEL [M3] - Ansicht Dossier (Pflichtenheft Seite 16)<br>
16   * KANN-ZIEL [K3] - Beanstandungen Status (Pflichtenheft b32.03_PF_eDossier.pdf, Seite 17)<br>
17   * KANN-ZIEL [K5] - Passwort vergessen (Pflichtenheft b32.03_PF_eDossier.pdf, Seite 17)<br>
18   * Die Klasse LoginAction verarbeitet die Daten der LoginForm.
19   * <p>
20   * Copyright (c) 2004, Eidgenössisches Institut für Geistiges Eigentum
21   * @author    Anita Rueegsegger, Marc Bouquet
22   * @version   $Id: LoginAction.java,v 1.14 2004/10/22 01:58:23 bouquet Exp $
23   */
24  public class LoginAction extends Action
25  {
26    // Attribute für Log4j-Logging
27    private static final Logger LOG = Logger.getLogger( LoginAction.class );
28  
29    /**
30     * Die Methode execute wird aufgerufen, wenn auf der JavaServerPage der Button "Login" gedrückt wird.
31     * Durch die Methode wird der Benutzername und das Passwort geprüft. Ist der Prüfvorgang erfolgreich
32     * wird der Benutzer in den geschützen Bereich weiter geleitet.
33     * @param actionMapping ActionMapping
34     * @param actionForm ActionForm
35     * @param httpServletRequest HttpServletRequest
36     * @param httpServletResponse HttpServletResponse
37     * @return ActionForward
38     */
39    public ActionForward execute( ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse )
40    {
41      ActionErrors errors = new ActionErrors();
42      HttpSession session = httpServletRequest.getSession();
43      LoginForm loginForm = ( LoginForm )actionForm;
44  
45      EDossierFacade eFacade = new EDossierControl();
46      AccountVO accountVO = new AccountVO();
47  
48      try
49      {
50        accountVO.setEmail( loginForm.getTxfEmail() );
51        accountVO.setPwd( loginForm.getTxfPW() );
52        accountVO = eFacade.checkPassword( accountVO );
53  
54        if( accountVO != null )
55        {
56          if( accountVO.getIsPwd() )
57          {
58            session.setAttribute( "accountVO", accountVO );
59            DossierOverviewVO dossierOverviewVO = eFacade.getDossiers( accountVO.getAccountId() );
60            session.setAttribute( "dossierOverviewVO", dossierOverviewVO );
61  
62            // Es wird für die erstellte Session ein Gültigkeits-Flag gesetzt.
63            session.setAttribute( "token", new Boolean( true ) );
64            loginForm.reset( actionMapping, httpServletRequest );
65            return( actionMapping.findForward( "forward" ) );
66          }
67          else
68          {
69            errors.add( "accountVO", new ActionError( "error.login.pwd" ) );
70            saveErrors( httpServletRequest, errors );
71            return( actionMapping.findForward( "self" ) );
72          }
73        }
74        else
75        {
76          errors.add( "accountVO", new ActionError( "error.login.account" ) );
77          saveErrors( httpServletRequest, errors );
78          return( actionMapping.findForward( "self" ) );
79        }
80      }
81      catch( Exception ex )
82      {
83        LOG.error( "Error: " + ex.getMessage() );
84        errors.add( "accountVO", new ActionError( "error.login.account", ex.getMessage() ) );
85        saveErrors( httpServletRequest, errors );
86        return( new ActionForward( actionMapping.getInput() ) );
87      }
88    }
89  }
90