<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: REST API and JSESSIONID</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid</link><description>&lt;p&gt;Hi Ivy Team,&lt;/p&gt;
&lt;p&gt;Is there a way to get the JSESSIONID (or the whole cookie itself) of the logged in user ?&lt;/p&gt;
&lt;p&gt;I want to build a rest method which is authenticating the user. 
I need to return the cookie, so that next requests are authenticated&lt;/p&gt;
&lt;p&gt;BR,
Yordan&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 11 Oct 2019 05:32:11 -0400</lastBuildDate><item><title>Comment by SupportIvyTeam on SupportIvyTeam's answer</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4101</link><description>&lt;p&gt;Do it directly in ivy.yaml in the configuration folder, yes this should also work in designer.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Fri, 11 Oct 2019 05:32:11 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4101</guid></item><item><title>Comment by Stelt0 on SupportIvyTeam's answer</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4087</link><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can I test this on the Designer ?
Is it equivalent if I configure it in app-designer.yaml ?&lt;/p&gt;
&lt;p&gt;if I set log the getHttpSessionIdentifier and getSessionUserName in the two requests I get again the same behavior &lt;/p&gt;
&lt;p&gt;Ivy.log().info(Ivy.request().getSession().getHttpSessionIdentifier());
Ivy.log().info(Ivy.session().getSessionUserName());&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/aaaa.JPG"&gt;&lt;/p&gt;
&lt;p&gt;BR,
Yordan&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stelt0</dc:creator><pubDate>Wed, 09 Oct 2019 09:19:24 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4087</guid></item><item><title>Answer by SupportIvyTeam</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid/4085</link><description>&lt;p&gt;Hi Yordan&lt;/p&gt;
&lt;p&gt;I can now reproduce your problem and see your use case!&lt;/p&gt;
&lt;p&gt;I think we have a bug there because on login we change the session id and we then do not map the correct session.
As workaround you could disable RenewIdOnLogin like this in ivy.yaml:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Session:
  RenewIdOnLogin: false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the follwowing code you can get the current http session id:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Ivy.request().getSession().getHttpSessionIdentifier();
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Wed, 09 Oct 2019 05:05:09 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid/4085</guid></item><item><title>Comment by Reguel Wermelinger on Stelt0's answer</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4079</link><description>&lt;p&gt;Some documentation to start with valves can be found here : &lt;a href="https://developer.axonivy.com/doc/latest/engine-guide/integration/web-application-firewall.html"&gt;https://developer.axonivy.com/doc/latest/engine-guide/integration/web-application-firewall.html&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 08 Oct 2019 03:57:12 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4079</guid></item><item><title>Comment by Reguel Wermelinger on Stelt0's answer</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4078</link><description>&lt;p&gt;Hi Yordan. Glad to hear on your success on providing a custom request filter to transform headers. Currently I do not have the time do drive further analysis why the session is not overtaken. But I'm confident that you can find the cause quickly by using a class decompiler + debugger to analyse the execution of our ApplicationSessionRequestFilter. The tracing on which terms the existing session are overtaken should be easy to see in there. 
If nothing works. You could try to handle the issue in a global tomcat Valve : which is in charge not only for the rest stack, but for the whole webserver.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 08 Oct 2019 03:56:12 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4078</guid></item><item><title>Answer by Stelt0</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid/4076</link><description>&lt;p&gt;Hi Reguel,&lt;/p&gt;
&lt;p&gt;I was able to add Authorization Basic  header before ApplicationSessionRequestFilter.
In result, the session of the user was changed based on this header.&lt;/p&gt;
&lt;p&gt;However, the returned cookie form this request, is still not valid for the next calls ... ) the second call is authenticated as Developer)&lt;/p&gt;
&lt;p&gt;I assume that this is a bug.&lt;/p&gt;
&lt;p&gt;Here how you can reproduce it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;create project myapp with two REST endpoints (require authentication) (/ivy/api/myapp/loginCall and /ivy/api/myapp/checkCurrentUser); in both of them just log Ivy.session().getSessionUserName()&lt;/li&gt;
&lt;li&gt;create user -&amp;gt; allan:allan&lt;/li&gt;
&lt;li&gt;add this code snippet as index2.html and place it in \AxonIvyDesigner7.4.0\webapps\ivy&lt;/li&gt;
&lt;li&gt;test it on &lt;a href="http://localhost:8081/ivy/index2.html"&gt;http://localhost:8081/ivy/index2.html&lt;/a&gt; (clean cache/session first)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;html:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta charset="UTF-8"&amp;gt;
&amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;
&amp;lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;

    function loginCall() {
    var authToken = btoa('allan:allan'); //user and passowrd

    return $.ajax({
      url: "/ivy/api/myapp/loginCall",
      type: 'GET',
      headers:{
            'X-Requested-By': 'myapp',
            'Content-Type':'application/json',
            'Authorization': 'Basic ' + authToken
        },
      dataType: 'json'
    });
  }

  function checkProfile() {

    return $.ajax({
      url: "/ivy/api/myapp/checkCurrentUser",
      type: 'GET',
      headers:{
            'X-Requested-By': 'myapp',
            'Content-Type':'application/json'
        },
      dataType: 'json'
    });
  }

  $(document).ready(function() {

      loginCall()
      .done(function() {
        checkProfile()
          .done(function(response) {

          }).fail(function() {

          });
      }).fail(function() {

      });


  });

&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
check F12
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;BR, Yordan&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stelt0</dc:creator><pubDate>Mon, 07 Oct 2019 06:25:30 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid/4076</guid></item><item><title>Comment by Stelt0 on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4075</link><description>&lt;p&gt;Hi Reguel,&lt;/p&gt;
&lt;p&gt;It&lt;code&gt;s an excellent hint!
I&lt;/code&gt;ll try it out and will let you know.&lt;/p&gt;
&lt;p&gt;BR,
Yordan&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stelt0</dc:creator><pubDate>Fri, 04 Oct 2019 09:36:59 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4075</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid/4066</link><description>&lt;p&gt;If setting up a BASIC_AUTH header on client side is the main issues I think it should be possible to solve this in an additional &lt;code&gt;ContainerRequestFilter&lt;/code&gt; for the IVY Rest stack. &lt;/p&gt;
&lt;p&gt;Currently auth and session handling is done in : &lt;code&gt;ch.ivyteam.ivy.webserver.internal.rest.security.ApplicationSessionRequestFilter&lt;/code&gt;
&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/appSessionFilter.png"&gt;&lt;/p&gt;
&lt;p&gt;The request filter comes with a priority (in this case: 1'000). Therefore, it should be possible to provide an additional request filter that can change the request just before the default filter is executed.  Your custom filter could compensate the inabilities of the real client &amp;gt; transform form params into http_basic auth headers.&lt;/p&gt;
&lt;p&gt;To setup your custom filter as general extension for the ivyEngine REST stack you have to add the &lt;code&gt;@Provider&lt;/code&gt; annotation on the class body. See &lt;a href="https://answers.axonivy.com/questions/3412/how-can-i-use-jax-rs-containerrequestfilter-responsefilter-for-my-jax-rs-resources"&gt;https://answers.axonivy.com/questions/3412/how-can-i-use-jax-rs-containerrequestfilter-responsefilter-for-my-jax-rs-resources&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;...just an idea: I did not check it with an example. &lt;/p&gt;
&lt;p&gt;PS: be aware that big improvements from 7.4 REST stack have been ported back to the 7.0 LTS train recently. So ensure that you work with the latest hotfix version to benefit of the extension capabilities mentioned here.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 04 Oct 2019 02:11:02 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid/4066</guid></item><item><title>Comment by Stelt0 on Stelt0's question</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4060</link><description>&lt;p&gt;Hi Reguel,&lt;/p&gt;
&lt;p&gt;The client application (browser) cannot be modified to send basic auth header. it sends user and password and It works only with cookie after that.&lt;/p&gt;
&lt;p&gt;And the problem I have with Axon.Ivy is that if a REST method has @PermitAll it automatically creates a session and the returns a cookie for this session (and not for the user which I`m trying to login)&lt;/p&gt;
&lt;p&gt;Basically, the question is -&amp;gt; How to do a REST method which is login a user and returns back cookie for for it&lt;/p&gt;
&lt;p&gt;BR,
Yordan&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stelt0</dc:creator><pubDate>Thu, 03 Oct 2019 10:41:59 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4060</guid></item><item><title>Comment by Reguel Wermelinger on Stelt0's question</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4059</link><description>&lt;p&gt;If you design the API to only allow normal users : the login will automatically be done based on the HTTP_BASIC auth headers. What value do you have if you can enforce to send it as POST and handle auth on your own?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 03 Oct 2019 10:14:35 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4059</guid></item><item><title>Comment by SupportIvyTeam on Stelt0's answer</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4041</link><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Means this code runs on the proxy? I do not see your complete use case. How do you share then the JSESSION Cookie with the browser?
Please share Code as Text and not as Image, thanks.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Tue, 01 Oct 2019 08:14:14 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4041</guid></item><item><title>Comment by SupportIvyTeam on Stelt0's question</title><link>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4034</link><description>&lt;p&gt;If the client is in the browser the JSESSIONID works for both the web and the rest stack. But this is transparent and you have nothing to configure.
Generally it is not possible to get the JSESSION cookie, this would be a security risk.
But that I can give you a concrete answer you have to explane exactly what is your usecase...&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Tue, 01 Oct 2019 02:47:58 -0400</pubDate><guid>https://answers.axonivy.com/questions/4032/rest-api-and-jsessionid#4034</guid></item></channel></rss>