cancel
Showing results for 
Search instead for 
Did you mean: 

Get the portal user id in WebDynpro java

Former Member
0 Kudos

Hi, I'm making a method which I get the portal user data, but it is not recognizing data types.
My question is, which libraries should I import?


My method is as follows:

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

          //}

          }

  } catch (UMException e) {

            // TODO Auto-generated catch block

            wdComponentAPI.getMessageManager().reportSuccess("Exception "+e);

       } 

Thanks.

Cristian ottero

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

To all: It is generally considered bad practice to add Jar files directly to the build path of Web Dynpro applications -- and when using NWDI for development instead of LocalDevelopment, adding Jar files directly is downright impossible!

Instead, you should add component tc/je/usermanagement/api as a 'Used DC' (NW 7.0) / 'Required DC' (NW7.11 and up)

At the bottom of the Java API pages, there is a chapter named 'This class can be accessed from' which displays the required DC's to be included in your Web Dynpro DC project (see http://help.sap.com/javadocs/NW73/SPS05/CE/se/com.sap.se/com/sap/security/api/UMFactory.html )

Former Member
0 Kudos

Thanks

I served a lot of your answer. and it is true that we must apply the best practices

Regards

Cristian

Answers (3)

Answers (3)

pankaj001
Participant
0 Kudos

Hi Cristian,

Please import com.sap.security.api.jar. You will find that in plugins folder.

Rgds,

Pankaj

vijay_kumar49
Active Contributor
0 Kudos

Hi,

1. Take jar file from below Path:

C:\Program Files\SAP\JDT\eclipse\plugins\com.sap.security\lib\com.sap.security.api.jar" file has to be added to classpath.

2. How to add Jar File to Project:

To resolve this, within the properties of  the project, choose Java build path -> Libraries -> Add external jars -> com.sap.securities -> lib -> com.sap.security.api.

3. Code:

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

}

Regards

Vijay Kumar Kalluri

Former Member
0 Kudos

Now why didn't you use the SCN search to locate examples? Find attached a link to one. You neglected to mention your AS JAVA version.

http://scn.sap.com/thread/3295530