<!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;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><html></p><p><head></p><p>  <title>HTTP 401</title> <!-- Do not remove --></p><p></head></p><p><body></p><p><form method="POST" action="j_security_check"></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>  <center/></p><p>  <br><br></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>  <div style="font-family:sans-serif;border:1px solid black; width:270;padding:15px;"></p><p>    <h2>BPM Console Server</h2></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    <table with=250></p><p>    <tr></p><p>      <td>Username:</td></p><p>      <td><input type="text" name="j_username"></td></p><p>    </tr></p><p>    <tr></p><p>      <td>Password:</td></p><p>      <td><input type="password" name="j_password"></td></p><p>    </tr></p><p>    <tr></p><p>      <td></td></p><p>      <td align=right><input type="submit"/></td></p><p>    </tr></p><p>  </table></p><p>  </div></p><p></form></p><p></body></p><p></html></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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;"> </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;"> </p><p> try</p><p>    {</p><p>      rb.sendRequest("j_username="+user+"&j_password="+pass, </p><p>                new RequestCallback()</p><p>          {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            public void onResponseReceived(Request request, Response response)</p><p>            {</p><p>              ConsoleLog.debug("postLoginCredentials() HTTP "+response.getStatusCode());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>              if(response.getText().indexOf("HTTP 401")!=-1) // HACK</p><p>              {</p><p>                if (callback != null)</p><p>                  callback.onLoginFailed(request, new Exception("Authentication failed"));</p><p>                else</p><p>                  throw new RuntimeException("Unknown exception upon login attempt");</p><p>              }</p><p>              else if(response.getStatusCode()==200) // it's always 200, even when the authentication fails</p><p>              {</p><p>                DeferredCommand.addCommand(</p><p>                    new Command()</p><p>                    {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                      public void execute()</p><p>                      {</p><p>                        requestAssignedRoles();</p><p>                      }</p><p>                    }</p><p>                );</p><p>              }</p><p>            }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>My code in EJB for invoke service j_security_check is:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span>  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>          HttpURLConnection connection = (HttpURLConnection) url.openConnection();</p><p>          connection.setRequestMethod(POST);</p><p>          connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");</p><p>        connection.addRequestProperty("j_password", "krisv"); </p><p>        connection.addRequestProperty("j_username", "krisv"); </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          // do request</p><p>          connection.connect();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The response is error LoginFailed.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The user krisv is ok for gwt-console-server.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Someone can help me with this.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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>