On Sunday, August 10, 2014, Wolfgang Knauf wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think my<br>
basic question should be &quot;what is the unauthenticatedIdentity used<br>
for?&quot;</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote><div><br></div><div>Afaik the unauthenticated identity that&#39;s exposed to user code is a very unfortunate result of the fact that whoever wrote the first EJB spec thought it was a good idea to add the requirement &quot;never null&quot; to the return value of EJBContext#getCallerPrincipal.</div>
<div><br></div><div>I&#39;m sure it was done with the best intentions, but without also defining a constant that we can use to compare to (ie via a reference) OR an explicit &quot;isCallerAuthenticated&quot; method, this has been nothing but a world of hurt.</div>
<div><br></div><div>The problem is that now there&#39;s no real good way to check if a user is authenticated in EJB. A null return would be a good method, but since that value is mysteriously not allowed the container has to use a regular principal. You should then compare the name of this principal to whatever the container has decided to use to determine if the user is authenticated or not.</div>
<div><br></div><div>This is a recipe for disaster, since without reserving a name, any name the container chooses could be a valid name in the application domain. It just can&#39;t work this way.</div><div><br></div><div>
As a workaround some containers like JBoss offer the option to remap the name to something, should it clash.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
. If this question is answered, the next question could be &quot;how<br>
could one use it in a web app or application client?&quot;</blockquote><div><br></div><div>See above, to test if the user is authenticated or not.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I tried to call HttpServletRequest.authenticate() in an unsecured JSP<br>
page, and this redirected me to my login form - so no help ;-).</blockquote><div><br></div><div>This is because the SAM or login module that you configured wasn&#39;t instructed to &quot;do nothing&quot; ;) </div><div><br>
</div><div>But my mentioning of request#authenticate was just an explanation of how a SAM could &quot;do nothing&quot; even after an explicit request for authentication. A SAM is a special case here since it&#39;s always called for every request (just like a Servlet Filter). If I&#39;m not mistaken, JBoss&#39; proprietary login modules are only called when authentication is explicitly required.</div>
<div><br></div><div>Kind regards,</div><div>Arjan</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Best regards<br>
<br>
Wolfgang<br>
<br>
-------- Original-Nachricht --------<br>
Betreff: Re: [undertow-dev] &quot;unauthenticatedIndentity&quot; in Undertow<br>
Von: arjan tijms &lt;<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;arjan.tijms@gmail.com&#39;)">arjan.tijms@gmail.com</a>&gt;<br>
An: Wolfgang Knauf &lt;<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;wolfgang.knauf@gmx.de&#39;)">wolfgang.knauf@gmx.de</a>&gt;<br>
Kopie (CC): &quot;<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;undertow-dev@lists.jboss.org&#39;)">undertow-dev@lists.jboss.org</a>&quot; &lt;<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;undertow-dev@lists.jboss.org&#39;)">undertow-dev@lists.jboss.org</a>&gt;<br>

Datum: 09.08.2014 14:33<br>
<br>
&gt; Hi,<br>
&gt;<br>
&gt; Although it&#39;s not directly what you asked, one thing which you may want<br>
&gt; to take into account is that in the web layer (via HttpServletRequest)<br>
&gt; the user/caller principal corresponding to the unauthenticated identity<br>
&gt; is always null. When using the EJBContext that same user/caller<br>
&gt; principal is something container specific (although contrary to the web<br>
&gt; layer never null).<br>
&gt;<br>
&gt; EJB is underspecified here (just as the run-as principal). Likewise, the<br>
&gt; way in which a security context established in the web layer propagates<br>
&gt; to EJB is not clear either. There&#39;s a vague paragraph about a security<br>
&gt; domain that should be consulted, which JBoss takes very literally (for<br>
&gt; secured beans it attempts to re-authenticate instead of propagating the<br>
&gt; established context), for non-secured beans it doesn&#39;t do this.<br>
&gt;<br>
&gt; Finally there are a couple of implementation differences between JBoss&#39;<br>
&gt; native login modules and the Java EE standard JASPIC ones. For JASPIC<br>
&gt; you would call HttpServletRequest.authenticate() and the &quot;login module&quot;<br>
&gt; (SAM) would pass a null to the CallerPrincipalCallback in order to<br>
&gt; establish the unauthenticated identity.<br>
&gt;<br>
&gt; Hope this somehow helps.<br>
&gt;<br>
&gt; On Friday, August 8, 2014, Wolfgang Knauf &lt;<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;wolfgang.knauf@gmx.de&#39;)">wolfgang.knauf@gmx.de</a><br>
&gt; &lt;mailto:<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;wolfgang.knauf@gmx.de&#39;)">wolfgang.knauf@gmx.de</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     Hi guys,<br>
&gt;<br>
&gt;     I try to sort out the &quot;unauthenticatedIdentity&quot; feature for JAS login<br>
&gt;     modules in WildFly 8.<br>
&gt;     To my understanding, when logging in without username/password, the<br>
&gt;     login module should fallback to this &quot;unauthenticatedIndentity&quot;, which<br>
&gt;     can only access public content (e.g. unsecured or @PermitAll ejb<br>
&gt;     methods).<br>
&gt;<br>
&gt;     But without a login, my public ejb method shows that<br>
&gt;     &quot;this.sessionContext.getCallerPrincipal().getName()&quot; returns<br>
&gt;     &quot;anonymous&quot;, which is NOT the &quot;unauthenticatedIdentity&quot; value.<br>
&gt;     And &quot;httpRequest.login(null, null)&quot; will fail because of the Undertow<br>
&gt;     implementation.<br>
&gt;<br>
&gt;     How can a switch to the user name declared in the<br>
&gt;     &quot;unauthenticatedIdentity&quot;?<br>
&gt;<br>
&gt;     Same question e.g. here: <a href="https://community.jboss.org/thread/237899" target="_blank">https://community.jboss.org/thread/237899</a><br>
&gt;<br>
&gt;     Seems I have a basic misunderstanding about this ;-), but I don&#39;t find a<br>
&gt;     clear explanation in the web...<br>
&gt;<br>
&gt;     Best regards<br>
&gt;<br>
&gt;     Wolfgang Knauf<br>
&gt;     _______________________________________________<br>
&gt;     undertow-dev mailing list<br>
&gt;     <a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;undertow-dev@lists.jboss.org&#39;)">undertow-dev@lists.jboss.org</a> &lt;javascript:;&gt;<br>
&gt;     <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br>
&gt;<br>
_______________________________________________<br>
undertow-dev mailing list<br>
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;undertow-dev@lists.jboss.org&#39;)">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br>
</blockquote>