You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by O'Reilly John <jo...@traventec.com> on 2001/07/06 18:31:40 UTC
Redirecting to login page
Hi,
I have overridden the processActionPerform method to cause the user to be
redirected to a login page if they are entering a "closed" area and have not
previously loggged in. The code below shows my initial attempt. What is
the accepted way of doing this? I assume there must be a cleaner way.
boolean isClosedArea = portalMapping.getIsClosedArea();
String userName = (String)session.getAttribute("USERNAME");
if ( isClosedArea && (userName == null || userName == "") )
{
// store requestPath so that we can use it when log in is successful
session.setAttribute("REQUEST_PATH", mapping.getPath());
return new ActionForward("/loginpage.do");
}
else
{
// If REQUEST_PATH is set, then this action was dynamically inserted
before
// original request. Make sure we redirect to original request when
// action completes.
String requestPath=(String)session.getAttribute("REQUEST_PATH");
if ( requestPath != null && requestPath != "" )
{
session.setAttribute("REQUEST_PATH", "");
super.processActionPerform(action,mapping, formInstance, request,
response);
return new RedirectingActionForward(requestPath + ".do");
}
return super.processActionPerform(action,mapping, formInstance,
request, response);
}
Thanks,
John O'Reilly
Traventec
Phone: +353 91 518786
Fax: +353 91 525056
Email: john.oreilly@traventec.com
www.traventec.com
Re: Redirecting to login page
Posted by Oleg V Alexeev <go...@penza.net>.
Hello O'Reilly,
You can check it in Action. Create base SecureAction with check of
login -
public class SecureAction extends Action {
ActionForward securePerform( ... ) {
return loginForward;
}
ActionForward perform ( ... ) {
if( check user - is logged in? ) {
return securePerform( ... );
} else {
return loginForward;
}
}
}
public class TransactionAction extends SecureAction {
ActionForward securePerform( ... ) {
// some stuff here
return nativeForward;
}
}
Friday, July 06, 2001, 8:31:40 PM, you wrote:
ORJ> Hi,
ORJ> I have overridden the processActionPerform method to cause the user to be
ORJ> redirected to a login page if they are entering a "closed" area and have not
ORJ> previously loggged in. The code below shows my initial attempt. What is
ORJ> the accepted way of doing this? I assume there must be a cleaner way.
ORJ> boolean isClosedArea = portalMapping.getIsClosedArea();
ORJ> String userName = (String)session.getAttribute("USERNAME");
ORJ> if ( isClosedArea && (userName == null || userName == "") )
ORJ> {
ORJ> // store requestPath so that we can use it when log in is successful
ORJ> session.setAttribute("REQUEST_PATH", mapping.getPath());
ORJ> return new ActionForward("/loginpage.do");
ORJ> }
ORJ> else
ORJ> {
ORJ> // If REQUEST_PATH is set, then this action was dynamically inserted
ORJ> before
ORJ> // original request. Make sure we redirect to original request when
ORJ> // action completes.
ORJ> String requestPath=(String)session.getAttribute("REQUEST_PATH");
ORJ> if ( requestPath != null && requestPath != "" )
ORJ> {
ORJ> session.setAttribute("REQUEST_PATH", "");
ORJ> super.processActionPerform(action,mapping, formInstance, request,
ORJ> response);
ORJ> return new RedirectingActionForward(requestPath + ".do");
ORJ> }
ORJ> return super.processActionPerform(action,mapping, formInstance,
ORJ> request, response);
ORJ> }
ORJ> Thanks,
ORJ> John O'Reilly
ORJ> Traventec
ORJ> Phone: +353 91 518786
ORJ> Fax: +353 91 525056
ORJ> Email: john.oreilly@traventec.com
ORJ> www.traventec.com
--
Best regards,
Oleg mailto:gonza@penza.net