OpenId + JSF将用户重定向到他登录的页面?

时间:2013-03-06 17:45:50

标签: java jsf openid web.xml

我正在使用带有JSF应用程序的OpenId4Java我在我的web.xml中添加了类似的安全约束..

<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>

现在,当应用程序启动并且用户想要访问

  

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

web.xml 的帮助下,我现在可以向用户显示一个登录页面我在这里用openid登录,像谷歌,雅虎现在我的问题是我怎么能告诉openid我的< strong>返回网址是

  

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

或者如果用户来自

  

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

此网址成功登录后,用户将转到此页面。

2 个答案:

答案 0 :(得分:0)

要获取用户尝试访问的原始网址,请尝试使用变量RequestDispatcher.FORWARD_REQUEST_URI

只有从某个其他受限页面重定向到登录页面时,此变量才可用。所以,请记住有一些默认网址,以防用户直接点击登录页面。

正如rrufai指出的那样,一旦用户请求的原始网址可用,您就可以在身份验证完成后按照this article中提到的步骤重定向到该网址。

答案 1 :(得分:0)

使用重定向转发下一页的控件。

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

看看这个:

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

<强>更新

要确定从哪个页面请求发出请参阅以下帖子:

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