Saturday 7 March 2015

ADF: Retrive logged in user's userID in the Managed Bean in a ADF Web Application

This post will describe how to derive userId from the database when we use SQLAuthenticator/ReadOnlySQLAuthenticator for authentication in a Fusion Web Application. 

Some example scenarios which you need to use this are:
  1. Your application tables has a userId column (created_by/last_updated_by) which you want to populate with the userId of the loggedIn Person.
  2. You want to display the Person Name, instead of the username in the main page
  • Create a Query based ViewObject to retrieve the userID.

  • Add a viewCriteria for the newly created ViewObject.
  • Add this ViewObject to the AM.
  • Write a method in the AM to accept the userName and return the userID by executing the ViewCriteria.
  • Expose this AM method in the Client Interface.

  • Now add this service as a methodAction binding to your Login PageDefinition. Map the parameter value to the userName in the LoginBean. #{loginBean.userName}



  • Now you can access this method inside your doLogin() method in your LoginBean and get the userID (or any other user related Information).
  • Now lets run this.
  • You can see the userId is getting printed from the LoginBean




You can store this in session/userData and use that for populating the userID columns (created_by/last_updated_by) in the Entity Objects. You can modify this code and get the DisplayName instead of userID, if you want to display it in the logged in screens.


Script to create tables and step by step information to configure ReadOnlySQLAuthenticator is available here. This is created based on Edwin's blog Using database tables as authentication provider in WebLogic.

Sample application built using Jdev 12.1.3 can be downloaded from here

To run the attached application, you might need to do 2 things:


  1. Configure the SQLAuthenticator/ReadOnlyAuthenticator based on the Edwin's blog or the attached doc below.
  2. Modify the UsersVO query based on your table. [I have used the same tables as mentioned in Edwin's blog with ReadOnlySQLAuthenticator].

To store any Global User Information across multiple AM, you can refer to Andrejus blog  Solution for Sharing Global User Data in ADF BC.

Feel free to point out if anything is missing/wrong in this blog.

No comments:

Post a Comment