<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">I tried it again with my application
      after deleting existing cookies and recreating the realm and
      indeed, it seems to use the underlying session.<br>
      <br>
      I guess with all the long living cookies in my history something
      got messed up. Configuring the session cookie name in web.xml does
      not work as far as I can tell, but that's a different problem.<br>
      <div class="moz-signature"><br>
        Mit freundlichen Grüßen,<br>
        <hr>
        <b>Christian Beikov</b><br>
      </div>
      Am 02.01.2015 um 08:34 schrieb Stian Thorgersen:<br>
    </div>
    <blockquote
      cite="mid:792210726.2563607.1420184087778.JavaMail.zimbra@redhat.com"
      type="cite">
      <pre wrap="">

----- Original Message -----
</pre>
      <blockquote type="cite">
        <pre wrap="">From: "Christian Beikov" <a class="moz-txt-link-rfc2396E" href="mailto:christian.beikov@gmail.com">&lt;christian.beikov@gmail.com&gt;</a>
To: "Stian Thorgersen" <a class="moz-txt-link-rfc2396E" href="mailto:stian@redhat.com">&lt;stian@redhat.com&gt;</a>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a>
Sent: Tuesday, 30 December, 2014 3:47:00 PM
Subject: Re: [keycloak-dev] Access original session

I am using the following versions:

  * Keycloak 1.0.4.Final
  * Wildfly 8.1.0.Final

Also it doesn't respect the cookie settings of the web.xml. I tried to
configure a different name for the cookie just to test it, but it didn't
change. When navigating to "/whatever.xhtml" I suddenly get the
configured cookie set.
It seems as if the Keycloak adapters wrap the HttpServletRequest to
expose a different session map when working with secured resources.
Which demo are you talking about? I would love to try it out so that I
can confirm if it has something to do with my setup or Keycloak.
</pre>
      </blockquote>
      <pre wrap="">
Keycloak should just be using the underlying http session and not do anything special to it. Do you have the same problem with HTTP basic?

The demo I'm referring to is the one that is bundled with the download, it's in examples/preconfigured-demo

</pre>
      <blockquote type="cite">
        <pre wrap="">
Mit freundlichen Grüßen,
------------------------------------------------------------------------
*Christian Beikov*
Am 30.12.2014 um 13:59 schrieb Stian Thorgersen:
</pre>
        <blockquote type="cite">
          <pre wrap="">
----- Original Message -----
</pre>
          <blockquote type="cite">
            <pre wrap="">From: "Christian Beikov" <a class="moz-txt-link-rfc2396E" href="mailto:christian.beikov@gmail.com">&lt;christian.beikov@gmail.com&gt;</a>
To: "Stian Thorgersen" <a class="moz-txt-link-rfc2396E" href="mailto:stian@redhat.com">&lt;stian@redhat.com&gt;</a>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a>
Sent: Tuesday, 30 December, 2014 1:45:13 PM
Subject: Re: [keycloak-dev] Access original session

Seems like my question wasn't clear enough.

I have the following config in my web.xml

      &lt;security-constraint&gt;
          &lt;web-resource-collection&gt;
&lt;web-resource-name&gt;Protected&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/protected/*&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint&gt;
              &lt;role-name&gt;user&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
      &lt;/security-constraint&gt;

      &lt;login-config&gt;
          &lt;auth-method&gt;KEYCLOAK&lt;/auth-method&gt;
          &lt;realm-name&gt;portfolio-webapp&lt;/realm-name&gt;
      &lt;/login-config&gt;

      &lt;security-role&gt;
          &lt;role-name&gt;user&lt;/role-name&gt;
      &lt;/security-role&gt;

Now when I navigate to e.g. "/protected/index.xhtml" I get redirected to
the Keycloak login. Unfortunately, the cookie which is set by the
Keycloak adapters after a succesful login, has the path "/protected"
set. When I navigate to "/whatever.xhtml" I obviously have no access to
the cookie since the browser doesn't send it.

How am I supposed to access the logged in user outside of the protected
area?

The session cookie (assuming you're talking about JSESSIONID) should be
set
to the context-path of your WAR not a specific protected resource.

Unfortunately I am experiencing that it is set to a different path.
</pre>
          </blockquote>
          <pre wrap="">Strange. I've just tried with our demo, which has a similar
security-constraint to yours, and it sets it to the context-path of the
WAR as expected.

Keycloak doesn't set this cookie itself, that's sorted by the JEE
container. Which Keycloak version and JEE server are you using?

</pre>
          <blockquote type="cite">
            <pre wrap="">Is your protected resources in the same WAR as the unprotected resources?

Yes, it's all in the same WAR.

Mit freundlichen Grüßen,
------------------------------------------------------------------------
*Christian Beikov*
Am 30.12.2014 um 13:38 schrieb Stian Thorgersen:
</pre>
            <blockquote type="cite">
              <pre wrap="">The session cookie (assuming you're talking about JSESSIONID) should be
set
to the context-path of your WAR not a specific protected resource. Is
your
protected resources in the same WAR as the unprotected resources?

----- Original Message -----
</pre>
              <blockquote type="cite">
                <pre wrap="">From: "Christian Beikov" <a class="moz-txt-link-rfc2396E" href="mailto:christian.beikov@gmail.com">&lt;christian.beikov@gmail.com&gt;</a>
To: <a class="moz-txt-link-abbreviated" href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a>
Sent: Sunday, 28 December, 2014 11:01:54 AM
Subject: [keycloak-dev] Access original session

Hello there!"

I have an application that has protected resources on the pattern
"/protected/*" and I receive a session cookie for the path "/protected",
which makes sense. Now my problem is, that I want the path of the cookie
to
be "/" so I can access the user information even outside of the
protected
resources.
Since I think this might introduce some problems, the only other way to
realize that I could think of is, to get access to the underlying
servlet
session. Not only would that session have to be created properly, which
I
am
not sure is happening when browsing in the protected resources, I would
also
need to access it on the server, so that I can save the currently logged
in
user into it.

Is there a possibility to access the servlet session within the Keycloak
context? If so, could you please share some code or point me to an API?
--

Mit freundlichen Grüßen,

Christian Beikov

_______________________________________________
keycloak-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-dev">https://lists.jboss.org/mailman/listinfo/keycloak-dev</a>
</pre>
              </blockquote>
            </blockquote>
            <pre wrap="">
</pre>
          </blockquote>
        </blockquote>
        <pre wrap="">

</pre>
      </blockquote>
    </blockquote>
    <br>
  </body>
</html>