cancel
Showing results for 
Search instead for 
Did you mean: 

How to get portal logon user information in a embeded Webdynpro App?

Former Member
0 Kudos

Hi all,

I have a webdynpro application and have integrate it into a Portal's iView. Now in my application, I want to get the Logon Portal urer's information(like username .. etc.) So how to achieve this?

Thanks and Best regards

Deyang

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

The only way I could figure out how to get it was to import the com.sap.security.api.

1. From Window>Preferences>Java-->Classpath Variables, set up a variable called WEBAS_HOME pointing to:

<drive>/usr/sap/<SID>/jc00/j2ee/cluster/server0/

2. Right click on properties of your Dynpro Project->Properties->Java Build Path->Libraries and click "Add Variable."

3. Select WEBAS_HOME and click "Extend"

4. Select /bin/ext/com.sap.api.sda/com.sap.security.api.jar and click OK.

If you don't have access to a portal directory, you will have to get this jar file and copy it to your workspace to add to your build path instead of the above steps.

Then in your code:

import com.sap.security.api.IUser;
import com.sap.security.api.IUserAccount;


  public void GetLogonID( )
  {
	String LogonID;

	try {

		/*	create an user object from the current user */
		IWDClientUser wdUser = WDClientUser.getCurrentUser();

		IUser user = wdUser.getSAPUser();

		if (user != null) {
			IUserAccount acct = user.getUserAccounts()[0];
			if (acct != null) {
				LogonID = acct.getLogonUid();
			} else
				LogonID = "acct null";
		} else {
			LogonID = "user null";
		}

		wdContext.currentContextElement().setDisplayName(user.getFirstName() + " " + user.getLastName());
		wdContext.currentContextElement().setLogonID(LogonID.toUpperCase());
	} catch (Exception e) {
		e.printStackTrace();
	}
  }

Hope this helps... I had to search several places before I found all the necessary stuff. Maybe I can get my first points!

Thanks,

Andrew

Answers (3)

Answers (3)

Former Member
0 Kudos

Thankx

Former Member
0 Kudos

Hi Shubhadip and Andrew,

Thanks for your answers! I think my problem was resolved

Former Member
0 Kudos

Hi Deyang,

u can use WDClientUser utility for this. Try the following code

try{

IWDClientUser user = WDClientUser.getCurrentUser();

String fName = user.getFirstName();

String lName = user.getLastName();

}catch(Exception e){

}

Hope it helps!!!

Shubhadip

Former Member
0 Kudos

You could also try the following for the LoginID. If all you need is the first and last name and not the users LoginID, you don't need the com.sap.security.api.jar file.

Also, make sure you check the "Authenticate" checkbox when creating your Dynpro application.

public void GetLogonID( )
{
	/*@@begin GetLogonID()*/
	String LogonID;

	try {

		/* create an user object from the current user */
		IWDClientUser wdUser = WDClientUser.getCurrentUser();
		IUser user = wdUser.getSAPUser();
		LogonID = user.getUniqueName();
 
		wdContext.currentContextElement().setDisplayName(user.getFirstName() + " " + user.getLastName());
		wdContext.currentContextElement().setLogonID(LogonID.toUpperCase());
	} catch (Exception e) {
		e.printStackTrace();
	}
   /*@@end*/
}