cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get current user info via WDClientUser

Former Member
0 Kudos

Hi experts,

I have developed and integrated a Web Dynpro application into SAP Neteaver portal. When user logged in to portal and run the web dynpro application, the web dynpro application will get the current user info such as logon Id. I discovered the logon id was not always retrieved (is null) and it not happen all the time.

Following are my code to retrieve logon id of the current user:

String logonId = null;
IWDClientUser wdUser = WDClientUser.getLoggedInClientUser();
IUser user = wdUser.getSAPUser();
try {
     if (user!=null) {
          IUserAccount[] userAccs = user.getUserAccounts();
          if (userAccs!=null && userAccs.length > 0) {
                IUserAccount userAcc = userAccs[0]; 
                logonId = userAcc.getLogonUid();
          }
     }	
}catch (UMException ex){
}

Btw anyway know what is the different between WDClientUser.getCurrentUser() and WDClientUser.getLoggedInClientUser()?

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi ,

You can try the following for getting the current logged in user :

IWDClientUser user=WDClientUser.getCurrentUser();

//set user

String userLogged = user.toString().substring(user.toString().lastIndexOf(".")+1,user.toString().length()-1);

Hope this helps to solve you problem.

Thanks

Ritushree

Former Member
0 Kudos

Hi,

Use the below code.

//get the currently logged in user

IWDClientUser wdUser = WDClientUser.getCurrentUser();

//get the com.sap.security.api.Iuser; It is null in case wdUser represents an anonymous user

IUser user = wdUser.getSAPUser();

//check whether the user is anonymous

if (user != null)

{

//access logon ID by iterating through the IUserAccount array

IUserAccount[] acct = user.getUserAccounts();

if(acct[0] != null)

{

String strUserid = acct[0].getLogonUid();

//CHANGE strUserid TO uppercase USING toUppercase() and bind it to ur arrtibute

wdContext.currentContextElement().setUserName(strUserid.toUpperCase());

}

}

***************************************************

Now Organise the import.If u get an error for IWDClientUser, then plz add an external jar file - "com.sap.security_2.0_0" to your project.

Hope it helps.

Regards

Shruti

Former Member
0 Kudos

Hi,

if your working with normal webdynpro development it will work i think,,

can you discribe your scenario. if your working with ESS&MSS that will be a different scenario,

Cheers,

Apparao

srinivas_sistu
Active Contributor
0 Kudos

Hi,

Try this code to get the logged in user's login ID.

import com.sap.security.api.IUser;

IWDClientUser user=WDClientUser.getCurrentUser();

IUser myuser=null;

myuser=user.getSAPUser();

wdContext.currentContextElement().setVa_EmpId(myuser.getUniqueName());

Regards,

Srinivas

former_member185086
Active Contributor
0 Kudos

Hello

Try this

String logonID = "";
 
		try
		{
 
			IWDClientUser wdUser = null;
			try
			{
				wdUser = WDClientUser.getCurrentUser();
			}
			catch (WDUMException e1)
			{
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
 
			IUser user = wdUser.getSAPUser();
			logonID = user.getUniqueName();
 
		}
		catch (Exception e)
		{
			
		}

Best Regards

Satish Kumar

Former Member
0 Kudos

hi

check this forum thread

and even you can search for the code in the SDN for WDClientUser code .

you would certainly get the exact code required .