X

Technical Articles relating to Oracle Development Tools and Frameworks

  • ADF
    May 10, 2011

Logout With ADF Security - Say no to 404 errors

Duncan Mills
Architect

This is one of those topics which seems to have plenty of coverage in the blog-sphere (and on the OTN forums) but I couldn't locate an existing post that showed the exact code that you would need. 

The issue here is  although the Fusion Developers guide (Chapter 30) covers the code for programmatic login from Java it does not do the same for logout, and just shows a technique for defining a "Go Link" to do the logout to a hard-coded location. 

There are certainly circumstances where you will want a bit more flexibility than this, for example you want to make the logout destination variable in some way.

So naturally you would take a look at the code for the <af:goLink ...> defined in the doc and replicate that  by doing a simple forward or redirect to  the ADF Authenication servlet (/adfAuthentication) with the relevant logout and end_url parameters. However, doing this will result in 404 not found errors on logout. 

The correct code is very simple you just have to remember to add the application context root as a prefix:

  ExternalContext ectx = 
FacesContext.getCurrentInstance().getExternalContext();
  // Obtain the Application context root
  StringBuilder logoutURL =
 new StringBuilder(ectx.getRequestContextPath());
  //Add the fixed reference to the ADF Security servlet
  logoutURL.append("/adfAuthentication?logout=true&end_url=");
  //And your final destination goes here
//In this case a hardcoded view activity but this bit would be variable

  logoutURL.append("/faces/homepage");
  // And do the redirect
  try {
       ectx.redirect(logoutURL.toString());
       } catch (IOException e) {
          logger.warning("Problem logging off");
          // And add further diagnostics of your choice
          e.printStackTrace();
       } 

Join the discussion

Comments ( 1 )
  • guest Wednesday, May 11, 2011
    hi Duncan
    Maybe you can make a suggestion for the logout related question in the forum thread "login after logout not possible using af:commandButton"
    at http://forums.oracle.com/forums/thread.jspa?threadID=2209096
    many thanks
    Jan Vervecken
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.