cancel
Showing results for 
Search instead for 
Did you mean: 

Get the last login date of portal users

Former Member
0 Kudos

i need to find out the last login date of all the portal users

i tried the below code

IUserFactory iuf;

ISearchResult isr;

IUser user;

String userid;

try{

iuf = UMFactory.getUserFactory();

isr = iuf.getUniqueIDs();

int i=0;

while(isr.hasNext())

{

userid = (String)isr.next();

user = iuf.getUser(userid);

IUserAccount[] IUF = user.getUserAccounts();

Date lastLogin = IUF[0].getPreviousSuccessfulLogonDate();

wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(user.getDisplayName()"------"lastLogin);

i=i+1;

}

wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(i+"");

}

its showing null for many of the users.

Please advise

AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Could you help me with the code for that.

Thanks

AM

former_member194668
Active Participant
0 Kudos

Hi Anoop,

1. Login to portal -> go to System Adminstration -> System Configuration -> UME Configuration -> Select 'User Admin UI' tab and click on Modify Configuration.

In the property "Administrator-Managed Custom Attributes:" add the following value:

<yourOwnNameSpace>:LastLogonDate

If there is already an attribute, seperate it by semicolon.

2. Restart the server after the above change.

3. Modify the Mast head par file ... Add the following fucntion and call it.

private void lastLogonDate(IPortalComponentRequest request)	{
	try	{			
		String userid = request.getUser().getUniqueID();
		IUserMaint usermt = UMFactory.getUserFactory().getMutableUser(userid);
		if(usermt!=null)	{
			String lastLogonDate = new SimpleDateFormat("EEE, MM/dd/yyyy HH:mm:ss").format(new Date());
			String[] lld = new String[1];
			lld[0] = lastLogonDate;
			usermt.setAttribute("<yourOwnNameSpace>", "LastLogonDate", lld);
			usermt.save();
			usermt.commit();
		}
	} catch(Exception ex)	{
	}
}

-Aarthi

Former Member
0 Kudos

Hi aarthi,

I am able to store the lastlogon date of the portal user, using the above code.

How to get the stored date and show it on the portal as "Previous Logon Date".

Regards

Ponnusamy

Answers (3)

Answers (3)

former_member189631
Active Contributor
0 Kudos

Hi,

Please use IUserAccount ot IUserMaint

Ram

former_member194668
Active Participant
0 Kudos

Hi Anoop,

The last logon date is not automatically populated in the recent versions

https://help.sap.com/javadocs/NW04S/current/se/index.html

-


getPreviousSuccessfulLogonDate

public java.util.Date getPreviousSuccessfulLogonDate()Deprecated.

get previous sucessful logon date NOTE: This attribute is not automatically updated during login.

Returns:

The PreviousSuccessfulLogonDate value

-


This is due to the performance issues at logon.

And this field is also not shown in the User Administration.

For this reason (with fear that the original field may be removed) we created a custom attribute and started populating using the mast head iView par file.

-Aarthi

Former Member
0 Kudos

Hi ,

just replace your logic with this code

The method getRemoteUser() of the HttpServletRequest gives the username of the client. With the remote useru2019s name, a servlet can save information about each client. Over the long term, it can remember each individualu2019s preferences. For the short term, it can remember the series of pages, viewed by the client and use them to add a sense of state to a stateless HTTP protocol.

A simple servlet that uses getRemoteUser() can greet its clients by name and remember when each last logged in as shown in the example below:

import java.io.*;

import java.sql.Date;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class PersonalizedWelcome extends HttpServlet{

Hashtable accesses = new Hashtable();

public void doGet(HttpServletRequest req,HttpServletResponse res)

throws ServletException,IOException{

res.setContentType("text/plain");

PrintWriter out= res.getWriter();

// Some introductory HTML...

String remoteUser = req.getRemoteUser();

// See if the client is allowed

if(remoteUser == null){

out.println("Welcome");

} else{

out.println("Welcome " + remoteUser + "!");

Date lastAccess = (Date)accesses.get(remoteUser);

if(lastAccess==null){

out.println("This last visit was " + accesses.get(remoteUser));

}

if(remoteUser.equals("Rohit")){

out.println("Shall we play a game");

}

accesses.put(remoteUser, new Date());

}

//continue handling the request

}

}

Regards ,

venkat p