Logout With ADF Security - Say no to 404 errors

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();
       } 

Comments:

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

Posted by guest on May 11, 2011 at 01:50 PM BST #

Post a Comment:
Comments are closed for this entry.
About

Hawaii, Yes! Duncan has been around Oracle technology way too long but occasionally has interesting things to say. He works in the Development Tools Division at Oracle, but you guessed that right? In his spare time he contributes to the Hudson CI Server Project at Eclipse
Follow DuncanMills on Twitter

Note that comments on this blog are moderated so (1) There may be a delay before it gets published (2) I reserve the right to ignore silly questions and comment spam is not tolerated - it gets deleted so don't even bother, we all have better things to do with our lives.
However, don't be put off, I want to hear what you have to say!

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today