Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Sharadha1
Active Contributor
5,741

Hi,

We all know that there is no standard solution provided by SAP to log out an idle user.After a number of futile search attempts in google/SDN for a solution, I set about to find a solution on my own. Find below the steps to create the simple portal component which tracks the user inactivity.


I have already  seen couple of solutions for this but they have minor issues and did not suit my requirements.


1. Portal user idle timeout using dialog windows - Client side solution => this solution does not seem to work for AJAX Framework in recent releases and did not track the user clicks, mouse movement etc. It worked only for Navigation event in portal. Basically, it will consider the user idle if he does not navigate. The user will be timed out

2. http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/309379b6-bb9b-2d10-feb1-91f2a7078... => Though this one says that it can track the user clicks, mouse movements etc, the logoff functionality did not work in NW portal 7.4.


My requirement is to track the user events in the content area as well before deciding if the user is idle or not.


The portal component which I have developed is very basic and uses Jquery. It tracks Key press, mouse movements in content area of the portal framework.


1. Go to Development Infrastructure perspective and create a EP DC


Click finish.

2. Create a 'Portal Application Object' in this EP DC.

Click Next. Select the DC created in step 1

Click Next. Choose Portal Component -> JSPDynPage

Click Next.  Enter the JSP class, package and file name.

Click Finish.

3. Open the TimeOut.jsp file under dist/PORTAL-INF/pagelet folder and copy the code below. Make sure that you place the relevant Jquery file under /scripts folder.

<html>

<head>

<% String mimeUrl = componentRequest.getWebResourcePath(); %>

  <script type="text/javascript" src="<%=mimeUrl%>/scripts/jquery-1.11.2.min.js"></script>

<script type="text/javascript">

var idleTime = 0;

$(document).ready(function () {

    //Increment the idle time counter every minute.

    idleInterval = setInterval(timerIncrement, 120000); // 2 minute

    //Zero the idle timer on mouse movement.

    $('body').mousemove(function (e) {

     idleTime = 0;

     document.querySelector('.content .value').innerHTML = idleTime + "mouse moved";

    });

    $('body').keypress(function (e) {

        idleTime = 0;

        document.querySelector('.content .value').innerHTML =idleTime +  "key press";

    });

    $('body').click(function() {

       idleTime = 0;

       document.querySelector('.content .value').innerHTML = idleTime + "mouse moved";

    });

});

function timerIncrement() {

    idleTime = idleTime + 1;

    document.querySelector('.content .value').innerHTML = idleTime;

    if (idleTime > 0) {

        if (confirm('Your session is inactive for the last 2 minutes. Press OK to log off. Press cancel to extend the session.') == true) {

          window.location.assign("/irj/servlet/prt/portal/prtroot/com.sap.portal.navigation.masthead.LogOutComponent?logout_submit=true");

      

        } else {

        idleTime = 0;

        document.querySelector('.content .value').innerHTML = idleTime

        }

  

     

    }

}

</script>

</head>

<body>

<div class="content">Status:  <span class='value'></span></div>

</body>

</html>

4. Build and Deploy the DC to the server.

5. Create an iview for the deployed application. You can preview and test before embedding it in the portal framework.

  Preview the iview and do not do any action on it. You can see the pop up below after 2 minutes.

6. Now you can place this iview in the framework page under 'Technical Hidden iviews Container'.

7. Save the Framework page. Log off and login to the portal.

As you can see, code is simple and timings and messages can be customised as per your requirements.

I have placed the following HTML element in the code so as to check if the mouse movements and user clicks are tracked or not.

<div class="content">Status:  <span class='value'></span></div>

Since you have placed the iview under hidden iviews, you will not be able to see this HTML element. If you want to debug , please move the iview to one of the other containers and make the component visible on the screen.

Feel free to comment any improvisations on this approach.

43 Comments
Labels in this area