on 01-05-2007 9:58 AM
Hi All
I used following source code to capture Portal User ID in WD Application
but i am not getting any UserName
public void wdDoInit()
{
//@@begin wdDoInit()
MessageManager msgMgr =(MessageManager) wdThis.wdGetAPI()
.getComponent().getMessageManager();
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();
// pass the value obtained from the portal to value attribute
wdContext.currentContextElement().setWelcomeText(strUserid);
}
}
}catch (Exception e){
msgMgr.raiseException(" Not a Valid User : " + e.getMessage(),false);
}
//@@end
}
Even I added com.sap.security.api.jar
what may be the reason
try {
IUser user = WDClientUser.getLoggedInClientUser().getSAPUser();
IUserAccount[] acct = user.getUserAccounts();
if (acct[0] != null) {
strUserid = acct[0].getLogonUid();
wdComponentAPI.getMessageManager().reportSuccess(strUserid );
} catch (UMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
it should helps you
Thanks,
Lohi.
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ramakrishna ,
<b>To get the logged In User ID: try the following Coding</b>
String epUserId="";// Logged In User ID
try
{
IWDClientUser wdUser = WDClientUser.getCurrentUser();
IUser user = wdUser.getSAPUser();
if (user != null)
{
IUserAccount[] acct = user.getUserAccounts();
if(acct[0] != null)
epUserId = epUserId+acct[0].getLogonUid();//.toUpperCase();
}
else
{
msgMngr.reportException("No USER",true);
epUserId="No User";
}
}
catch(Exception ume)
{
msgMngr.reportException("Exception : "+ume,true);
epUserId="No User";
}
<b>To Get the User Name of a particular portal User ID Try:</b>
String epUserName="";
try
{
IUserFactory ufact = UMFactory.getUserFactory();
IUserSearchFilter isf;
isf = ufact.getUserSearchFilter();
isf.setUniqueName(epUserID, ISearchAttribute.EQUALS_OPERATOR, false);//SEARCHES USING userID
ISearchResult sr = ufact.searchUsers(isf);
String strtest = "";
String strnamen = "";
while (sr.hasNext())
{
strtest = sr.next().toString();
IUser user = UMFactory. getUserFactory(). getUser(strtest);
if(user!=null)
{
if(user.getFirstName()!=null)
epUserName=user.getFirstName().toUpperCase();
else
epUserName=user.getLastName().toUpperCase();
}
else
epUserName="No User Name Found.";
}
}
catch(Exception e)
{
msgMngr.reportException("Exception : "+e, true);
epUserName="No User Name Found";
}
Let me know whether this is useful for you.
thanks
Smitha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your method is correct and it should be work.... but if wont then
main thing
set sap.authentication-> true...
and try it without portal. it`ll give you a UME login screen and you can pass user to it...
and when u`ll integrate application with portal do one thing.
1>in interfaceviewcontroller of your main screen. there is one default inbound plug its a startup plug.. pass user as a parameter. its a simple solution...
as when startup plug is start point for ur application in portal.. reply me when you`ll try it. i just tried it as a quick fix solution fro my application
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Try this.
try {
IWDClientUser curUser = WDClientUser.getCurrentUser();
IUser sapUser = curUser.getSAPUser();
String userId = curUser.getClientUserID();
if (sapUser != null) {
userId = sapUser.getUniqueName();
}
... catch etc.
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
WDClientUser.getCurrentUser().getSAPUser().getUniqueName()
should work if you want to retrieve the portal user id in the webdynpro application.
You might have already done this... but have u set the "sap.authentication = true" in the application properties of your application? Without this, you will get a null pointer exception if you try to run the getSAPUser() method.
To set application properties, right click on your application -> Edit -> Go to the "Application Properties" tab -> New -> Pre-defined radio button -> Browse -> "Authentication" -> choose true in the "value" dropdown.
Hope this solves your problem
Regards,
Navneet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you set authentication as true ,when you deploy your webdynpro application you will get logon screen which asks you to enter username and password and if it valid it takes you to the first view and displays the username of the user you have logged in as.
If you dont set authentication as true ,then you may not get screen to enter your username and password and so it may display null there.
Regards
Akshaya
Yes. I put this:
IWDMessageManager mgr = wdComponentAPI.getMessageManager();
try {
IWDClientUser curUser = WDClientUser.getCurrentUser();
curUser.getFirstName();
mgr.reportSuccess("FirstName= " + curUser.getFirstName() + " /Last= " + curUser.getLastName() + " /ID= " + curUser.getClientUserID());
//User sapUser = curUser.getSAPUser();
String userId = curUser.getClientUserID();
// if (sapUser != null)
// {
// userId = sapUser.getUniqueName();
// }
}catch(Exception e)
{
mgr.reportException("Exception", false);
}
It shows me "guest" as LastName and null as FirstName( this without authentication).
Does this means that when you don't use the "authentication=true", the user is Guest ??
null
HI,
use this code.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.