cancel
Showing results for 
Search instead for 
Did you mean: 

Getting current username

Former Member
0 Kudos

Hi,

How can i get username currently log in portal?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello

Use the following piece of code to get the logged in user name


try 
{
    IWDClientUser clientUser = WDClientUser.getCurrentUser()
} 
catch (WDUMException e)
{
    // do exception handling
}

Do try searching the forum before posting questions, this question has been asked and answered way too many times.

Thanks,

GLM

Former Member
0 Kudos

Hi,

When i use code below,it gets string like c2048452902111dec429001fd0a72672

But it need to get user-id?

IWDClientUser clientUser = WDClientUser.getCurrentUser();

String user = clientUser.getClientUserID();

Thanks.

Former Member
0 Kudos

Hello Cemil,

Do refer this link - https://wiki.sdn.sap.com/wiki/display/Snippets/GettingLoggedinPortalUserDetailsinWebDynPro

It has all the needed code to get the current logged in user

Snippet from the said link


Description This code will help one to get the current logged in Portal User through Web DynPro application 

These are the imports to be used

import com.sap.security.api.IUser;
import com.sap.security.api.IUserAccount;
import com.sap.security.api.UMException;
import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;
import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;
import com.sap.tc.webdynpro.services.sal.um.api.WDUMException;

String strUserName = null;
try {
      IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
      IUser sapUser = wdClientUser.getSAPUser();
      if (sapUser != null) {
            IUserAccount[] acct = sapUser.getUserAccounts();
            if (acct[0] != null) {
                  strUserName = acct[0].getDisplayName();
            }
      }
} catch (WDUMException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
} catch (UMException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
}

Thanks,

GLM

former_member197348
Active Contributor
0 Kudos

Hi Cemil Bozlagan,

	String userName = "";
		
		try
		{
			IUser user= WDClientUser.getCurrentUser().getSAPUser();
		}
		catch (WDUMException e)
		{
			wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(), false);
		}
		
		userName = user.getUniqueName();
// we have different  methods here like getDisplayName(), getUniqueID() etc.

Regards,

Siva

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Use this code,

IWDClientUser wdUser = WDClientUser.getCurrentUser();

IUser user = wdUser.getSAPUser();

Note: Defining the IUser will show an error. To resolve this, within the properties of

the project, choose Java build path -> Libraries -> Add external jars ->

com.sap.securities -> lib -> com.sap.security.api.

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi Cemil Bozlagan,

Use the code to get current user logged in

try

{

IUser user= WDClientUser.getCurrentUser().getSAPUser();

String name=user.getUniqueName();

}

catch (WDUMException e)

{

}

U need to add com.sap.security.api.jar file to the project.

Regards,

srikanth

Former Member
0 Kudos

Try the following code to get vurrently logged in user on portal :

IWDClientUser l_ClntUser = WDClientUser.getCurrentUser();

IUser l_IUser = l_ClntUser.getSAPUser();

IUserAccount[] l_IUA = l_IUser.getUserAccounts();

String uniqName = l_IUA[0].getLogonUid();

If the logged-in user is a URL parameter then try the following :

Eg: to extract the parameter "User" from the URL

String LogginUser = WDProtocolAdapter.getProtocolAdapter().getRequestObject().getParameter("User");

Also check this thread...

Thanks

Avik

Edited by: AVIK SANYAL on Aug 24, 2009 6:49 AM