I have my project with shiro and I need when closing inactivity timeout, pops out pop up warning the user that the session will close. At the moment I have shiro with Servlet Container
Asked
Active
Viewed 92 times
1 Answers
0
try using javascript to show a popup once timer expires here timeout stores timeout period and now run a timer and show a popup once timer expires. Demo code below but you have to customize it and it is not full code.
var timeout=<%= currentUser.getSession().getTimeout() %>;
var starttimer=timeout-60000; //+100000000;
var timerstep=1;//In minutes
var alertbefore=5;//In minutes
var logoutUrl="logout";//Url to logout
var militimerstep=timerstep*60*1000;
var sessionNoExpireMessage="Session will never expire!!!";
var sess_timer=window.setInterval(updateTimer,militimerstep);
$("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true) + " remaining ");
if(timeout<0)
{
clearInterval(sess_timer);
$("#timeout").html(sessionNoExpireMessage+ " remaining ");
}else{
$("#timeout").html( moment.duration(parseInt(starttimer,10)).humanize() + " remaining");
}
function updateTimer(){
console.log("In timer");
// alert(timeout);
if(timeout<0)
{
clearInterval(sess_timer);
$("#timeout").html(sessionNoExpireMessage);
return false;
}
starttimer = starttimer-militimerstep;
$("#timeout").html(moment.duration(parseInt(starttimer,10)).humanize() + " remaining");
$("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true));
if(starttimer<=0){
window.location.replace("${pageContext.request.contextPath}/"+logoutUrl);
window.location("${pageContext.request.contextPath}/"+logoutUrl);
}
if(starttimer<alertbefore*60*1000){
$("#session_alert").modal();
}
}
function updateSessionInfo(){
if(timeout<0)
{
return false;
}
ajaxCount--;
resetajaxView();
starttimer=timeout-60000;
$("#timeout").html(moment.duration(parseInt(starttimer,10)).humanize() + " remaining");
$("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true));
}

Dev
- 6,628
- 2
- 25
- 34