cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect user to a custom "logoff" page after 10 minutes of user inactivity

Former Member
0 Kudos

Hi,

I have a portal application which uses the logged in user. If the user remains inactive for 10mins, I want to automatically logoff the user and redirect him to a custom logoff page (URL).

I have tried expiring the session id, but nothing happens (the user is still not logged out). While using sap logon ticket, the user is logged off irrespective of being active or inactive.

Both these don't suffice my requirement.

I want the user to be logged off and automatically redirected to a URL, only if he is inactive.

Any help in this regard will be highly appreciated.

Thanks,

Ajay

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ajay,

Can you explain how do u expire session id.

thanks you,

Regards

Vijai

Former Member
0 Kudos

Hi Vijai,

I changed the <session-timeout> to 10 in WEB-INF\web.xml

Thanks,

Ajay

0 Kudos

Hi,

Setting session timeout in web.xml only releases the current users session, which will then release all datas stored in this session. But this does not have any influence on users logon ticket, while the ticket validity is by default set to 8 hours in UME and with in this 8 hours every time a users session gets expired, a new session is created for the user on demand.

So the only way would be to have javascript that logsoff users after 10 min inactivity.

So create an IView and place the javascript that calls logoff component after 10 min of inactivity.

Add this IView to your Frameworkpage and set this IView to invisible, so that the end users do not see any visual part of IView like tray and buttons.

Regards,

Praveen Gudapati

Former Member
0 Kudos

Hi Praveen,

Thanks for your answer. So that means, setting the session timeout and setting the lifetime of the sap logon ticket wouldn't help me in logging off and redirecting the user after 10 mins of inactive time.

Can you please tell me more about the javascript code required to log off the user? Code snippet would be great, since I am new to this.

Thanks,

Ajay

0 Kudos

Hi,

One more idea apart from writing javascript is to implement a portal component and add it to your frameworkpage and set it to invisible.

The logic that should be implemented is in this thread, check reply from Ganesan:

You should call the LogOutComponent in your Javascript by setting some timer in javascript:

/irj/servlet/prt/portal/prtroot/com.sap.portal.masthead.LogOutComponent?logout_submit=true

Regards,

Praveen Gudapati

Former Member
0 Kudos

Hi Praveen,

I saw the reply from Ganesan S in that thread. There he has already given the code to call the LogOutComponent when the session expiry time exceeds 10mins. I have added the expireSession() method in my JSPDynpage. But where do I call this method expireSession(), so that it checks for the expiry?

Thanks,

Ajay

0 Kudos

Hi,

Call it in your doProcessBeforeOutput() method.

But for this you need not use JSPDynpage as there is no JSP to show here.

You can either use DynPage or AbstractPortalComponent.

If you create your component which implements AbstractPortalComponent then call the expireSession methd in doContent() method.

Regards,

Praveen Gudapati

Former Member
0 Kudos

Hi Praveen,

This is what I did. Please find the doProcessBeforeOutput() method below:

		public void doProcessBeforeOutput() throws PageException {
			IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
			IPortalComponentResponse response = (IPortalComponentResponse) this.getResponse();
			
			long lastAccessedTime=request.getServletRequest().getSession().getLastAccessedTime();
			Date currentDate = new Date();
			Calendar currentDateCal = new GregorianCalendar();
			currentDateCal.setTime(currentDate);
			long systemTime = currentDateCal.getTimeInMillis();
			long sessionExpiryTime = systemTime - lastAccessedTime;
			long sessionExpiryTimeProp = 40; //dont hard code.get from property file
			if(sessionExpiryTime >= sessionExpiryTimeProp)
			{
				try
				{
					String sessionExpiryPage ="/irj/servlet/prt/portal/prtroot/com.sap.portal.masthead.LogOutComponent?logout_submit=true";
//**** Code same as written by Ganesan S. Unable to write it in here, cause SDN is throwing some error.

response.write("</script>");
				}catch(Exception e)
				{
				//
				}
			}
			else{
			
			
			if (navigation == 1)
			{
				this.setJspName("paymentHistoryAll.jsp");
			}
			else
			{
				this.setJspName("paymentHistory.jsp");
			}
			}
		}

But the portal application is not working as expected. Sometimes it doesn't logoff even if i keep it inactive for 20 mins, and sometimes it logoff within a few seconds.

Any idea why this is happening?

Thanks,

Ajay

0 Kudos

Hi,

Your sessionExpiryTimeProp = 40, so why do you expect it to expire in 20 min?

Do you still have session timeout 10 min in your web.xml? Also set 20 min here.

Correct them to see if this works.

I also doubt if accessing lastAccessedTime from session is the right way to do this, as when ever the session expires depending on the session timeout in web.xml, a new session is created and the lastAccessedTime in the new session object should be currently accessed time.

So if all this does not help. try the javascript way to solve this problem.

Regards,

Praveen Gudapati

Former Member
0 Kudos

Hi Praveen,

I have set the session timeout in web.xml. But, the behaviour of this code is very inconsistent. Initially when I opened my application these were the values:

Session Expiry Time Property: 20

Session Expiry Time: 15

System Time: 1210137417812

Last Accessed Time: 1210137417797

Now within a few seconds, when I clicked on a link in my application, the Session Expiry Time became 76, and logged me out. Even I think, this might not be the right way to go ahead. Could you please tell me more about the javascript to do this?

Thanks,

Ajay

0 Kudos

Hi,

You should use window.setTimeout function and call the logoff in a function which is call when timeout occurs.

Check this for example:

http://javascript.about.com/od/reference/g/ssettimeout.htm

Do some googling for more examples.

Regards,

Praveen Gudapati

Former Member
0 Kudos

Hi Praveen,

I found the following code.

(Once again sorry, not able to attach the code here cause of sdn error. Please check Johnny Ramondino's 2nd reply in this thread [|]

I am not sure how to customize this for my requirement. I want to logoff and redirect to a custom screen after session timeout. Any idea?

Thanks,

Ajay

Answers (0)