struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heligon Sandra <Sandra.Heli...@nextream.fr>
Subject RE: Login process
Date Fri, 05 Jul 2002 13:19:15 GMT
I agree and I do similar things in the processPreprocess() method of the
RequestProcessor.
In your case, you don't have my problem because the solution consists in
not extending logon action with the AuthenticatedAction.
Do you must conclude that the processPreprocess() method of the
RequestProcessor
doesn't allow to do authentication test ?
 

-----Original Message-----
From: David Mulligan [mailto:david.mulligan@LECAN.ie]
Sent: 05 July 2002 15:15
To: 'Struts Users Mailing List'
Subject: RE: Login process


-----Original Message-----
From: Heligon Sandra [mailto:Sandra.Heligon@nextream.fr]
Sent: Friday, July 05, 2002 1:52 PM
To: 'Struts Users Mailing List'
Subject: RE: Login process


I prefer 
- create a ActionBase class with a method IsLogin() and all Action classes
of my application
  have to sub-class this class.
- or second solution subclass RequestProcessor class, and do
  login process in the processPreprocess() method. 





How about something like the below?

public abstract class AuthenticatedAction extends
org.apache.struts.action.Action {
  /** A bean that will contain information about the requests autenticated
users. */
  private UserBean user;
  /**
   * Check to see if a user is logged in.
   * If a user is logged in then <code>performAuthenticated</code> method
   * will be called, otherwise the logon page will be displayed.
   * This method is set to final so that is can't be overriden by any
subclass.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param actionForm The optional ActionForm bean for this request (if
any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   *
   * @exception IOException if an input/output error occurs
   * @exception ServletException if a servlet exception occurs
   */
  public final ActionForward perform(ActionMapping mapping,
                                     ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
IOException, ServletException {
    HttpSession session = request.getSession();
    this.user = (UserBean)session.getAttribute(Constants.USER_KEY);

    if( this.user == null ) { //The user is not logged in, so display the
logon page.
      System.out.println("User is not logged in");
      return mapping.findForward(Constants.FORWARD_LOGON);
    } else {
      ActionForward forward = performAutenticated(mapping, form, request,
response);
      session.setAttribute(Constants.USER_KEY, this.user);
      return forward;
    }
  }

  /**
   * Perfrom an autenticated action for a request.
   * This method will be called if an only if the request has already been
autenticated.
   * i.e. The use has logged onto the system and has a session.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param actionForm The optional ActionForm bean for this request (if
any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   *
   * @exception IOException if an input/output error occurs
   * @exception ServletException if a servlet exception occurs
   *
   */
  public abstract ActionForward performAutenticated(ActionMapping mapping,
                                                    ActionForm form,
                                                    HttpServletRequest
request,
                                                    HttpServletResponse
response) throws IOException, ServletException;
  /**
   * The current users <code>UserBean</code>.
   * Get the user that is logged in for the current request.
   * @return user - The <code>UserBean</code> of the user that has been
autenticated for this request.
   */
  protected UserBean getUser() {
  	return user;
  	}
}



All actions that need the user to be logged in extend the above 
class and provide an implemation of performAutenticated() method

All sub-classes can call the getUser() method which will return the current
user.

Obviously, the logon action WILL NOT extend this class!

Dave.

--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message