Go to the external url from the bean backup?

I am trying to implement the correct output for my Java EE / JSF2 application.

This requires two things:

  • I need to exit JAAS and cancel the session
  • Then I have to go to the external URL in order to start logging out of Siteminder

The Siteminder exit URL (configured on the policy server -> I cannot change it) is out of my application context. For instance. if my webapp url is https: // localhost: 8080 / sm / MyWebApp , then the exit URL is https: // localhost: 8080 / anotherwebapp / logout.html .

This is the current local exit 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(); } } 

And here is the property that returns the exit 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; } 

However, I cannot find the JSF2 / Primefaces component that can call logout () and then open the external URL. For example, if I have:

 <h:outputLink value="#{authBean.logoutUrl}" onclick="#{authBean.logout()}">[Logout]</h:outputLink> 

then onclick does not seem to be called.

Another way I tried is to put the external URL at the end of the exit function so that it returns as a navigation bar, but it is not recognized (also used with "? Faces-redirect = true ...)."

Any help would be appreciated.

+4
source share
2 answers

You can create a logout.xhtml page, so the code will look like this:

 public String getLogoutUrl() { return "/logout.jsf"; } 

and on the add page:

 <META HTTP-EQUIV="Refresh" CONTENT="0;URL=https://localhost:8080/anotherwebapp/logout.html"> 
+3
source

You can also just use ExternalContext#redirect() .

 public void logout() throws ServletException, IOException { ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); ((HttpServletRequest) ec.getRequest()).logout(); ec.invalidateSession(); ec.redirect("http://example.com/anothercontext/logout"); } 

There is no need for an intermediate meta refresh page.

+13
source

Source: https://habr.com/ru/post/1316394/


All Articles