I want the user id with which i have logged in - Websphere

This is a discussion on I want the user id with which i have logged in - Websphere ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: I want the user id with which i have logged in

  1. 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.

  2. Re: I want the user id with which i have logged in

    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

  3. Re: I want the user id with which i have logged in

    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.

  4. Re: I want the user id with which i have logged in

    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

  5. Re: I want the user id with which i have logged in

    I tried the code:

    String user=request.getUserPrincipal.getName()

    but it is giving null pointer exception

  6. Re: I want the user id with which i have logged in

    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

+ Reply to Thread