<!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;">
Problem with securing web service with ws security ( username token )
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/lmarczuk">Ćukasz Marczuk</a> in <i>JBoss Web Services</i> - <a href="http://community.jboss.org/message/560597#560597">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hello,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I'am trying to secure web service ( from ejb 3.0 stateless bean) and it is not working.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>here is my code :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Bean : </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@Stateless</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@SOAPBinding(style=SOAPBinding.Style.RPC)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@SecurityDomain("JBossWS")</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@EndpointConfig(configName = "Standard WSSecurity Endpoint")</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span>@WebService(name="Hello",targetNamespace = "</span><a class="jive-link-external-small" href="http://test" target="_blank">http://test</a><span>",serviceName = "HelloWSSService")</span></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class HelloBean implements IHello {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@WebMethod</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public String sayHello(String aName) {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">return "siemanko " + aName;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div></p><pre class="jive-pre"><code class="jive-code jive-java"><font color="darkgreen">// ... some imports</font>
 
@Stateless
@SOAPBinding(style=SOAPBinding.Style.RPC)
@SecurityDomain(<font color="red">"JBossWS"</font>)
@EndpointConfig(configName = <font color="red">"Standard WSSecurity Endpoint"</font>)
@WebService(name=<font color="red">"Hello"</font>,targetNamespace = <font color="red">"http://test"</font>,serviceName = <font color="red">"HelloWSSService"</font>)
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> HelloBean <font color="navy"><b>implements</b></font> IHello <font color="navy">{</font>
 
     @WebMethod
     <font color="navy"><b>public</b></font> String sayHello(String aName) <font color="navy">{</font>
          <font color="navy"><b>return</b></font> <font color="red">"siemanko "</font> + aName;
     <font color="navy">}</font>
 
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>interface : </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">@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@EndpointConfig(configName = <font color="red">"Standard WSSecurity Endpoint"</font>)
@WebService(name=<font color="red">"Hello"</font>,targetNamespace = <font color="red">"http://test"</font>,serviceName = <font color="red">"HelloWSSService"</font>)
<font color="navy"><b>public</b></font> <font color="navy"><b>interface</b></font> IHello  <font color="navy">{</font>
     
     
     String sayHello( String name);
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In my META-INF folder i put jboss-wsse-server.xml file :</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-xml"><span class="jive-xml-tag"><span><jboss-ws-security xmlns="</span><a class="jive-link-external-small" href="http://www.jboss.com/ws-security/config" target="_blank">http://www.jboss.com/ws-security/config</a><span>"
     xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"
     xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://www.jboss.com/ws-security/config" target="_blank">http://www.jboss.com/ws-security/config</a><span>
                      </span><a class="jive-link-external-small" href="http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd" target="_blank">http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd</a><span>"></span></span>
     <span class="jive-xml-tag"><config></span>
          <span class="jive-xml-tag"><timestamp ttl="300"/></span>
          <span class="jive-xml-tag"><requires/></span>
     <span class="jive-xml-tag"></config></span>
<span class="jive-xml-tag"></jboss-ws-security></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Now i deploy my app on server and i test it from SoapUI. </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"><soapenv:Envelope xmlns:soapenv=<font color="red">"http://schemas.xmlsoap.org/soap/envelope/"</font> xmlns:test=<font color="red">"http://test"</font>>
   <soapenv:Header/>
   <soapenv:Body>
      <test:sayHello>
         <arg0>?</arg0>
      </test:sayHello>
   </soapenv:Body>
</soapenv:Envelope>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>And anser : </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-xml"><span class="jive-xml-tag"><span><env:Envelope xmlns:env="</span><a class="jive-link-external-small" href="http://schemas.xmlsoap.org/soap/envelope/" target="_blank">http://schemas.xmlsoap.org/soap/envelope/</a><span>"></span></span>
   <span class="jive-xml-tag"><env:Header></span>
      <span class="jive-xml-tag"><span><wsse:Security env:mustUnderstand="1" xmlns:ds="</span><a class="jive-link-external-small" href="http://www.w3.org/2000/09/xmldsig#" target="_blank">http://www.w3.org/2000/09/xmldsig#</a><span>" xmlns:wsse="</span><a class="jive-link-external-small" href="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" target="_blank">http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd</a><span>" xmlns:wsu="</span><a class="jive-link-external-small" href="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" target="_blank">http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd</a><span>"></span></span>
         <span class="jive-xml-tag"><wsu:Timestamp wsu:Id="timestamp"></span>
            <span class="jive-xml-tag"><wsu:Created></span>2010-09-06T11:41:38.621Z<span class="jive-xml-tag"></wsu:Created></span>
            <span class="jive-xml-tag"><wsu:Expires></span>2010-09-06T11:46:38.621Z<span class="jive-xml-tag"></wsu:Expires></span>
         <span class="jive-xml-tag"></wsu:Timestamp></span>
      <span class="jive-xml-tag"></wsse:Security></span>
   <span class="jive-xml-tag"></env:Header></span>
   <span class="jive-xml-tag"><env:Body></span>
      <span class="jive-xml-tag"><span><test:sayHelloResponse xmlns:test="</span><a class="jive-link-external-small" href="http://test" target="_blank">http://test</a><span>"></span></span>
         <span class="jive-xml-tag"><return></span>siemanko ?<span class="jive-xml-tag"></return></span>
      <span class="jive-xml-tag"></test:sayHelloResponse></span>
   <span class="jive-xml-tag"></env:Body></span>
<span class="jive-xml-tag"></env:Envelope></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Got any idea why i can't secure my web service like that? i tryid it on jboss 4.2.3  , 5.01, 5.1, and 6 actually i work on 5.0.1 with JBoss Web Services - Native Server 3.3.1.GA. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Mayby i'm skipping some step or jboss-wsse-server.xml is incorect ? </p><p>when i put to jboss-wsse-server.xml this :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java"><jboss-ws-security xmlns=<font color="red">"http://www.jboss.com/ws-security/config"</font>
  xmlns:xsi=<font color="red">"http://www.w3.org/2001/XMLSchema-instance"</font>
  xsi:schemaLocation=<font color="red">"http://www.jboss.com/ws-security/config</font>
                      http:<font color="darkgreen">//www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd"></font>
  <config>
    <username/>
    <authenticate>
      <usernameAuth/>
    </authenticate>
  </config>
</jboss-ws-security>
 
 
 
</code></pre><p>Also nothing happend and i'am albe to get response without puting principals in header.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>JBossWS is good configured in login-config.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Please help.</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/560597#560597">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Web Services at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>