从支持bean导航到外部URL? [英] Navigate to external URL from a backing bean?
问题描述
我正在尝试为我的Java EE/JSF2应用程序实现正确的注销.
I'm trying to implement proper logout for my Java EE / JSF2 application.
它需要两件事:
- 我需要从JAAS中注销,并使会话无效
- 然后我必须导航到一个外部URL来触发Siteminder注销
Siteminder注销URL(在策略服务器上配置->我无法更改)在我的应用程序上下文之外.例如.如果我的Web应用程序URL为 https://localhost:8080/sm/MyWebApp ,则注销URL为 https://localhost:8080/anotherwebapp/logout.html .
The Siteminder logout URL (configured on the Policy server -> I cannot change it) is outside my applications context. Eg. if my webapp URL is https://localhost:8080/sm/MyWebApp then the logout URL is https://localhost:8080/anotherwebapp/logout.html.
这是当前的本地注销代码:
This is the current local logout code:
public void logout() {
System.out.println("Logging out...");
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
try {
request.logout();
} catch (ServletException e) {
e.printStackTrace();
}
HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
if (session != null) {
session.invalidate();
}
}
这是产生注销URL的属性:
And here is the property that produces the logout URL:
public String getLogoutUrl() {
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String requestServer = request.getServerName();
String requestScheme = request.getScheme();
int serverPort = request.getServerPort();
String logoutUrl = requestScheme + "://" + requestServer + ":" + Integer.toString(serverPort) + "/anotherwebapp/logout.html";
return logoutUrl;
}
但是,我找不到可以调用logout()然后打开外部URL的JSF2/Primefaces组件.例如,如果我有:
However, I cannot find a JSF2 / Primefaces component that can call logout() then open the external URL. For example, if I have:
<h:outputLink value="#{authBean.logoutUrl}" onclick="#{authBean.logout()}">[Logout]</h:outputLink>
然后似乎未调用onclick.
then onclick does not seem to be called.
我尝试的另一种方法是将外部URL放在注销函数的末尾,以使其作为导航字符串返回,但无法识别(也尝试使用?faces-redirect = true" ...).
Another way I tried was putting the external URL to the end of the logout function to have it returned as a navigation string but it is not recognized (also tried with "?faces-redirect=true"...).
任何帮助将不胜感激.
推荐答案
您可以创建页面logout.xhtml,因此代码如下所示:
You can create a page logout.xhtml, so the code will look like this:
public String getLogoutUrl() {
return "/logout.jsf";
}
,然后在页面中添加:
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=https://localhost:8080/anotherwebapp/logout.html">
这篇关于从支持bean导航到外部URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!