Method call in addition to session logout in AEM | Community
Skip to main content
Level 4
June 20, 2023
Solved

Method call in addition to session logout in AEM

  • June 20, 2023
  • 3 replies
  • 2057 views

Requirement

Implementing session management

Session duration is 30 mins

After 30 mins, user session should be terminated and local data stored should be deleted.

For the logout functionality, I've written a separate servlet that will be triggered on click on 'Logout' button. It will delete all the local user data stored in AEM.

Now, my requirement is that if the user does not click on logout button and leave the session idle, session needs to logout after 30 mins automatically along with user data deletion. For the later part to happen, I need to call the method written in the servlet. How can I implement this?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by TarunKumar

Hi @goyalkritika ,

You can make use of Oak login token session expiration.

 

The steps to do that can be found in the below link

How to set the Oak login token session expiration | Adobe Experience Cloud


3 replies

New Member
June 20, 2023

HI @goyalkritika ,

 

you can try this by writing Javascript

Tanika02
Level 7
June 20, 2023

Hello @goyalkritika - 

 

You can follow below implementation approach : 

 

  1. Use JavaScript to detect user activity or inactivity on the client-side. You can listen for mouse movements, keyboard events, or any other user interactions to determine if the user is active or idle.

  2. When the user becomes inactive, start a timer using JavaScript's setTimeout() function. Set the timer to 30 minutes.

  3. In the timer callback function, make an AJAX request to your logout servlet or the desired endpoint to trigger the deletion of local user data in AEM.

  4. Additionally, If the user becomes active again before the timer expires, cancel the timer using JavaScript's clearTimeout function. You can listen for user activity events and cancel the timer whenever activity is detected.

Level 4
June 20, 2023

The duration of session does not depend on the user activeness or inactiveness. There is a fix 30 mins window for one session. 

My concern is how can I make a call to a method to delete the user data just after I'm logging out the user session at AEM end using Java.

Tanika02
Level 7
June 20, 2023

@goyalkritika  - 

 

 

var inactivityTimer; function resetTimer() { clearTimeout(inactivityTimer); inactivityTimer = setTimeout(logoutAndDeleteUserData, 30 * 60 * 1000); // 30 minutes } function logoutAndDeleteUserData() { // Make an AJAX call to your servlet endpoint for logout and data deletion // Example: // $.post('/path/to/your/servlet', function(data) { // // Handle the response // }); window.location.href = '/path/to/your/logout/page'; // Redirect the user to a logout page } // Start the initial timer when the page loads resetTimer();

 

Have you tried doing something like this? 

TarunKumar
Community Advisor
TarunKumarCommunity AdvisorAccepted solution
Community Advisor
June 21, 2023

Hi @goyalkritika ,

You can make use of Oak login token session expiration.

 

The steps to do that can be found in the below link

How to set the Oak login token session expiration | Adobe Experience Cloud


July 27, 2023

That helps to specify when a session should be expired, but what about triggering an action when a session is going to expire? Something similar to what the HttpSessionListener interface does? Is there something in AEM we can use to trigger an action when a session or a token is going to expire? 

 

I haven't been able to find a way to emulate this type of behavior.