<div dir="ltr"><div><div>Hi, <br><br></div>Marek, the tips of building a simple redirect servlet protected by a user role constraint and let the other servlets unconstrained is working like a charm. This simple servlet act as a redirect point to ensure keycloak adapter handling of authentication without writing new code. A perfect solution in fact.<br><br></div>Thank you very much for your support, best regards, Jérôme.<br></div><br><div class="gmail_quote">Le jeu. 23 avr. 2015 à 18:34, Bill Burke &lt;<a href="mailto:bburke@redhat.com">bburke@redhat.com</a>&gt; a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Please read this:<br>
<br>
<a href="http://docs.jboss.org/keycloak/docs/1.2.0.Beta1/userguide/html/ch08.html#jboss-adapter" target="_blank">http://docs.jboss.org/keycloak/docs/1.2.0.Beta1/userguide/html/ch08.html#jboss-adapter</a><br>
<br>
add a @SecurityDomain(&quot;keycloak&quot;) to your EJB and it will pick up the<br>
Keylcoak context.<br>
<br>
On 4/23/2015 12:16 PM, Marek Posolda wrote:<br>
&gt; You&#39;re not wrong. With ServletOAuthClient you have control when you<br>
&gt; redirect user to the KC login screen. But you&#39;re completely independent<br>
&gt; on Wildfly container security layers, hence no propagation to EJB layer.<br>
&gt;<br>
&gt; If ServletOAuthClient is good for you, depends on the usecase you want<br>
&gt; to achieve. Maybe it is better for you to add some security-constraints<br>
&gt; URL to your web.xml  (for example &quot;/my-protected-url&quot;) and you will<br>
&gt; redirect your application to /my-protected-url (with<br>
&gt; httpResponse.sendRedirect) whenever you want your application to be<br>
&gt; logged with keycloak. Then once KC authentication is finished and your<br>
&gt; application will visit &quot;/my-protected-url&quot; as authenticated user, you<br>
&gt; will redirect back to the original URL before authentication.<br>
&gt;<br>
&gt; Not sure if EJB propagation will happen once you&#39;re authenticated, but<br>
&gt; visit unprotected URL though... But at least you can give it a shot.<br>
&gt;<br>
&gt; Marek<br>
&gt;<br>
&gt; On 23.4.2015 15:35, Jérôme Blanchard wrote:<br>
&gt;&gt; Hi,<br>
&gt;&gt; I wonder that the Servlet OAuth Client won&#39;t propagate authentication<br>
&gt;&gt; to wildfy EJB layer... Am I wrong ?<br>
&gt;&gt; Jérôme.<br>
&gt;&gt;<br>
&gt;&gt; Le mar. 21 avr. 2015 à 18:13, Marek Posolda &lt;<a href="mailto:mposolda@redhat.com" target="_blank">mposolda@redhat.com</a><br>
&gt;&gt; &lt;mailto:<a href="mailto:mposolda@redhat.com" target="_blank">mposolda@redhat.com</a>&gt;&gt; a écrit :<br>
&gt;&gt;<br>
&gt;&gt;     You can take a look at our examples for how to use<br>
&gt;&gt;     ServletOAuthClient. Hopefully it could help with your usecase:<br>
&gt;&gt;     <a href="https://github.com/keycloak/keycloak/tree/master/examples/demo-template/third-party" target="_blank">https://github.com/keycloak/keycloak/tree/master/examples/demo-template/third-party</a><br>
&gt;&gt;     <a href="https://github.com/keycloak/keycloak/tree/master/examples/demo-template/third-party-cdi" target="_blank">https://github.com/keycloak/keycloak/tree/master/examples/demo-template/third-party-cdi</a><br>
&gt;&gt;<br>
&gt;&gt;     Marek<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;     On 21.4.2015 12:14, Jérôme Blanchard wrote:<br>
&gt;&gt;&gt;     Hi all,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     I&#39;m trying to protect a servlet application which can be accessed<br>
&gt;&gt;&gt;     either as anonymous user and as authenticated user. Some<br>
&gt;&gt;&gt;     resources are protected and my application takes in charge the<br>
&gt;&gt;&gt;     access control (not role based) so I can&#39;t use the war protection<br>
&gt;&gt;&gt;     using role user constraint.<br>
&gt;&gt;&gt;     In this case I&#39;ve removed the role constraint in the web.xml and<br>
&gt;&gt;&gt;     the keycloak wildfly (undertow) adapter let me access the<br>
&gt;&gt;&gt;     application as unauthentified user (anonymous) which is perfect.<br>
&gt;&gt;&gt;     What I want to handle on some AccessDeniedException is to<br>
&gt;&gt;&gt;     redirect the user to the authentication server manually. In this<br>
&gt;&gt;&gt;     case, user authentified an come back to the protected URL but is<br>
&gt;&gt;&gt;     no more anonymous but a authentified user.<br>
&gt;&gt;&gt;     Is ther is a way to handle this redirection to the authentication<br>
&gt;&gt;&gt;     server manually (I don&#39;t know where to store the state variable<br>
&gt;&gt;&gt;     allowing keycloak wildfly adapter to handle properly the auth<br>
&gt;&gt;&gt;     redirect that include the code).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     Best regards, Jérôme.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     _______________________________________________<br>
&gt;&gt;&gt;     keycloak-user mailing list<br>
&gt;&gt;&gt;     <a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>  &lt;mailto:<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>&gt;<br>
&gt;&gt;&gt;     <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; keycloak-user mailing list<br>
&gt; <a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt;<br>
<br>
--<br>
Bill Burke<br>
JBoss, a division of Red Hat<br>
<a href="http://bill.burkecentral.com" target="_blank">http://bill.burkecentral.com</a><br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</blockquote></div>