What I do is:

within a group of servlets, with each request they check to see if that the
user is validated.  If they aren't, it still instantiates the session object
(in my case, a PassCard) which holds a redirection url and then redirects
the user to the security servlet.  If the login is valid, it sends then
checks to see if the passcard has a valid redirect..

// The sevice requested first checks to see if the user is approved

HttpSession session = req.getSession(true);
PassCard passCard = (PassCard)session.getValue("neo.passcard");

if ( (passCard == null) || (! passCard.isApproved()) )
{
  passCard = new PassCard();
  passCard.setLoginRedirect(the url for this service);
  passCard.updateCard("neo.passcard",session);
  res.sendRedirect(to security servlet);
}

// if not, they're forwarded to the security manager which processes their
login.  If the manager approves them, it checks for a loginRedirect...

if (passc.isApproved())
{
  if (passc.getLoginRedirect() != null)
  {
   res.sendRedirect( passc.getLoginRedirect() );
   passc.setLoginRedirect( null );
  }
}


Anyways, I've snipped a lot of code from the original.  But that's the gist
of it.

Cheers.

-mark



-----Original Message-----
From: Brian Moynihan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 04, 2000 6:42 AM
To: [EMAIL PROTECTED]
Subject: Saving URL's for redirection


Hi All,

I need some help with this problem.

1. I want to click on a hyperlink, and redirect that page to a Security
Servlet, which verifies if the user is logged in or not. This piece is done.

2. Within the security servlet, I want to save the original url of the
hyperlink, and if the user is verified, redirect to that url.

So far this is the code I have from the servlet:

*******************************************************************

  // DOES THE SESSION INDICATE THIS USER IS ALREADY LOGGED IN?
  Object loggedIn = session.getValue("logon.isDone"); // MARKER OBJECT

  if (loggedIn == null)
  {
    // NO logon.isDone, THIS USER IS NOT LOGGED IN
    // SAVE THE REQUEST URL AS THE TRUE TARGET AND REDIRECT TO THE LOGIN
PAGE
    session.putValue("OriginalTarget",
HttpUtils.getRequestURL(req).toString());
    res.sendRedirect(req.getScheme() + "://" + req.getServerName() + ":" +
req.getServerPort() + "/Login.html");
    return;
  }
  else
  {
    // Try redirecting the client to the page he first tried to access
    try
    {
      String target = (String)session.getValue("OriginalTarget");
      if (target != null)
        res.sendRedirect(target);
      else
        out.println("No target specified");
      return;
    }
    catch (Exception ignored) { }
  }

*******************************************************************

Thanks for any help,
Brian.

P.S. GUINESS IS GOOD FOR YOU :)


Get your FREE Email at http://mailcity.lycos.com
Get your PERSONALIZED START PAGE at http://my.lycos.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to