cancel
Showing results for 
Search instead for 
Did you mean: 

Help Needed: Getting Portal User

Former Member
0 Kudos

Hi all,

We developed the development component under the track and deployed in standalone J2EE server. From the development J2EE server we transport the component to solution manager J2EE server. In EP we created system, for the same solution manager server and with this system as a reference we created the webdynpro iView in portal to access the component stored in solution manager server.

Now we want to get the EP Login User of the portal server. Please can anybody help us to get the EP user with respect to our senario.

The code with which we tried was as follows,

//To get EPUser

IUser epuser = null;

IUserObjectBasedNavigation obnService = (IUserObjectBasedNavigation) WDPortalUtils.getServiceReference(IUserObjectBasedNavigation.KEY);

String portalUser="";

try

{

IWDClientUser user1 = WDClientUser.getLoggedInClientUser();

epuser=user1.getSAPUser();

portalUser=epuser.getUniqueName();

wdComponentAPI.getMessageManager().reportSuccess(portalUser);

}

catch (Exception e)

{

wdComponentAPI.getMessageManager().reportException("Failed to get current user: " + e.getLocalizedMessage(),true);

}

Please experts advice needed.

Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

Dheerendra
Participant
0 Kudos

Hi Krish,

try the following one..

Try out this code in webdynpro.

{

// 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

Dheerendra Shukla

Former Member
0 Kudos

hi Shukla,

if you want to get the uniquename of the logged in portal user use this code.

String Username = "";

IWDClientUser wdUser = null;

try {

wdUser = WDClientUser.getCurrentUser();

} catch (WDUMException e) {

e.printStackTrace();

}

IUser user = wdUser.getSAPUser();

();

Username =user.getUniqueName();

// for unique ID use user.getUniqueId().

for this you need to add the security.api jar file.

Right click on the project properties->addexternal jars and add this .jar file

Regards,

Gopi

Former Member
0 Kudos

Hi,

Make sure you have set the "sap.authentication = true" in the application properties of your application.

Then use the following code -

WDClientUser.getCurrentUser().getSAPUser().getUniqueName()

Remember, if the "sap.authentication: application property is not set, the above method will throw a Null Pointer.

Regards,

Navneet.

Former Member
0 Kudos

Hi,

Check this blog:

/people/preksha.malhotra/blog/2006/12/12/accessing-a-web-dynpro-application-through-portal-using-portal-user-id

Regards,

Bhavana