[Xml-compile] Need help with XML::Compile::Translate::Writer and attributes with namespace

David McMath mcdave at stanford.edu
Fri Aug 3 15:13:13 GMT 2012


Dear List,

This question came out of my trying to add "Create" and "Nonce" elements 
to a wsse:Security element and use them to create a password digest.  I 
got my case to work, in that the server is accepting my password now. 
I've appended the code below in case it's relevant.


My code works, and I shouldn't complain too much, but the example in the 
documentation I'm working from has elements that look like

<wsse:Security soap:mustUnderstand="1">
...
               <wsu:Timestamp 
wsu:Id="Timestamp-b23cf78f-09f8-4eec-9106-3a9a52819842">
...
               <wsse:UsernameToken 
wsu:Id="SecurityToken-8836043e-8f9b-4e56-8e2b-5610e9ce280f">

(evidently, they're optional).

Whenever I try to put an attribute from another namespace into my 
element, I get warnings that are variations on "tag `wsu_Id' not used", 
as in the following:

> trace: schema compile WRITER for {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Password
> trace: schema compile WRITER for {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Nonce
> trace: schema compile WRITER for {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Created
> trace: schema compile WRITER for {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}UsernameToken
> trace: rewrote type {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Username to wsse_Username
> trace: available tags are: wsse_Username, Id
> mistake: tag `wsu_Id' not used at {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}UsernameToken
>  at /usr/lib/perl5/site_perl/5.8.8/XML/Compile/Translate/Writer.pm line 530


If anyone has any advice about how to add those sorts of attribute in, 
either during writing or after the fact, I'd appreciate hearing it.


Thanks,

dave

--

PS.  My code.  For purposed of my experiment, I stuck the method in 
XML::Compile::SOAP::WSS because I started out thinking I'd just override 
wsseBasicAuth but that didn't end up making sense.

<code>
package XML::Compile::SOAP::WSS ;
...
use DateTime ;
use Digest::SHA1 qw/sha1_base64/ ;
use MIME::Base64 ;

sub wsseBasicAuth_nonce
{   my ($self, $username, $password, $nonce) = @_;
     my $type = UTP11_PDIGEST ;

     my $schema = $self->schema or panic;

     my $pwtype = $schema->findName('wsse:Password');
     my $untype = $schema->findName('wsse:UsernameToken');
     my $noncetype = $schema->findName('wsse:Nonce') ;
     my $createdtype = $schema->findName('wsu:Created' ) ;
     my $expirestype = $schema->findName('wsu:Expires' ) ;
     my $timestamptype = $schema->findName('wsu:Timestamp') ;

     my $currentTimeStamp = DateTime->now ;
     # Timestamps are UTC by default but no trailing "Z".
     my $now = $currentTimeStamp . 'Z' ;
     # A one-minute lifespan seems like plenty.
     my $then = $currentTimeStamp->clone->add( minutes => 1 ) . 'Z' ;

     # Add a trailing "=" for "compatibility", as mentioned in
     # Digest::SHA1.
     $password  = sha1_base64( $nonce . $now . $password ) . '=' ;

     my $doc    = XML::LibXML::Document->new('1.0', 'UTF-8');
     my $pwnode = $schema->writer($pwtype, include_namespaces => 0)
         ->($doc, {_ => $password, Type => $type} );
     my $noncenode = $schema->writer($noncetype, include_namespaces => 0)
         ->($doc, {_ => encode_base64($nonce) } );
     my $cnode = $schema->writer($createdtype, include_namespaces => 0)
         ->($doc, {_ => $now } );
     # Without "include_namespaces", my server complains about bad requests.
     my $token  = $schema->writer($untype, include_namespaces => 1)
         ->($doc, { # wsu_Id => 'baz',  ## Leaving out wsu:Id doesn't 
seem to hurt.
		  ## uncommenting the line above leads to
# trace: available tags are: wsse_Username, Id
# mistake: tag `wsu_Id' not used at 
{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}UsernameToken
#  at /usr/lib/perl5/site_perl/5.8.8/XML/Compile/Translate/Writer.pm 
line 530
		  wsse_Username => $username,
		  $pwtype => $pwnode,
   		  $noncetype => $noncenode,
		  $createdtype => $cnode,
		 } );

     my $tsToken = $schema->writer( $timestamptype, include_namespaces => 1)
       ->( $doc, { # Id => 'goo',  # Id typically looks like 
"Timestamp-ebd1b9f9-decf-45db-bf38-95cc219c8ca6", but where does that 
come from?
		  wsu_Created => $now,
		  wsu_Expires => $then,
		} ) ;
      +{ $untype => $token,
	$timestamptype => $tsToken,
       };
}
</code>



More information about the Xml-compile mailing list