Thursday, May 31, 2012

Logout from an ADF application

ADF Security configures an authentication servlet, AuthenticationServlet, in the web.xml file that also provides a logout functionality. You can logout by executing the following action method:
public String onLogout() {
    FacesContext fctx = FacesContext.getCurrentInstance();
    ExternalContext ectx = fctx.getExternalContext();
    String url = ectx.getRequestContextPath() + "/adfAuthentication?logout=true&end_url=/faces/Home.jspx";
    try {
        ectx.redirect(url);
    } catch (IOException e) {
    e.printStackTrace(); }
    fctx.responseComplete();
    return null;
}

To use this functionality in your application, you have to change the Home.jspx reference to a public page of yours that the user is redirected to after successful logout.