<?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>Wed, 09 Oct 2019 05:05:09 -0400</lastBuildDate><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>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>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></channel></rss>