Friday, May 4, 2012

ADF: Programmatic Logging out


Below are the ways to programmatically logging out the user:
  • First Approach
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)fc.getExternalContext().getSession(false);
session.invalidate();

try {
   fc.getExternalContext().redirect("faces/welcome");
} catch (IOException e) {
   e.printStackTrace();
}
  • Second Approach
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
StringBuilder logoutURL = new StringBuilder(ectx.getRequestContextPath());

logoutURL.append("/adfAuthentication?logout=true&end_url=");
logoutURL.append("/faces/welcome");

try {
   ectx.redirect(logoutURL.toString());
} catch (IOException e) {
   adfLogger.warning("Error logging off");
   e.printStackTrace();
}

No comments:

Post a Comment