cancel
Showing results for 
Search instead for 
Did you mean: 

Not getting WDClientUser.getCurrentUser().getSAPUser()

Former Member
0 Kudos

Hi All,

I want to get the current loggedin user in my WD Application.

I tried to use like WDClientUser.getCurrentUser().getSAPUser().getUniqueName()

But here I am not getting getSAPUser() for WDClientUser.getCurrentUser()

How can I get that...

Even I tried by using like WDClientUser.getLoggedInClientUser().getClientUserID().

But in this case, I am getting the number of characters inthat UserID.

Please provide the solution for my issue.

Thanks,

Bhvayasri.M

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Bhavya,

Can you try this in onPlugDefault(IWDCustomEvent wdEvent) method of the InterfaceView


try {
			
			IWDClientUser l_ClntUser = WDClientUser.getCurrentUser();
			
			IUser l_IUser = null;
			if(l_ClntUser!=null)
			 l_IUser= l_ClntUser.getSAPUser();
			
			IUserAccount[] l_IUA =null;
			if(l_IUser!=null)
			 l_IUA = l_IUser.getUserAccounts();
			
			String uniqName ="";
			if(l_IUA!=null && l_IUA.length >0)
			uniqName = l_IUA[0].getLogonUid();
		 
		wdThis.wdGet<comp>Controller().wdGetContext().currentContextElement().setCtx_va_loggedInUser(uniqName.toUpperCase());
		
		} catch (WDUMException e) {
			
					
		}catch (UMException e) {
			
					
		}

Answers (8)

Answers (8)

Former Member
0 Kudos

Answered

nikhil_bose
Active Contributor
0 Kudos

for getSAPUser() com.sap.security.api is needed.

If you are using DCs go to DC MetaData - DC Definition - choose add Used Dc from Used DCs context menu

drilldown SAP-JEE and you can find com.sap.security.api.sda[sap.com] drill further and select default under public part

click ok and select dependency type as Built time and Run time.

If you are not using DC, copy the same to \lib directory and include in the java build path

Former Member
0 Kudos

Hi,

You will first have to add the com.sap.security.api.sda file to the used DC. This will import the following classes required for user identification :

import com.sap.security.api.IUser;

import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;

import com.sap.tc.webdynpro.services.sal.um.api.WDUMException;

Then in the wdDoInit() method of the view, you can add the following code to fetch the user ID of the user logged in :

IUser currentUser = null;

try

{

currentUser = WDClientUser.getCurrentUser().getSAPUser();

}

catch (WDUMException e)

{

// TODO Auto-generated catch block

wdComponentAPI.getMessageManager().reportException( "Error occured while processing data:" + e.getMessage() , true);

return null;

}

String userID = currentUser.getUniqueName();

You will get the userID of the current user in 'userID'.

Regards,

Divyata

Former Member
0 Kudos

Hi,

Write the code which is given above and refer this thred to import .jar file to ur Application.

Regards,

H.V.Swathi

Former Member
0 Kudos

Hi Bhavya,

Use the below code in your WD Application

IWDClientUser clientUser = WDClientUser.getCurrentUser();

IUser user = clientUser.getSAPUser();

from the object "user" you can get the current logged in user details.

If you want your application to provide access for authentication, you can achieve this by setting the application property i.e, "authentication = true"

Regards,

Kavitha.

Former Member
0 Kudos

Hi,

Try this......

import com.sapportals.portal.security.usermanagement.IUser;

import com.sapportals.portal.security.usermanagement.UserManagementException;

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;

import com.sapportals.wcm.util.usermanagement.WPUMFactory;

try {

com.sapportals.portal.security.usermanagement.IUser ep5User = null;

IWDClientUser wdClientUser=WDClientUser.getCurrentUser();

com.sap.security.api.IUser sapUser=wdClientUser.getSAPUser();

ep5User=WPUMFactory.getUserFactory().getEP5User(sapUser);

String UesrId=ep5User.getId();

}catch (WDUMException e1) {

mgr.reportException("WDUMException::"+e1.toString(),true);

} catch (UserManagementException e2) {

mgr.reportException("UserManagementException::"+e2.toString(),true);

}

Hope this will be useful....

Regards,

Swati

Former Member
0 Kudos

Hi Bhavya,

Go through the following link:

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e039ce31-4156-2b10-1481-bdc3ff8c...

It contains the method for how to create such an application that will fulfil your requirements. You once go through that and check what you are doing is consistent with the above article or not. When you deploy your application on the browser, if everything is alright then it will show J2EE_USER where you are showing the credentials of the logged in user.

Hope it helps.

Regards.

Rajat

former_member197348
Active Contributor
0 Kudos

Hi Bhavya,

First you need to add the corresponding jar file the com.sap.security.api .

Then

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

After this try with this code to get user ID. This code is working for me.

String userName = "";
	IWDClientUser wdUser = null;
	try
	{
	wdUser = WDClientUser.getCurrentUser();
	}
	catch (WDUMException e)
	{
	wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(), false);
	}
	IUser usernam = wdUser.getSAPUser();
	userName = usernam.getUniqueName();

regards,

Siva