cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get Portal Login User Details in WD Application

Former Member
0 Kudos

Hi,

Could you please help me out as how to get the user who has logged into the portal.

Regards,

Abilash.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

In you webdynpro location you can use the following code to get the logged in user details.

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();
}

The following import statements have 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;

Award points if helpful.

Regards,

Sujana

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Abilash,

If you want to get the user who has logged into the portal in your web dynpro application then you can use the following logic.

{

// 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();

//pass the value obtained from the portal to value attribute

wdContext.currentNode().setAttribute(new String(strUserid));

}

}

}

Note: Defining the IUser will show an error. To resolve this:

1. Right-click the project in Eclipse or SAP NetWeaver Developer Studio.

2. Select Properties.

3. Choose Java build path -> Libraries -> Add Variable -> Select variable WD_RUNTIME -> Extend -> com.sap.security -> lib -> com.sap.security.api.jar.

Thanks & Regards,

Suvarna.

Former Member
0 Kudos

Hi Suvarna,

Thanks for your reply. I will try to do that.

Thanks,

Abilash