cancel
Showing results for 
Search instead for 
Did you mean: 

how can we find current logged in users in portal using webdynpro java

Former Member
0 Kudos

Hello Gurus,

how can we find list of currently logged in users in portal using APIs from webdynpro java.

Thanks

Venkat.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Venkat,

Use this code to get all the logged on portal users:

IUserAccountFactory accFc = UMFactory.getUserAccountfactory();

IUserAccountSearchFilter srchFltr = accFc.getUserAccountSearchFilter();

srchFltr.setLoggedInBetween(Date from, Date to);

if(accFc.search(srchFltr).hasNext()){

IUser user = accFc.getUserAccount((String) accFc.search(srchFltr).next()).getAssignedUser();

}

Adjust the 'from' (Date) as current date and

'to' (Date) as future date. Should work.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi Venkat,

IWDClientUser currentloggedonUsers[] = WDClientUser.getClientUsers();

for(int i = 0; i < currentloggedonUsers.length; i++)

{

if(currentloggedonUsers.getSAPUser() != null)

{

// retrieve the currents users

currentloggedonUsers.getSAPUser().getUniqueName());

}

}

Please have a look at this thread aswell

Kind regards,

Saravanan K

Former Member
0 Kudos

Hi saravanan,

Thank you for your quick response, i have used same code,mentioned in your reply.

But it is displaying only one currently logged in user, but i want list of all currently logged in users. I mean if logged in with my account and run application, it showing only my user id, eventhough my collegues are entered into portal at same time(not showing their user ids in my output).

how can i acheive this?

Thanks

Venkat.

Former Member
0 Kudos

Hi Venkat,

You can get the users using the UserFactory

Please have a look at this thread

Kind regards,

Saravanan K

Former Member
0 Kudos

Hi venkat,

You can do it simply and efficiently by filtering the role (roleid as for my previous code).


try {
			IWDClientUser wdUser = WDClientUser.getCurrentUser();
 
		} catch (WDUMException e) {
		}
		try {
 
			String roleId, uniqueName, displayName = null;
			IUser currentUser = WDClientUser.getCurrentUser().getSAPUser();
			String User = WDClientUser.getCurrentUser().getClientUserID();
			String[] str = User.split(".");
			Iterator<String> rolesAssignedToUser = currentUser.getRoles(true);
 
			while (rolesAssignedToUser.hasNext()) {
 
				roleId = rolesAssignedToUser.next();
                               //The filter to filter the loged in roles.
                                if(roleid.contains("ROLE.PCD")) {                                         
				displayName = UMFactory.getRoleFactory().getRole(roleId)
						.getDisplayName();
				String uName[] = displayName;}
			}

"ROLE.PCD" is the possible Roles for the particular application.

Let me know if you need any help.

Regards

Jeetendra.

Former Member
0 Kudos

Hi Venkat,

Getting user usind WDClientUser api will only retrieve you as the portal user on the thin client. That is why we need to use IUserAccountFactory to get the users on portal under UMFactory. And, what Dreamd4Desire is trying to get is the portal role assigned to the current user i.e. you to access application, which I think is not what you want.

Just try setting attribute in the instance of IUserAccountSearchFilter and use the setter of attribute LoggedInBetween(Date from, Date to) to set the search criterion.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi Venkat,

I have something for you. Try this for getting current client users and client sessions on portal server.

String [] ses = WDServerState.getActualClientSessions();

String [] urs = WDServerState.getActualClientUsers();

int usrNo = WDServerState.getNumberOfClientUsers();

int sessNo = WDServerState.getNumberOfActualClientSessions();

wdComponentAPI.getMessageManager().reportSuccess("No of client sessions: " + sessNo);

wdComponentAPI.getMessageManager().reportSuccess("No of current user: " + usrNo);

int in = urs.length;

for(int i=0; i<in;i++){

wdComponentAPI.getMessageManager().reportSuccess("User-->" + urs<i> + " : ");

}

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi Tushar,

Thank you for your response.

I have tried with your code.

while i am using this code

int in = urs.length;

for(int i=0; i<in;i++){

wdComponentAPI.getMessageManager().reportSuccess("User-->" + urs + " : ");

}

i am getting output like : User-->[Ljava.lang.String;@7ddce0cc; , but it is not showing currently logged inusers.

how can i acheive this?

Thanks

Venkat.

Former Member
0 Kudos

Hi Venkat,

Please correct your code as


int in = urs.length;
for(int i=0; i<in;i++){
wdComponentAPI.getMessageManager().reportSuccess("User-->" + urs + " : ");// replace the urs with urs<i>
}

with this one


int in = urs.length;
for(int i=0; i<in;i++){
wdComponentAPI.getMessageManager().reportSuccess("User-->" + urs<i> + " : ");
}

Regards

Jeetendra

Former Member
0 Kudos

Oh yes, printing usr would give the string array for all the logged in users. But, usr[int index] would give the user at index 'index' of the string array. So, change suggested by Dream4Desire is corect.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi venkat,

You can Achive this as follows...


try {
			IWDClientUser wdUser = WDClientUser.getCurrentUser();

		} catch (WDUMException e) {
		}
		try {

			String roleId, uniqueName, displayName = null;
			IUser currentUser = WDClientUser.getCurrentUser().getSAPUser();
			String User = WDClientUser.getCurrentUser().getClientUserID();
			String[] str = User.split(".");
			Iterator<String> rolesAssignedToUser = currentUser.getRoles(true);

			while (rolesAssignedToUser.hasNext()) {

				roleId = rolesAssignedToUser.next();

				displayName = UMFactory.getRoleFactory().getRole(roleId)
						.getDisplayName();
				String uName[] = displayName;
			}

After this by accessing the uName[]'s element you can get the logged in users. Let me know if you need more help on this,

Regards

Jeetendra

Former Member
0 Kudos

Hi Jeetendra,

Thank you for your quick response, i have used same code, what u have mentioned in your reply.

But it is displaying all roles in portal, but i do not want roles, i want only currently logged in users in portal.

please let me know, if my question not understandble.. i will explain again.

i am waiting for your reponse.

Thank you

Venkat.