6

I am using OpenId4Java with JSF application i have added Security Constraints in my web.xml something like this..

<security-constraint>
     <web-resource-collection>
       <web-resource-name>Restricted</web-resource-name>
       <url-pattern>/core/*</url-pattern>
       <http-method>GET</http-method>
       <http-method>POST</http-method>
     </web-resource-collection>
</security-constraint>
<login-config>
  <auth-method>FORM</auth-method>
  <form-login-config>
    <form-login-page>/user/login.xhtml</form-login-page>
    <form-error-page>/user/logout.xhtml</form-error-page>
  </form-login-config>
</login-config>

Now when application start and user want to access the

http://www.somehost:8080/myapp/core/abc.xhtml

with the help of web.xml i am able to show user a login page now here i put login with openid like Google,Yahoo now my question is that how can i tell openid that my return url is

http://www.somehost:8080/myapp/core/abc.xhtml

Or if user coming from

http://www.somehost:8080/myapp/core/xyz.xhtml

this url then after successful login user will go this page.

Giovani Guizzo
  • 527
  • 3
  • 13
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202

2 Answers2

0

In order to get the original url that the user tried to access, please try using the variable RequestDispatcher.FORWARD_REQUEST_URI.

This variable will be available only if you are redirected to login page from some other restricted page. And so, please remember to have some default url, in case the user directly hits the login page.

As rrufai pointed out, once the original url that the user requested for is available, you can follow the steps mentioned in this article to redirect to that url, when authentication is complete.

Ajmal Ahammed
  • 145
  • 1
  • 11
  • But i am using web.xml security-context tag and in each pages if user not login i web.xml showing login.xhtml page – Subodh Joshi Mar 18 '13 at 11:20
  • Since you are using JSF, can you try using the [RequestDispatcher.FORWARD_REQUEST_URI](http://docs.oracle.com/javaee/6/api/javax/servlet/RequestDispatcher.html#FORWARD_REQUEST_URI), as the login page is opened by a server-side forward? This variable will be available only if you are redirected to login page from some other restricted page. And so, please remember to have some default url, in case the user directly hits the login page. – Ajmal Ahammed Mar 18 '13 at 12:31
  • Still it is giving me the url of logix.xhtml page – Subodh Joshi Mar 19 '13 at 11:53
0

Use redirect to forward control on next page.

String returnToUrl = returnToUrl("/nextPage.xhtml");
FacesContext.getCurrentInstance().getExternalContext().dispatch(returnToUrl);

Have a look at this:

http://blog.enterpriselab.ch/tdmarti/2011/04/06/openid-in-a-web-application-based-on-java-ee-and-jsf-2-0/

Update:

To identify that from which page request was made please refer to these posts:

How to get the previous page URL from request in servlet after dispatcher.forward(request, response)

How to get the original request url from a servlet/jsp after multiple servlet forwards

http://www.coderanch.com/t/361942/Servlets/java/Track-Jsp-request-coming-Servlet

Community
  • 1
  • 1
Ravi Sharma
  • 873
  • 7
  • 24
  • thats the issue How i will get from which page user come because when ever user click on a link i am showing him a login.xhtml – Subodh Joshi Mar 19 '13 at 18:06
  • For that you can pass a parameter with request to identify that from which page request was made and based on that you can redirect to same page or to a different one. Please check the updated answer. – Ravi Sharma Mar 20 '13 at 07:52
  • Can it possible for you give me any demo code for this..as i did same but its telling me i am in login.xhtml page – Subodh Joshi Mar 20 '13 at 08:43
  • You can pass parameter as this sample: http://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ – Ravi Sharma Mar 20 '13 at 09:00
  • i am totally agree with you but issue is that its a Menu Item Second thing if i will pass parameter everywhere its too complicated in future as i am using preetyfaces as well so i am doing Url rewriting it will create issue in near future – Subodh Joshi Mar 20 '13 at 09:21
  • Try passing `page.xhtml?param=pageName` – Ravi Sharma Mar 20 '13 at 09:32