You are here

Get the current username from within a portlet

It often happens that you need to know the username from the user who has logged in into the portal. The JSR 168 and 286 standard dictates that the portal should pass this information to the portlet.
This snippet will show you how you can get the username:

Snippet: 
If you are creating portlets with the ADF Portlet bridge you can use the ADFContext:
  1. String user =
  2.     ADFContext.getCurrent().getSecurityContext().getUserName();
Otherwhise, you can get it from the PortletRequest:
  1.     FacesContext ctx = FacesContext.getCurrentInstance();
  2.     PortletRequest req =
  3.         (PortletRequest)ctx.getExternalContext().getRequest();
  4.     String user = req.getRemoteUser();
Applies to: 

Comments

From the portal application I have to get the logged in user and use the same user to filter the records in Portlet. I have to execute a view Criteria in portlet as a default method activity which takes logged in user as a input param.

Is this achievable? Please let me know.
Thanks,
Shiva.

It's possible but the explenation is quite large. Can you post this on the webcenter forum on otn so i can answer it there? It0s much better to ask such question there.

Hi Yannick,
I have posted the question on webcenter forum. the below is the thread id.

https://forums.oracle.com/forums/thread.jspa?threadID=2272975&tstart=0

Thanks,

Hello!

Is there any way to pass a user parameter in an OmniPortlet's SQL statement?

I have am omniportlet that sends a SQL statement and gets back data. It works. But I am trying to figure out how to pass a user parameter such as UserName.

Thanks!

The omniportlet is not a JSR 168 or 286 portlet. Instead it is an Oracle PDK portlet which means that it's using different API's.

In you case I would recommend passing the username as a parameter to the omniportlet. While creating your query, you can then bind them to the username i nthe portal.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer