cancel
Showing results for 
Search instead for 
Did you mean: 

Need User Name/userid from Portal in WebDynpro Java application

Former Member
0 Kudos

Hi All,

I am using my Webdynpro for Java application as a iveiw in Enterprise portal. I want to get the Username/userid for the portal. how can we get that?

Regards,

Puneet Aggarwal

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Use below code for retrive al users from portal:


try {
		IUserFactory ufactory=UMFactory.getUserFactory();
		ISearchResult rst = UMFactory.getUserFactory().getUniqueIDs();
		
		IUserFactory usf = UMFactory.getUserFactory();
		
		
		
		IUser iuser = null;
		
		//IUserListElement userElement = null;
		
		int i = 0;
		IPrivateKmnewsView.IUserNodeNode usernode=wdContext.nodeUserNode();
		IPrivateKmnewsView.IUserNodeElement usernodeelement = null;
		
		while (rst.hasNext()) {
		
		iuser =
		
		UMFactory.getUserFactory().getUser(rst.next().toString());
		//wdComponentAPI.getMessageManager().reportSuccess("rst.next().toString() : "+rst.next().toString());
		usernodeelement = usernode.createUserNodeElement();
		String UID=iuser.getUid().toString();
		//wdComponentAPI.getMessageManager().reportSuccess("UID:"+UID);
		usernodeelement.setUserId(UID);
		//wdContext.currentUserNodeElement().setUserId(UID);
		String UniqueID=iuser.getUniqueID().toString();
		//wdComponentAPI.getMessageManager().reportSuccess("UniqueID:"+UniqueID);
		String email = iuser.getEmail();
		
		String fname = iuser.getFirstName();
		
		String lname = iuser.getLastName();
		String Name =fname+lname;
		//if(!(fname.equalsIgnoreCase("") ^ fname.equalsIgnoreCase("")))
		//{
		//if(currentUsers.equals()
		usernodeelement.setUserName(Name);
		usernodeelement.setUserEmailID(email);
		usernode.addElement(usernodeelement);
		
		//wdComponentAPI.getMessageManager().reportSuccess("Name : "+fname+""+lname);
		
		//wdComponentAPI.getMessageManager().reportSuccess("Email : "+email);
		//}
		} 
		wdContext.currentContextElement().setUserTableVisible(WDVisibility.VISIBLE);
	} catch (UMException e) {
		// TODO Auto-generated catch block
		wdComponentAPI.getMessageManager().reportSuccess("Exception "+e);
	}  

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Puneet,

Please use the below code to get the logged in User

try

{

IWDClientUser CurrentUser = WDClientUser.getCurrentUser();

String UserId = WDClientUser.getCurrentUser().getSAPUser().getUniqueName();

String UserName = WDClientUser.getCurrentUser().getSAPUser().getName();

}

catch(Exception e)

{

e.printStackTrace();

}

Gurmat

Former Member
0 Kudos

Hi,

1.Use the following code.

try{

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

String UserID = strUserid.toUppercase();

}

}

}

catch(Exception e)

{

}

2.Now right click & "organise import".

3.Add JAR file u2013 com.sap.security_2.0_0

Right click on project->properties->java build path->libraries tab->Add External JARs->eclipse folder->plugins folder->select jar file

Hope this helps.

Regards

Shruti

Former Member
0 Kudos
//	To get logged in user details
	   IWDClientUser clientUser = null;
	   try {
		   clientUser = WDClientUser.getCurrentUser();
	   } catch (WDUMException e) {
		   // TODO Auto-generated catch block
		   e.printStackTrace();
	   }
	   IUser user = clientUser.getSAPUser();

user.getUniqueName() will give you user ID.

Add the jar mentioned above, you can find that jar @ C:\Program Files\SAP\IDE\IDE70\eclipse\plugins\com.sap.security_2.0.0\lib

whichever directory you installed NWDS.

Former Member
0 Kudos

Hi Puneet,

Please add the "com.sap.security.api.jar" to your Project and write the following piece of Code to retrieve the User Name and User Id.


try
{
      IWDClientUser CurrentUser = WDClientUser.getCurrentUser();
      String UserId = WDClientUser.getCurrentUser().getSAPUser().getUniqueName();
      String UserName = WDClientUser.getCurrentUser().getSAPUser().getName();
}
catch(Exception e)
{
     e.printStackTrace();
}

Thanks & Regards,

Sharma Kvbk.