<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
secureResponse called before service invocation instead of after
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/atijms">arjan tijms</a> in <i>PicketBox Development</i> - <a href="https://community.jboss.org/message/799210#799210">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>WebJASPIAuthenticator in JBoss AS 7.1.1 and JBoss EAP 6.0.1 calls <em>secureResponse</em> right after <em>validateRequest</em> on a SAM has been called. The only intermediate code is registering the result of the callback handler with the container. The service invocation (e.g. calling a Servlet) is done afterwards, ie after the call to <em>secureResponse</em>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>See the following fragment:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">    <font color="navy"><b>if</b></font> (sam != <font color="navy"><b>null</b></font>) <font color="navy">{</font>
            result = sam.isValid(messageInfo, clientSubject, messageLayer, appContext, cbh);
        <font color="navy">}</font>
        <font color="darkgreen">// the authentication process has been a success. We need to register the principal, username, password and roles</font>
        <font color="darkgreen">// with the container</font>
        <font color="navy"><b>if</b></font> (result) <font color="navy">{</font>
            PasswordValidationCallback pvc = cbh.getPasswordValidationCallback();
            CallerPrincipalCallback cpc = cbh.getCallerPrincipalCallback();
            <font color="darkgreen">// get the client principal from the callback.</font>
            Principal clientPrincipal = cpc.getPrincipal();
            <font color="navy"><b>if</b></font> (clientPrincipal == <font color="navy"><b>null</b></font>) <font color="navy">{</font>
                clientPrincipal = <font color="navy"><b>new</b></font> SimplePrincipal(cpc.getName());
            <font color="navy">}</font>
            <font color="darkgreen">// if the client principal is not a jboss generic principal, we need to build one before registering.</font>
            <font color="navy"><b>if</b></font> (!(clientPrincipal <font color="navy"><b>instanceof</b></font> JBossGenericPrincipal))
                clientPrincipal = this.buildJBossPrincipal(clientSubject, clientPrincipal);
            this.register(request, response, clientPrincipal, authMethod, pvc.getUsername(),
                    <font color="navy"><b>new</b></font> String(pvc.getPassword()));
            <font color="navy"><b>if</b></font> (this.secureResponse)
                sam.secureResponse(messageInfo, <font color="navy"><b>new</b></font> Subject(), messageLayer, appContext, cbh);
        <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>However, section 3.8.3.3 of the JSR 196 (JASPIC) spec says that the semantics of <span class="s1">secureResponse</span> are as defined in Section 3.8.2.2, which thus means that <span class="s1">secureResponse</span> should be called <em>after</em> a service invocation. Figure 1.1 in Section 1.1 shows this as well, and the general flow as described is Section 3.8 also mentions this.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>So, in JBoss the sequence is </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">validateRequest -> secureResponse -> Invoke Service
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>While the spec seems to say it should be:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">validateRequest -> Invoke Service -> secureResponse
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In the reference implementation GlassFish the sequence is indeed the latter one.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/799210#799210">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in PicketBox Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2088">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>