<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Is there any possible way to switch SYSTEM session to another regular user's session in a ProgramStart execution?</title><link>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution</link><description>&lt;p&gt;In our project, we use &lt;code&gt;ProgramStart&lt;/code&gt; to implement &lt;code&gt;cron&lt;/code&gt; jobs. The executions will always be carried on by the SYSTEM user using only one &lt;code&gt;ISession(id = 0)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The problem is, we heavily store plenty of &lt;em&gt;Context Information&lt;/em&gt; (authentication token, user-session-specific data, etc) into &lt;code&gt;ISession.setAttribute()&lt;/code&gt;. It works well on normal situation with logged-in Ivy user. However, because in background jobs, there is only one session, each execution will interfere with each others, trying to &lt;code&gt;set&lt;/code&gt; and &lt;code&gt;get&lt;/code&gt; the &lt;em&gt;Context Information&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In addition, this happens the same with &lt;code&gt;Signals&lt;/code&gt; since execution of those also delegated to &lt;code&gt;SYSTEM&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I've tried to call &lt;code&gt;ivy.session.login()&lt;/code&gt; but it threw exception since Axon.ivy refuse to allow logging out of &lt;code&gt;SYSTEM&lt;/code&gt; user.&lt;/p&gt;
&lt;p&gt;My question is: Is there any possible way to switch from SYSTEM sessions to regular normal user's session?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 20 Jun 2018 02:29:54 -0400</lastBuildDate><item><title>Comment by Reto Weiss on haissam's answer</title><link>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#3335</link><description>&lt;p&gt;In case maps you use normal RequestStart process elements. This topic here talks about a ProgramStart. In a RequestStart you will not be able to get a runtime. This is something that is unique to ProgramStart. What is your use case?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Wed, 20 Jun 2018 02:29:54 -0400</pubDate><guid>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#3335</guid></item><item><title>Comment by Genzer Hawker on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#1784</link><description>&lt;p&gt;As of now, we don't have any. But it could be the case that we will introduce an on-demand feature to trigger the same background job. A &lt;code&gt;Signal&lt;/code&gt; would be broadcasted to run the process in additional to the existing &lt;code&gt;EventBean&lt;/code&gt;.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Genzer Hawker</dc:creator><pubDate>Fri, 27 May 2016 13:16:53 -0400</pubDate><guid>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#1784</guid></item><item><title>Comment by Reto Weiss on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#1783</link><description>&lt;p&gt;It's not planned for Signals yet. If there is a concrete common use case we can provide support for it in a future version.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Fri, 27 May 2016 10:11:46 -0400</pubDate><guid>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#1783</guid></item><item><title>Comment by Genzer Hawker on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#1782</link><description>&lt;p&gt;Oooh, I didn't know about this. Guess I need to read more the API then. Will there be support for such use case in &lt;code&gt;Signals&lt;/code&gt;? Thanks!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Genzer Hawker</dc:creator><pubDate>Fri, 27 May 2016 10:07:12 -0400</pubDate><guid>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution#1782</guid></item><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution/1781</link><description>&lt;p&gt;In a ProgramStart you can program which Session should be used to execute the process in the EventBean. The method &lt;code&gt;fireProcessStartEventRequest&lt;/code&gt; of the &lt;code&gt;IProcessStartEventBeanRuntime&lt;/code&gt; interface takes as first parameter an &lt;code&gt;ISession&lt;/code&gt;. The process will be executed in the context of this session. Most EventBean implementors simply give a null value for this Session. In this case the process is executed in the context of the SYSTEM session. To use another session do as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ISession session = runtime.createSession();
try
{
  runtime.fireProcessStartEventRequest(session, ...);
}
finally
{
  runtime.destroySession(session);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The method &lt;code&gt;createSession&lt;/code&gt; will create an annonymous session. There is also another &lt;code&gt;createSession&lt;/code&gt; method that takes two arguments so that you can specify a user and password to create a session with a user. 
Don't forget to destroy the session otherwise you have a session leak. &lt;/p&gt;
&lt;p&gt;For Signals there is no such solution available yet.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Fri, 27 May 2016 08:56:14 -0400</pubDate><guid>https://answers.axonivy.com/questions/1780/is-there-any-possible-way-to-switch-system-session-to-another-regular-user-s-session-in-a-programstart-execution/1781</guid></item></channel></rss>