[Xml-compile] WS-Security to Axis2 server

gstewart gstewart at gmail.com
Tue Aug 28 23:45:11 GMT 2012


Ok, so I'm slowly limping along from one problem to the next :-)

My application interface is running on an Axis2 server with
rampart installed. All the examples I've googled to date are for Java,
access. I want to do it in Perl.

>From various sources I've cobbled together an attempt to send the wsse
headers, as part of the query:

#! /usr/bin/perl

use Log::Report mode =3D> 'DEBUG';
use strict;
use warnings;

$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} =3D 0;
$ENV{'HTTPS_PROXY'} =3D "http://127.0.0.1:8080";
$ENV{'PERL_NET_HTTPS_SSL_SOCKET_CLASS'} =3D "Net::SSL";

use XML::Compile::WSDL11;      # use WSDL version 1.1
use XML::Compile::SOAP11;      # use SOAP version 1.1
use XML::Compile::Transport::SOAPHTTP;
use LWP::UserAgent;

my $browser =3D LWP::UserAgent->new();
my $wsdl_data =3D $browser->get("
https://endace1-ash.network.ibechtel.com/services/fwif?wsdl");
my $schema_data =3D $browser->get("
https://endace1-ash.network.ibechtel.com/services/ninjaprobe.xsd");

my $key_policy =3D '<wsp:Policy wsu:Id=3D"UsernameToken" xmlns:wsu=3D"
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-=
1.0.xsd"
xmlns:wsp=3D"http://schemas.xmlsoap.org/ws/2004/09/policy">
      <wsp:ExactlyOne>
        <wsp:All>
          <sp:SupportingTokens xmlns:sp=3D"
http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
            <wsp:Policy>
              <sp:UsernameToken sp:IncludeToken=3D"
http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Alwa=
ysToRecipient
"/>
            </wsp:Policy>
          </sp:SupportingTokens>
        </wsp:All>
      </wsp:ExactlyOne>
</wsp:Policy>';

use XML::Compile::WSS;
use XML::Compile::Util 'pack_type';

use constant MY_PASSWORD =3D> q/username_goes_here/;
use constant MY_USERNAME =3D> q/password_goes_here/;

my $wsdl =3D XML::Compile::WSDL11->new($wsdl_data->content);
$wsdl->importDefinitions($schema_data->content);

my $call =3D $wsdl->compileClient('VersionQuery');

use constant WSS_200401          =3D>
   'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss';
use constant WSS_SECEXT_200401   =3D> WSS_200401 .
'-wssecurity-secext-1.0.xsd';
use constant WSS_USERNAME_200401 =3D> WSS_200401 .
'-username-token-profile-1.0';

# Create the password translator

my $password_element  =3D pack_type WSS_SECEXT_200401, 'Password';
my $password_writer   =3D $wsdl->compile(WRITER =3D> $password_element);

my $password_document =3D XML::LibXML::Document->new('1.0', 'UTF-8');
my $password_value    =3D $password_writer->($password_document,
   { _    =3D> MY_PASSWORD
   , Type =3D> WSS_USERNAME_200401 . '#PasswordText'
   }
);

# Map the first any of SecurityHeaderType to UsernameToken, and set
# the password which is any using the above.

my $UsernameToken_element  =3D pack_type WSS_SECEXT_200401, 'UsernameToken';
my $UsernameToken_writer   =3D
  $wsdl->schemas->compile(WRITER =3D> $UsernameToken_element);
my $UsernameToken_document =3D XML::LibXML::Document->new('1.0', 'UTF-8');

my $UsernameToken_value    =3D
$UsernameToken_writer->($UsernameToken_document,
    { Username =3D> { _ =3D> MY_USERNAME }
    , $password_element =3D> $password_value
    }
);

my ($result, $trace) =3D $call->(
    header =3D> { $UsernameToken_element =3D> $UsernameToken_value },
    # rest of arguments
);

However the response I'm seeing is confusing:

race: register prefix SOAP-ENC for '
http://schemas.xmlsoap.org/soap/encoding/'
trace: schema compile WRITER for {
http://schemas.xmlsoap.org/soap/envelope/}Fault
trace: schema compile WRITER for {http://endace.com/ninjaprobe/}VersionQuery
trace: schema compile WRITER for {
http://schemas.xmlsoap.org/soap/envelope/}Fault
trace: schema compile WRITER for {http://endace.com/ninjaprobe/}ReturnStatus
trace: schema compile WRITER for {
http://schemas.xmlsoap.org/soap/envelope/}Envelope
trace: schema compile READER for {
http://endace.com/ninjaprobe/}VersionQueryResponse
trace: schema compile READER for {
http://schemas.xmlsoap.org/soap/envelope/}Fault
trace: schema compile READER for {
http://schemas.xmlsoap.org/soap/envelope/}Envelope
trace: loading extension XML::Compile::Transport::SOAPHTTP
trace: schema compile WRITER for {
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1=
.0.xsd}Password
error: cannot find element or attribute `{
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1=
.0.xsd}Password
'
 at /Library/Perl/5.12/XML/Compile/Translate.pm line 197
XML::Compile::Translate::topLevel(XML::Compile::Translate::Writer=3DHASH(0x=
7f8960f51ea8),
"{
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1=
.0.xsd}Password",
"{
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1=
.0.xsd}Password")
at /Library/Perl/5.12/XML/Compile/Translate.pm line 105
XML::Compile::Translate::compile(XML::Compile::Translate::Writer=3DHASH(0x7=
f8960f51ea8),
"{
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1=
.0.xsd}Password",
"sloppy_integers", 0, "check_values", 1, "xsi_type", HASH(0x7f8960f2d5c0),
[30 more]) at /Library/Perl/5.12/XML/Compile/Schema.pm line 249
XML::Compile::Schema::compile(XML::Compile::WSDL11=3DHASH(0x7f8960ccabd8),
"WRITER", "{
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1=
.0.xsd}Password",
"xsi_type", HASH(0x7f8960f2d5c0), "hooks", ARRAY(0x7f8960ef5e90),
"typemap", [3 more]) at /Library/Perl/5.12/XML/Compile/Cache.pm line 390
XML::Compile::Cache::compile() at ./wsdl_test.pl line 59

This is despite there being a "Password" attribute in
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1=
.0.xsd
.

Any thoughts?

P.S This was helpful:
http://cpansearch.perl.org/src/MARKOV/XML-Compile-SOAP-0.78/examples/wssecu=
rity/security.pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20120828/7a=
91e722/attachment-0001.htm


More information about the Xml-compile mailing list