cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the current user credentials?

Former Member
0 Kudos

Hello,

How do I take the current user credentials (meaning his username and password)? I know how to retreive his first name, last name ect... using wdClientUser.getCurrentUser(), but there is no option there to receive the user's parameters which serves him to enter the portal...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I had the same problem .As a workaround you can try this

try{

user = WDClientUser.getCurrentUser();

IUser userID = user.getSAPUser();

wdContext.currentContextElement().setINumber(userID.getUniqueID().substring(userID.getUniqueID().length()-7,userID.getUniqueID().length()));

}

catch(Exception ex)

{

/* Exception Handling */

}

NOTE ::This is not the standard way of doing

Regards, Anilkumar

Answers (6)

Answers (6)

Former Member
0 Kudos

Hello Thanx

Former Member
0 Kudos

Hi @ all,

I need the user credentials as well. And I tried this code:

<b>

IWDClientUser wdUser = WDClientUser.getCurrentUser();

IUser user = wdUser.getSAPUser();

</b>

But my developer studio doesn't find the <b>getSAPUser()</b> method.

Does anyone have an idea why I doesn't have it.

I have NDS SP11.

I got this two errors:

This compilation unit indirectly references the missing type com.sap.security.api.IUser (typically some required class file is referencing a type outside the classpath) MainBLComp.java art/gen_wdp/packages/com/ar line 0

-


The project was not built since its classpath is incomplete. Cannot find the class file for com.sap.security.api.IUser. Fix the classpath then try rebuilding this project. AR_Tool

Regards,

Dennis

Former Member
0 Kudos

Hi Dennis,

Add the following jar file in the classpath of your project.

"C:\Program Files\SAP\JDT\eclipse\plugins\com.sap.security\lib\com.sap.security.api.jar"

Until you add the jar file, you will not get the "getSAPUser()".

Regards,

Santhosh.C

Former Member
0 Kudos

Hi Santhosh,

thanks for the hint.

As I imported the jar file, I got no more errors.

Regards,

Dennis

WolfgangJanzen
Product and Topic Expert
Product and Topic Expert
0 Kudos

Are you seriously asking for a mechanism to retrieve a user's password ...? (in ABAP: SY-PASSWD²)

As already outlined in the password is supposed to be a private information ("secret") known only to the user. The user is not supposed to share this secret with other users - and the system is supposed to handle this data with care as well.

I guess that you intend to submit a request to another server and wish that this request is processed under the userID of the current user (system acting on behalf of the user). Well, that's a typical scenario where "authentication assertions" should be used. That can be either SAML or the SAP proprietary version ("SAP Authentication Assertion Ticket").

Regards, Wolfgang

-

-


² that's a joke, such a system variable does not exist

Former Member
0 Kudos

Are your portal instance and webdynpro app running on the same WAS server.

Former Member
0 Kudos

Yes they are

Former Member
0 Kudos

Hi,

Try creating an application that just displays the username(strUserid) and then embed it in an iview.

Check if it works. I tried it and is working fine.

If you still find a problem then I believe you will have to take it up in the portal forum.

Do send in your feedback

Regards

Noufal

Former Member
0 Kudos

Can you send in the code that you have written? And also what are you trying to do with the user credentials?

May be there you are doing something wrong.

I feel this is resolved from the webdynpro side.

Former Member
0 Kudos

Hello sdn...?

Thanx for the reply

Former Member
0 Kudos

Hi,

Please check the following.

Regards, Anilkumar

Former Member
0 Kudos

Hi just try this

WDClientUser.getLoggedInClientUser()

Thanks

Krishna Kanth

Former Member
0 Kudos

Hi,

Include the com.sap.security.api. jar file

and he following code

IWDClientUser wdUser = WDClientUser.getCurrentUser();

IUser user = wdUser.getSAPUser();

Regards

Noufal

Former Member
0 Kudos

Try {

IWDClientUser wdUser = WDClientUser.getCurrentUser();

IUser user = wdUser.getSAPUser();

if (user != null)

{

IUserAccount[] acct = user.getUserAccounts();

if(acct[0] != null)

{

String strUserid = acct[0].getLogonUid();

wdContext.current<input>Element().setAssoid(new String(<Userid>));

}

}

}

Former Member
0 Kudos

Dear krish,

I don't see an option there to retreive the UserID the getClientUserID retreives the unique id of the dynPro not the UserID the client loggen into the portal with.

Former Member
0 Kudos

10X Noufal, this is what I looked for

Former Member
0 Kudos

Hello again,

When I run your code on a DynPro application inside the portal I receive null instead of the userName. Why is that?

Former Member
0 Kudos

Hi,

The code retrieves the user credentials from the portal. I beleive when you are trying to run it as a dynpro application. It would not give any value.

Regards

Noufal

Former Member
0 Kudos

So how do I do it when I am running a dynpro application? Are you saying that a DynPro application cannot know these details? Do note that I am not running it from the NWDS test and preview(at this case I can understan why it gives null, since I am not inside the portal), I am running it from an iView while I'm inside the portal and I still receive null.

Former Member
0 Kudos

Hi,

I don't know what the problem is, however the code works fine for me. May be there is some configurations that you have missed out.

I'll tell you what i have done.

I've used the code in the init of the webdynpro and embedded the application in an iview . I assigned it to a role and the username is displayed in the application.

Regards

Noufal

Former Member
0 Kudos

Hi Roy,

Is ur portal and WAS using the same user store.

Any way try this code which works fine for me.

IWDClientUser clientUser = WDClientUser.forceLoggedInClientUser();

IUser user=clientUser.getSAPUser();

String userID=user.getUniqueID();

String id= userID.substring((userID.indexOf(":")+1));

Hope this should solve ur problem.

Regards,

Sowjanya.

Former Member
0 Kudos

The earlier code provide the username during preview itself.

I've checked. I believe it's related to some configuration issues in the portal.

Former Member
0 Kudos

Hey Sowjanya

Your code is working thanx,but instead:

String userID=user.getUniqueID();

You can use:

String userID=user.getUniqueName();

which gives the login name!

Former Member
0 Kudos

But for recieving the password you will need the useraccount also.

Former Member
0 Kudos

Hi Roy,

I thought u just need the login ID.

Now is it solved or do u need anything else.

Former Member
0 Kudos

I need the password as well...

Former Member
0 Kudos

try {

IWDClientUser wdUser = WDClientUser.getCurrentUser();

IUser user = wdUser.getSAPUser();

if (user != null)

{

IUserAccount[] acct = user.getUserAccounts();

if(acct[0] != null)

{

String strUserid = acct[0].getLogonUid();

<b>boolean pass=acct[0].checkPassword(<String>);</b>

wdComponentAPI.getMessageManager().reportSuccess(strUserid);

}

else{

wdComponentAPI.getMessageManager().reportSuccess("no value retrieved");

}

}

else{

wdComponentAPI.getMessageManager().reportSuccess("no value retrieved");

}

}catch(Exception e){

wdComponentAPI.getMessageManager().reportSuccess("no value retrieved "+ e.toString());

}

Former Member
0 Kudos

Dear Sowjanya,

Please ignore my last messege...

Former Member
0 Kudos

Hello All,

Do forgive my novice question here but I am also currently encountering similar difficulties in obtaining the userid from Poratls. I have followed Noufal's code snippets and the WD app was deployed successfully. However, All I got back was a message "No value retrieved". According to the code, thsi probably means that the user equals to null. My WD app is embedded in an iview and is lauched from Portals. Does anyone know what else I must do to have my userid/login info displayed ? Eg: Parameters settings on the WAS or Portals ?

Thank you.

from

Kwok Wei

Former Member
0 Kudos

Hey Kwok,

Please check if your portal is configured with a proxy.

You can check that under: System Administration->System Configuration->Service Configuration. Search there for a portal service by the name "proxy".

After it found it, right-click on it and choose "configure".

In case your portal is configured with a proxy the fields "HTTP Proxy Host" and "HTTP Proxy Port" are filled.

In that case verify that the field "HTTP - Bypass Proxy Servers" is also filled. If it is not filled fill it like this:

<portalhost> | localhost | <portalhost fully qualified name>.

Save the changes and restart the Service. In order to restart it:

right-click again on "proxy" and choose "Locate in portal catalog". Once it found it, go to it's containing folder "com.sap...", right-click on it and choose "Administrate". there you can restart the services.

Let me know if it helped in any way.

Regards,

Roy

Former Member
0 Kudos

Hi Roy,

Thanks for the tip ! I will try it out on Monday with the Portal guys. Btw, will you be kind enough to share any of your implementation experience particularly the tricky parts so that I may be able to learn from your experience ? Thanks !!

from

Kwok Wei

Former Member
0 Kudos

Just tell me what u need and if I know, I will happy to share with you. But even if I don't know there are more than few people here who can help almost on any situation, and this I am saying from experience...

Former Member
0 Kudos

Oh and one more thing: Verify that your application is configured with "authentication=true".

You can find this property under the NWDS at DynPro application's properties under the application you created.

Former Member
0 Kudos

Hello Roy,

By setting the "authentication=true" in NDS, do I also need to turn on some parameters @ the WAS end as well ?

from

Kwok Wei

Former Member
0 Kudos

Hey Roy... It works now !!!

I am able to display my login ID after I set the "authentication=true". However, One thing that I have noticed is that it actually prompts me for a logon screen prior to lauching my web dynpro app. This looks like some parameter settings are needed on the WAS end. Can you advise ?

from

Kwok Wei

Former Member
0 Kudos

It does that because you launch the app from the NWDS which is outside the Portal. When you will build an iView based on this app inside the portal it won't ask you for login anymore since it will run inside the portal context, after the user made his login already....

If you need more help tell me.