cancel
Showing results for 
Search instead for 
Did you mean: 

Null Pointer exception when retrieving the portal user name in webdynpro

Former Member
0 Kudos

Hi All,

Using the IWDClientUser and IUser classes, I am retrieving the portal logged in user name in web dynpro. But iam getting null pointer exception.

IUser sapUser = null; IWDClientUser user = WDClientUser.getCurrentUser();sapUser = user.getSAPUser(); String str = sapUser.getName();

Help required.

thanks

Supriya.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

try with the following code,

String userid="";

try {

IWDClientUser user = WDClientUser.getCurrentUser();

userid = user.getSAPUser().getUniqueName();

}

catch (WDUMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Thanks,

ramesh

Former Member
0 Kudos

Hi All,

Thanks for the reply. My requirement is to retreive the protal login user id. For this user id what and all are roles mapped to it. There is LDAP mapped for s-account that also i should retreieve.

Please help me out. Thanks.

Former Member
0 Kudos

Hi ,


IWDClientUser wdUser;
		try {
			wdUser = WDClientUser.getCurrentUser();
			IUser user = wdUser.getSAPUser();
			if (user != null)
			try {
				  {
				  IUserAccount[] acct = user.getUserAccounts();
				  if(acct[0] != null)
				  {
				  String strUserid = acct[0].getLogonUid();
				  //strUserid.get
				  			  }
				  }
			} catch (UMException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} catch (WDUMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 

use the above code to get Logonid

To get the Roles, assigned to portal user

see the below link

https://forums.sdn.sap.com/thread.jspa?threadID=918585&messageID=5597028#5597028

Regards,

Sunitha Hari

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

You can use the following cade...

String login;

IWDClientUser wdUser;

try {

wdUser = WDClientUser.getCurrentUser();

IUser user = wdUser.getSAPUser();

if ( user != null ){

try {

IUserAccount account = user.getUserAccounts()[0];

if(account != null){

login = account.getLogonUid();

String fname = user.getFirstName();

String lname = user.getLastName();

wdContext.currentLoginInfoElement().setFirstName(fname);

wdContext.currentLoginInfoElement().setLastName(lname);

}

} catch (UMException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

} catch (WDUMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Former Member
0 Kudos

Hi All,

I am getting the result using the following code, but i am getting for adminstrator and not for the user who has logged in.

Please let me know the result.

Thanks & Regards

Supriya

Former Member
0 Kudos

The follwing lines of code would provide u the current user

IWDClientUser user = WDClientUser.getCurrentUser();

and the sap was user

IUser suser = user.getSAPUser();

to get the role

IRole role = UMFactory.getRoleFactory().getRole(roleName);

// check if user is member of role,

// the "true" attribute means, that role assignment might be

// indirect (ie. for a group in which user is a member

result =role.isUserMember(sapUser.getUniqueID(), true);

regards

Nihil tapkir

siddharth_jain
Active Contributor
0 Kudos

Hi Venkata,

Make sure that sap.Authentication property of WD Application is set to true.

Try using the below code:

IWDClientUser user = WDClientUser.getLoggedInClientUser();

IUser puser = user.getSAPUser();

now you can get the name and other attributes.

Regards,

Siddharth

lokesh_kamana
Active Contributor
0 Kudos

Hi,

i think you are getting Null pOinter exceptions because

Most possible case is you dont have the NAME field filled while creating the user in portal.

try getting the remaining fileds like (first name,last name,display name,etc.,,,,,,,,,,,,).

Thanks & Regards,

Lokesh

snehal_kendre
Active Contributor
0 Kudos

HI,

Can you check once again, i think your null pointer exception is at

String str = sapUser.getName();

if yes then

do as above post and use firstname lastname

Former Member
0 Kudos

Hi,

Are you logging into the portal to run your application? Is a guest user configured in the UME? The getSAPUser() call returns null if there's no guest user in the UME or it might return a named anonymous IUser instance.

Regards,

Satyajit.

Former Member
0 Kudos

Hi satyajith,

Yes i am logging to the portal and accessing my application. So my application should basically return my portal login id inside the code right? Please let me know if any configurations be done.

My requiremnet is to retrive the current logged in user and his roles.

Thanks

Supriya

Former Member
0 Kudos

Hi,

Try using the current logged in client user:


 IWDClientUser usr = WDClientUser.getLoggedInClientUser();
	  
 //get first and last names
 String firstName 	= usr.getFirstName();
 String lastName	= usr.getLastName();

Regards,

Satyajit.