<!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="http://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;">
    jbpm-console invocation of services & j_security_check
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/jfaggiano">Janina Faggiano</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/602570#602570">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I'm trying to invoke the services of the console without using the gwt client. </p><p>Whenever I request a service from my EJB throws me the following response.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;html&gt;</p><p>&lt;head&gt;</p><p>&#160; &lt;title&gt;HTTP 401&lt;/title&gt; &lt;!-- Do not remove --&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;</p><p>&lt;form method="POST" action="j_security_check"&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; &lt;center/&gt;</p><p>&#160; &lt;br&gt;&lt;br&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; &lt;div style="font-family:sans-serif;border:1px solid black; width:270;padding:15px;"&gt;</p><p>&#160;&#160;&#160; &lt;h2&gt;BPM Console Server&lt;/h2&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; &lt;table with=250&gt;</p><p>&#160;&#160;&#160; &lt;tr&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;td&gt;Username:&lt;/td&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;td&gt;&lt;input type="text" name="j_username"&gt;&lt;/td&gt;</p><p>&#160;&#160;&#160; &lt;/tr&gt;</p><p>&#160;&#160;&#160; &lt;tr&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;td&gt;Password:&lt;/td&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;td&gt;&lt;input type="password" name="j_password"&gt;&lt;/td&gt;</p><p>&#160;&#160;&#160; &lt;/tr&gt;</p><p>&#160;&#160;&#160; &lt;tr&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;td&gt;&lt;/td&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;td align=right&gt;&lt;input type="submit"/&gt;&lt;/td&gt;</p><p>&#160;&#160;&#160; &lt;/tr&gt;</p><p>&#160; &lt;/table&gt;</p><p>&#160; &lt;/div&gt;</p><p>&lt;/form&gt;</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I was checking out the code in jbpm-gwt-console project, and before invoking any service gwt client authenticates against the server to access the services with the following code.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> String formAction = config.getConsoleServerUrl() + "/rs/identity/secure/j_security_check";</p><p> RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, formAction);</p><p> rb.setHeader("Content-Type", "application/x-www-form-urlencoded");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> try</p><p>&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160; rb.sendRequest("j_username="+user+"&amp;j_password="+pass, </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new RequestCallback()</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void onResponseReceived(Request request, Response response)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConsoleLog.debug("postLoginCredentials() HTTP "+response.getStatusCode());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(response.getText().indexOf("HTTP 401")!=-1) // HACK</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (callback != null)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; callback.onLoginFailed(request, new Exception("Authentication failed"));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new RuntimeException("Unknown exception upon login attempt");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if(response.getStatusCode()==200) // it's always 200, even when the authentication fails</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DeferredCommand.addCommand(</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new Command()</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void execute()</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; requestAssignedRoles();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; );</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My code in EJB for invoke service j_security_check is:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>&#160; URL url = new URL("</span><a class="jive-link-external-small" href="http://localhost:8080/gwt-console-server/rs/identity/secure/j_security_check" target="_blank">http://localhost:8080/gwt-console-server/rs/identity/secure/j_security_check</a><span>");</span></p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;HttpURLConnection connection = (HttpURLConnection) url.openConnection();</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;connection.setRequestMethod(POST);</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection.addRequestProperty("j_password", "krisv"); </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection.addRequestProperty("j_username", "krisv"); </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;// do request</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;connection.connect();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The response is error LoginFailed.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The user krisv is ok for gwt-console-server.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Someone can help me with this.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/602570#602570">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>