5

Is that possible to retrieve the user's requested URL before the JAAS redirect it?

my web.xml is like this:

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.jsf</form-login-page>
        <form-error-page>/login.jsf</form-error-page>
    </form-login-config>
</login-config>

So, when I'm not logged and try to go at ex. www.blah.com/myApp/users.jsf then the app redirect me to login.jsf but the url still the same that the user requested.

then I fill the login form and click Login, that goes to my backbean where a call my loginModule and callbackHandler ex.:

public String actionLogin(){
   //do my login and stuff
   return "page that user requested";
}

I tried many ways to get the user's requested page. request.getRequestURL()

all returned me : www.blah.com/myApp/login.jsf

any way to get the requested page? www.blah.com/myApp/users.jsf

regards

Tiny
  • 27,221
  • 105
  • 339
  • 599
Rafael Mule'
  • 53
  • 1
  • 5

1 Answers1

2

The login page is internally opened by a server-side forward by RequestDispatcher#forward(). This thus means that the initially requested page is available as a request attribute with the name as specified in RequestDispatcher.FORWARD_REQUEST_URI constant. In JSF terms, that's thus available as follows:

String originalURI = (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI);
String originalQuery = (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_QUERY_STRING);

if (originalQuery != null) {
    originalURI+= "?" + originalQuery;
}

(keep in mind to have a fallback URL for the case it returns null, i.e. when it's been opened directly without hitting a restricted URL first)

The best place to collect it would be the (post)constructor of a @ViewScoped bean associated with the login page.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Perfectly , but some pages I have escop.jsf?value=some-thing possible to gel all url plus params ? – Rafael Mule' Dec 19 '12 at 18:05
  • 1
    They're available by `FORWARD_QUERY_STRING` constant. See updated answer. – BalusC Dec 19 '12 at 18:09
  • More than perfect!!!! I apreciate you pacience and your goodwill. here in my departament you won a lot of fans! thanks a lot and i wish you a great xmas and happy new year! greating from Rio de Janeiro - Brazil – Rafael Mule' Dec 19 '12 at 18:16