<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SOAP headers in Flex and WS-Security</title>
	<atom:link href="http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/</link>
	<description>deserialize me</description>
	<lastBuildDate>Tue, 04 May 2010 22:52:15 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Matt</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-2516</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Tue, 04 May 2010 22:52:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-2516</guid>
		<description>Same problem as Ankur.
getUsernameTokenAsArray is undefined.  
Is it deprecated?</description>
		<content:encoded><![CDATA[<p>Same problem as Ankur.<br />
getUsernameTokenAsArray is undefined.<br />
Is it deprecated?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clay</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-2269</link>
		<dc:creator>Clay</dc:creator>
		<pubDate>Thu, 25 Feb 2010 21:18:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-2269</guid>
		<description>Anyone know if the WSDL Wizard in Flash Builder 4 also has the problem? I&#039;ve been having... issues.</description>
		<content:encoded><![CDATA[<p>Anyone know if the WSDL Wizard in Flash Builder 4 also has the problem? I&#8217;ve been having&#8230; issues.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaurav</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-2264</link>
		<dc:creator>Gaurav</dc:creator>
		<pubDate>Wed, 24 Feb 2010 05:41:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-2264</guid>
		<description>Thanks for this wonderful post. I would like to add that the statement &quot;Let me start off by saying that the Import Web Service (WSDL) wizard in Flex 3 doesn’t work as it should!&quot; by Sven is completely true. But we have the, generated proxies working fine with Apache CXF hosted webservice using Security headers with a couple of tweaks.

In order to implement the fix we need to understand the design using which the proxy files are generated.

Here is how the proxies work: 

Let us suppose Demo being the service name.

There is one DemoWebService.as file which is derived 
from interface IDemoService.as.
There is another file called BaseDemoWebService.as which actually does the SOAP serialization and deserialization.

The DemoWebService.as (ServiceImpl) delegates all the opreations to the BaseDemoWebService instance which is composed in it.

Now in order to add the SOAP security headers we should add a method in the DemoWebService.as like setAuthentication(or whatever you like). This code is similar to what Sven did in his post. Clearing and adding the security headers.

My custom method looks like:

public function setAuthentication(userName:String, password:String):void
{
import be.svendens.util.SOAPHeaderUtil;
import mx.rpc.soap.SOAPHeader;
if (_baseService != null) {
var customHeader:SOAPHeader = SOAPHeaderUtil.returnWSSEHeaderWithoutNonceAndTimestamp(userName, password);
		
//customHeader.mustUnderstand = true;
_baseService.clearHeaders();
_baseService.addHeader(customHeader);
 }
}

The second and most important issue that needs to be fixed is in the BaseDemoWebService.as which is the core file. Here all the headers that we add are ignored as its everytime does the new for Header array. 

The simple fix is in BaseDemoService file.

Find the line in method call

soap = enc.encodeRequest(args,headers);

and replace it with 

soap = enc.encodeRequest(args, super.headers);

Just compile and verify  the system will send your WSSE security headers to the webservice endpoint URI.

All these fixes can be automated easily by writing a simple tool. We have created one tool which runs on
the generated proxies and patches the proxies to support the WSSE headers exactly as mentioned above.

Please contact us in case you need that tool for free :) or in case you have any other issue.

Regards
Gaurav
gaurav_handa@nthdimenzion.com</description>
		<content:encoded><![CDATA[<p>Thanks for this wonderful post. I would like to add that the statement &#8220;Let me start off by saying that the Import Web Service (WSDL) wizard in Flex 3 doesn’t work as it should!&#8221; by Sven is completely true. But we have the, generated proxies working fine with Apache CXF hosted webservice using Security headers with a couple of tweaks.</p>
<p>In order to implement the fix we need to understand the design using which the proxy files are generated.</p>
<p>Here is how the proxies work: </p>
<p>Let us suppose Demo being the service name.</p>
<p>There is one DemoWebService.as file which is derived<br />
from interface IDemoService.as.<br />
There is another file called BaseDemoWebService.as which actually does the SOAP serialization and deserialization.</p>
<p>The DemoWebService.as (ServiceImpl) delegates all the opreations to the BaseDemoWebService instance which is composed in it.</p>
<p>Now in order to add the SOAP security headers we should add a method in the DemoWebService.as like setAuthentication(or whatever you like). This code is similar to what Sven did in his post. Clearing and adding the security headers.</p>
<p>My custom method looks like:</p>
<p>public function setAuthentication(userName:String, password:String):void<br />
{<br />
import be.svendens.util.SOAPHeaderUtil;<br />
import mx.rpc.soap.SOAPHeader;<br />
if (_baseService != null) {<br />
var customHeader:SOAPHeader = SOAPHeaderUtil.returnWSSEHeaderWithoutNonceAndTimestamp(userName, password);</p>
<p>//customHeader.mustUnderstand = true;<br />
_baseService.clearHeaders();<br />
_baseService.addHeader(customHeader);<br />
 }<br />
}</p>
<p>The second and most important issue that needs to be fixed is in the BaseDemoWebService.as which is the core file. Here all the headers that we add are ignored as its everytime does the new for Header array. </p>
<p>The simple fix is in BaseDemoService file.</p>
<p>Find the line in method call</p>
<p>soap = enc.encodeRequest(args,headers);</p>
<p>and replace it with </p>
<p>soap = enc.encodeRequest(args, super.headers);</p>
<p>Just compile and verify  the system will send your WSSE security headers to the webservice endpoint URI.</p>
<p>All these fixes can be automated easily by writing a simple tool. We have created one tool which runs on<br />
the generated proxies and patches the proxies to support the WSSE headers exactly as mentioned above.</p>
<p>Please contact us in case you need that tool for free <img src='http://www.svendens.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  or in case you have any other issue.</p>
<p>Regards<br />
Gaurav<br />
<a href="mailto:gaurav_handa@nthdimenzion.com">gaurav_handa@nthdimenzion.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pramod</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-1535</link>
		<dc:creator>pramod</dc:creator>
		<pubDate>Tue, 13 Oct 2009 12:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-1535</guid>
		<description>But after adding the security data in header how to fetch the same at the service side.. is at possible? because in headers object at service side m able to fetch all data except this security tag data..</description>
		<content:encoded><![CDATA[<p>But after adding the security data in header how to fetch the same at the service side.. is at possible? because in headers object at service side m able to fetch all data except this security tag data..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: web services new bee</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-1514</link>
		<dc:creator>web services new bee</dc:creator>
		<pubDate>Fri, 09 Oct 2009 17:47:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-1514</guid>
		<description>hi, i am trying to add digest authentication to client side, can some one let me how to write spring client for consuming spring web service which requires digest authentication. should i populate soap headers? if so, how to do that.
i am using axis
thanks</description>
		<content:encoded><![CDATA[<p>hi, i am trying to add digest authentication to client side, can some one let me how to write spring client for consuming spring web service which requires digest authentication. should i populate soap headers? if so, how to do that.<br />
i am using axis<br />
thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wojciech</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-1426</link>
		<dc:creator>Wojciech</dc:creator>
		<pubDate>Thu, 17 Sep 2009 21:11:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-1426</guid>
		<description>In WSSEUsernameToken class in the getUsernameTokenAsArray function there is changed order of lines. 
Line: 
 nonce = base64Encode(nonce);
should be after the line:
var password64:String = getBase64Digest(nonce, created, password);

or it&#039;s better to provide a new variable:
var encodedNonce:String = base64Encode(nonce);
var created:String = generateTimestamp(timestamp);
var password64:String = getBase64Digest(nonce, created, password);
var token:Array = new Array(username, password64, encodedNonce, created);</description>
		<content:encoded><![CDATA[<p>In WSSEUsernameToken class in the getUsernameTokenAsArray function there is changed order of lines.<br />
Line:<br />
 nonce = base64Encode(nonce);<br />
should be after the line:<br />
var password64:String = getBase64Digest(nonce, created, password);</p>
<p>or it&#8217;s better to provide a new variable:<br />
var encodedNonce:String = base64Encode(nonce);<br />
var created:String = generateTimestamp(timestamp);<br />
var password64:String = getBase64Digest(nonce, created, password);<br />
var token:Array = new Array(username, password64, encodedNonce, created);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-1421</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Tue, 15 Sep 2009 11:26:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-1421</guid>
		<description>OK, it seems to be sorted now.  The cause was that I added SOAP-ENV:mustUnderstand=&quot;1&quot; as an attribute under the wsse:Security element.

Note that this is not present in Sven&#039;s code so it was pretty much a problem of my own making.  However, in the interests of disclosure...

Adding this attribute seems, at least in the implementation I&#039;m working with, to make the server pay attention to the wsu:Id attribute in the UsernameToken element along with the Created and Expires elements in the Timestamp (i.e. If you pass a different Id attribute value through the same browser session before the Timestamp has expired then it&#039;s throwing an error).

There&#039;s two ways I&#039;ve found to get around this:

1.  Exclude the mustUnderstand attribute - I&#039;m not sure if this is desirable or not (and I also have no idea what this would do to any implementations that actually track sessions for a reason), but the WSS specs (http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0.pdf) state:

&quot;When a  header includes a mustUnderstand=&quot;true&quot; attribute:

 The receiver MUST generate a SOAP fault if does not implement the WSS: SOAP Message Security specification corresponding to the namespace. Implementation means ability to interpret the schema as well as follow the required processing rules specified in WSS: SOAP Message Security.

 The receiver must generate a fault if unable to interpret or process security tokens contained in the  header block according to the corresponding WSS: SOAP Message Security token profiles.

 Receivers MAY ignore elements or extensions within the  element, based on local security policy.&quot;

2.  Keep the Id attribute value consistent until the Timestamp expires (or in theory throughout the life of the session) - This would seem to be a slightly more official way of doing it.

Either of these will make it work with the server implementation I&#039;m using right now, although I&#039;m storngly leaning towards the second option.

Again, all the usual caveats apply regarding this being a fix for my specific implementation and relying on the server-side guys to have locked things down well enough from a security angle that I can&#039;t actually implement an insecure solution. ;)</description>
		<content:encoded><![CDATA[<p>OK, it seems to be sorted now.  The cause was that I added SOAP-ENV:mustUnderstand=&#8221;1&#8243; as an attribute under the wsse:Security element.</p>
<p>Note that this is not present in Sven&#8217;s code so it was pretty much a problem of my own making.  However, in the interests of disclosure&#8230;</p>
<p>Adding this attribute seems, at least in the implementation I&#8217;m working with, to make the server pay attention to the wsu:Id attribute in the UsernameToken element along with the Created and Expires elements in the Timestamp (i.e. If you pass a different Id attribute value through the same browser session before the Timestamp has expired then it&#8217;s throwing an error).</p>
<p>There&#8217;s two ways I&#8217;ve found to get around this:</p>
<p>1.  Exclude the mustUnderstand attribute &#8211; I&#8217;m not sure if this is desirable or not (and I also have no idea what this would do to any implementations that actually track sessions for a reason), but the WSS specs (<a href="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0.pdf" rel="nofollow">http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0.pdf</a>) state:</p>
<p>&#8220;When a  header includes a mustUnderstand=&#8221;true&#8221; attribute:</p>
<p> The receiver MUST generate a SOAP fault if does not implement the WSS: SOAP Message Security specification corresponding to the namespace. Implementation means ability to interpret the schema as well as follow the required processing rules specified in WSS: SOAP Message Security.</p>
<p> The receiver must generate a fault if unable to interpret or process security tokens contained in the  header block according to the corresponding WSS: SOAP Message Security token profiles.</p>
<p> Receivers MAY ignore elements or extensions within the  element, based on local security policy.&#8221;</p>
<p>2.  Keep the Id attribute value consistent until the Timestamp expires (or in theory throughout the life of the session) &#8211; This would seem to be a slightly more official way of doing it.</p>
<p>Either of these will make it work with the server implementation I&#8217;m using right now, although I&#8217;m storngly leaning towards the second option.</p>
<p>Again, all the usual caveats apply regarding this being a fix for my specific implementation and relying on the server-side guys to have locked things down well enough from a security angle that I can&#8217;t actually implement an insecure solution. <img src='http://www.svendens.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-1416</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Mon, 14 Sep 2009 16:32:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-1416</guid>
		<description>Heh.  You&#039;d have thought I&#039;d haven taken the whole parsing issue into account for posting XML, but no.  The header (now with added entities) should read:

&lt;wsse:Security xmlns:wsse=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot; soapenv:mustUnderstand=&quot;1&quot;&gt;
	&lt;wsse:UsernameToken&gt;
		&lt;wsse:Username&gt;username&lt;/wsse:Username&gt;
		&lt;wsse:Password Type=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest&quot;&gt;encoded pasword&lt;/wsse:Password&gt;
		&lt;wsse:Nonce&gt;encoded nonce&lt;/wsse:Nonce&gt;
		&lt;wsu:Created xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;&gt;2009-09-14T10:53:01Z&lt;/wsu:Created&gt;
	&lt;/wsse:UsernameToken&gt;
	&lt;wsu:Timestamp xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;&gt;
		&lt;wsu:Created&gt;2009-09-14T10:53:01Z&lt;/wsu:Created&gt;
		&lt;wsu:Expires&gt;2009-09-14T10:58:01Z&lt;/wsu:Expires&gt;
	&lt;/wsu:Timestamp&gt;
&lt;/wsse:Security&gt;</description>
		<content:encoded><![CDATA[<p>Heh.  You&#8217;d have thought I&#8217;d haven taken the whole parsing issue into account for posting XML, but no.  The header (now with added entities) should read:</p>
<p>&lt;wsse:Security xmlns:wsse=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot; soapenv:mustUnderstand=&quot;1&quot;&gt;<br />
	&lt;wsse:UsernameToken&gt;<br />
		&lt;wsse:Username&gt;username&lt;/wsse:Username&gt;<br />
		&lt;wsse:Password Type=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest&quot;&gt;encoded pasword&lt;/wsse:Password&gt;<br />
		&lt;wsse:Nonce&gt;encoded nonce&lt;/wsse:Nonce&gt;<br />
		&lt;wsu:Created xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;&gt;2009-09-14T10:53:01Z&lt;/wsu:Created&gt;<br />
	&lt;/wsse:UsernameToken&gt;<br />
	&lt;wsu:Timestamp xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;&gt;<br />
		&lt;wsu:Created&gt;2009-09-14T10:53:01Z&lt;/wsu:Created&gt;<br />
		&lt;wsu:Expires&gt;2009-09-14T10:58:01Z&lt;/wsu:Expires&gt;<br />
	&lt;/wsu:Timestamp&gt;<br />
&lt;/wsse:Security&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-1415</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Mon, 14 Sep 2009 16:21:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-1415</guid>
		<description>I&#039;ve got it working to a point right now.  We&#039;ve used Axis to implement WSS on our server so I used this to knock together a java client then checked the password and nonce encoding were working correctly in the flex client (which they are).  Basically in the end all I needed to do was to implement the timestamp token within the security element on the header:


	
		
	
	
		2009-09-14T10:53:01Z
		2009-09-14T10:58:01Z
	


(This&#039;ll be pretty badly formatted but it should be decipherable).

The java client set the expiry time for the header as creation time + 5 mins, so I set the Flex entry to be the same (the created value is the same as the created entry within the UsernameToken).

Having said that I supposed it&#039;s possible that the requirement for the timestamp may be Axis and/or implementation specific, so it may not be the solution to anyone&#039;s problems bar mine but it&#039;s a starting point.

There&#039;s still one problem I haven&#039;t overcome yet which is that if you call the same webservice operation a few times in a row after succeeding the first couple of times it permanently falls over with the error:

soapenv:Server.userException - org.xml.sax.SAXParseException: The prefix &quot;soapenv&quot; for attribute &quot;soapenv:mustUnderstand&quot; is not bound.

Once I get a solution for this I&#039;ll post it here (I&#039;m guessing it&#039;s probably a server-side issue).</description>
		<content:encoded><![CDATA[<p>I&#8217;ve got it working to a point right now.  We&#8217;ve used Axis to implement WSS on our server so I used this to knock together a java client then checked the password and nonce encoding were working correctly in the flex client (which they are).  Basically in the end all I needed to do was to implement the timestamp token within the security element on the header:</p>
<p>		2009-09-14T10:53:01Z<br />
		2009-09-14T10:58:01Z</p>
<p>(This&#8217;ll be pretty badly formatted but it should be decipherable).</p>
<p>The java client set the expiry time for the header as creation time + 5 mins, so I set the Flex entry to be the same (the created value is the same as the created entry within the UsernameToken).</p>
<p>Having said that I supposed it&#8217;s possible that the requirement for the timestamp may be Axis and/or implementation specific, so it may not be the solution to anyone&#8217;s problems bar mine but it&#8217;s a starting point.</p>
<p>There&#8217;s still one problem I haven&#8217;t overcome yet which is that if you call the same webservice operation a few times in a row after succeeding the first couple of times it permanently falls over with the error:</p>
<p>soapenv:Server.userException &#8211; org.xml.sax.SAXParseException: The prefix &#8220;soapenv&#8221; for attribute &#8220;soapenv:mustUnderstand&#8221; is not bound.</p>
<p>Once I get a solution for this I&#8217;ll post it here (I&#8217;m guessing it&#8217;s probably a server-side issue).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sven Dens</title>
		<link>http://www.svendens.com/flex/soap-headers-in-flex-and-ws-security/comment-page-1/#comment-1412</link>
		<dc:creator>Sven Dens</dc:creator>
		<pubDate>Sat, 12 Sep 2009 09:36:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.svendens.be/blog/archives/27#comment-1412</guid>
		<description>Nothing wrong with the download link as far as I can tell Ankur.

A perfectly working solution has not been found by anybody just yet as you can tell from the other comments.  I&#039;ll have to test what Stuart writes, comparing the headers from a Java-originated call to those of a Flex-originated call to see why the Flex ones won&#039;t validate.
I&#039;ll also have to test it against different versions of SOAP etc...

Hope to have a new post on the subject soon that FINALLY contains a 100% working solution.

Kind regards,
Sven</description>
		<content:encoded><![CDATA[<p>Nothing wrong with the download link as far as I can tell Ankur.</p>
<p>A perfectly working solution has not been found by anybody just yet as you can tell from the other comments.  I&#8217;ll have to test what Stuart writes, comparing the headers from a Java-originated call to those of a Flex-originated call to see why the Flex ones won&#8217;t validate.<br />
I&#8217;ll also have to test it against different versions of SOAP etc&#8230;</p>
<p>Hope to have a new post on the subject soon that FINALLY contains a 100% working solution.</p>
<p>Kind regards,<br />
Sven</p>
]]></content:encoded>
	</item>
</channel>
</rss>
