Check all Users who have logged into portal - webdynpro appl

Check all Users who have logged into portal - webdynpro appl




Get Portal users from WebDynpro

//Get user Logon Id who has logged in the current session-I

To run this code successfully, we need to add security.api.jar file by using following setps
Right Click on project->Java Build Path>Add Variables>WD_Runtime>Extendsàcom.sap.security_2.0.0>lib->com.sap.security.api.jar







public void GetLogonID()
Unknown macro: {//@@begin GetLogonID()String LogonID;try{ /* create an user object from the current user */ IWDClientUser wdUser=WDClientUser.getCurrentUser(); IUser user=wdUser.getSAPUser(); if(user!=null){ IUserAccount acct=user.getUserAccounts()[0]; if(acct!=null) LogonID=acct.getLogonUid(); else LogonID="acct null"; }
else

Unknown macro: { LogonID="user null"; }
wdComponentAPI.getMessageManager().reportSuccess(user.getFirstName()+" "+user.getLastName());
wdComponentAPI.getMessageManager().reportSuccess(LogonID.toUpperCase());
}catch(Exception e)
Unknown macro: { e.printStackTrace(); } //@@end
}
//@@begin javadoc:GetCurrentUser()
/*Declaredmethod./
//@@end
*Get user who has logged in the current session-II{*}public void GetCurrentUser()
Unknown macro: {//@@begin GetCurrentUser()String LogonID;try{ // create an user object from the current user IWDClientUser wdUser=WDClientUser.getCurrentUser(); IUser user=wdUser.getSAPUser(); LogonID=user.getUniqueName(); wdComponentAPI.getMessageManager().reportSuccess(user.getFirstName()+" "+user.getLastName()); wdComponentAPI.getMessageManager().reportSuccess(LogonID.toUpperCase()); }
catch(Exception e)
//@@end
}
//@@begin javadoc:CheckAllUsers()



*Declaredmethod ./

//@@end


//Check all the users method to get current logged in users from the portalpublic void CheckAllUsers(){
//@@begin CheckAllUsers()
IWDClientUser currentUsers[]=WDClientUser.getClientUsers();
//Displaying the count of logged on users
wdComponentAPI.getMessageManager().reportSuccess("Number of logged on Users in the portal - "+(currentUsers.length-1));
for(int i=0;i<currentUsers.length;i++)
Unknown macro: {if(currentUsers[i]!=null){ // Displaying the logged on users; if(!currentUsers[i].getLastName().equals("Guest")){ String first= currentUsers[i].getFirstName(); wdComponentAPI.getMessageManager().reportSuccess("User - "+currentUsers[i].getFirstName()+" "+currentUsers[i].getLastName()); }
}
}



//@@end
}
//@@begin javadoc:LogOffUser()
/*Declaredmethod./
//@@end
Log off the userpublic void LogOffUser(){
 //@@begin LogOffUser()                   
WDClientUser.forceLogoffClientUser("http://koldxp-pigoswam:50000/irj/portal");
//@@end
}