WebSphere Portal Server - I want the user id with which i have logged in

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > December 2006 > I want the user id with which i have logged in





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author I want the user id with which i have logged in

2006-12-06, 3:07 pm

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

2006-12-07, 1:47 am

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

2006-12-08, 1:36 am

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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com