| Author |
I want the user id with which i have logged in
|
|
|
| I am using JSR 168 portlet.suppose i have logged in to the portal page with userid "123",i need to get that userid in the portlets.
i am using the code request.getRemoteUser(). But it is giving me some id that is not the id with which i have logged in.I think it is an unique id generated by the portal server.
| |
| WartookMan 2006-12-06, 7:26 pm |
| Try:
User portalUser = portletRequest.getUser();
If you need a Principal object then try:
if(portalUser != null && portalUser instanceof java.security.Principal)
Principal p = (java.security.Principal)portalUser;
You can then use the method getName() to get the current user's name... funny enough. 
Pete.
---------------------------------------------------
Freelance IBM WCM (Java/Domino) / Portal Consultant
w: http://www.lwwcm.com
w: http://www.lwwcm.com/discussion
aim: WartookMan
Looking for a holiday: http://www.grampiansnationalpark.com
| |
|
| When i am using
User portalUser = portletRequest.getUser();
it is giving that portletRequest can not be resolved.
Actually i am using JSR168 portlet.Please help as soon as possible.Shall i have to include any jar file.
| |
| WartookMan 2006-12-07, 7:39 pm |
| Ok, so you should have something like:
public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
RenderRequest request has a super class of PortletRequest, which means you should be able to use the method getUserPrincipal().
Have you tried:
String user = request.getUserPrincipal().getName();
Pete.
---------------------------------------------------
Freelance IBM WCM (Java/Domino) / Portal Consultant
w: http://www.lwwcm.com
w: http://www.lwwcm.com/discussion
aim: WartookMan
Looking for a holiday: http://www.grampiansnationalpark.com
| |
|
| I tried the code:
String user=request.getUserPrincipal.getName()
but it is giving null pointer exception
| |
| Mahmoud Matouk 2006-12-10, 7:26 am |
| Hi,
getRemoteUser() will work and return the user id only if you have securoty enabled, I think you are testing on your own local test env so it returns a fake ID, but of your production server will have seurity enabled then use it and don't worry.
Another way to get the user ID (it will always work even if security is of, but not recommended)is to use this code.
User user = (User) request.getAttribute("com.ibm.portal.puma.request-user");
String uid = user.getUserID();
you will need to add wp.user.api.jar to your class path to compile your code, which is located under portal/shared/app
good luck
|
|
|
|