<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Detect a user session is closing because of timeout</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout</link><description>&lt;p&gt;Hi everybody,&lt;/p&gt;
&lt;p&gt;Is there a way to detect a user session is closing because of a timeout?
There is the "unload" event that can be catched in an ULC Rich Dialog for performing some stuff when the user close a Dialog.
Is there something similar for a session timeout?&lt;/p&gt;
&lt;p&gt;If not it would be very usefull to have such a possibility.&lt;/p&gt;
&lt;p&gt;Thanks in advance
Emmanuel&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 14 Aug 2018 05:41:13 -0400</lastBuildDate><item><title>Answer by nhuuduong</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/3390</link><description>&lt;p&gt;This is my implementation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@ManagedBean
@SessionScoped
public class MySesssionBean {
    @PreDestroy
    public void destroy() {
        Ivy.log().fatal("Hi there");
        }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But we still got the error:
Caused by: ch.ivyteam.ivy.environment.EnvironmentNotAvailableException: Access to ivy environment outside a process request thread is not possible.&lt;/p&gt;
&lt;p&gt;Current thread: Thread[ContainerBackgroundProcessor[StandardEngine[ivy]],6,main]
    at ch.ivyteam.ivy.environment.Ivy.getIvy(Ivy.java:577)
    at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:556)
    at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:551)
    at ch.ivyteam.ivy.environment.Ivy.log(Ivy.java:413)&lt;/p&gt;
&lt;p&gt;We can't get any ivy environment here :(&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nhuuduong</dc:creator><pubDate>Tue, 14 Aug 2018 05:41:13 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/3390</guid></item><item><title>Answer by Jailson Brito</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2487</link><description>&lt;p&gt;Following your recommendation, I am registering my Session extension with a 'Program Start', it's properly detecting when the session is destroyed, and then my StartEventBean calls fireProcessStartEventRequest(). The 'Program Start' is being triggered but it's failing on the way to a "Login Dialog". Any ideas of what I am missing?&lt;/p&gt;
&lt;p&gt;All I need is to redirect to my "Login Dialog" on a session timeout.&lt;/p&gt;
&lt;p&gt;The error message:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;OutOfScopeException: Cannot access scoped [ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped [ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
  at ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager.class(DialogRuntimeManager.java:30)
  while locating ch.ivyteam.ivy.dialog.execution.DialogRuntimeManager

1 error
BpmError: ivy:error:system
RequestException: ivy:error:system
Process Start Event Bean SessionWatcher [class=ch.ivyteam.wf.session.SessionWatcherStartEventBean, path=13EACA2A989BCC3D/eventLink.ivp] fire has been failed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks in advance!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jailson Brito</dc:creator><pubDate>Thu, 09 Mar 2017 05:14:11 -0500</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2487</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2475</link><description>&lt;p&gt;it's not public API therefore there is no documentation for it. But the simple methods of theses interfaces should speak for themselves. Anyway here is a simple implementation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package ch.ivyteam.sample;

import ch.ivyteam.di.restricted.DiCore;
import ch.ivyteam.ivy.persistence.IPersistentTransaction;
import ch.ivyteam.ivy.persistence.PersistencyException;
import ch.ivyteam.ivy.security.ISecurityManager;
import ch.ivyteam.ivy.security.ISession;
import ch.ivyteam.ivy.security.ISessionExtension;

public class MyDemoSessionExtension implements ISessionExtension 
{

    public static void install()
    {
        DiCore.getGlobalInjector().getInstance(ISecurityManager.class)
           .addSessionExtension(new MyDemoSessionExtension());
    }

    @Override
    public void createSession(ISession session, IPersistentTransaction transaction)
            throws PersistencyException {
        System.err.println("created session "+session);
    }

    @Override
    public void destroySession(ISession session, IPersistentTransaction transaction)
            throws PersistencyException {
        System.err.println("session destroyed "+session);
    }

    @Override
    public void logoutSession(ISession session, IPersistentTransaction transaction,
            long currentTaskId) throws PersistencyException {
        System.err.println("session logout "+session);
    }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The easiest way to register this Session extension is with a 'Program Start' event bean that runs when the server is up and running. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 03 Mar 2017 09:33:30 -0500</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/2475</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/1362</link><description>&lt;p&gt;I did not test it: but I think that the ISessionExtension can do that job. &lt;/p&gt;
&lt;p&gt;See: ch.ivyteam.ivy.security.ISessionExtension.destroySession(ISession, IPersistentTransaction)&lt;/p&gt;
&lt;p&gt;And to register your extension: ch.ivyteam.ivy.security.ISecurityManager.addSessionExtension(ISessionExtension)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Mon, 15 Jun 2015 10:44:50 -0400</pubDate><guid>https://answers.axonivy.com/questions/1359/detect-a-user-session-is-closing-because-of-timeout/1362</guid></item></channel></rss>