Skip to content

Commit 3741d2a

Browse files
committed
Replace XML::XPath with XML::libXML
1 parent f3887f5 commit 3741d2a

File tree

6 files changed

+55
-35
lines changed

6 files changed

+55
-35
lines changed

Makefile.PL

-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ my %WriteMakefileArgs = (
4747
"XML::LibXML" => 0,
4848
"XML::Tidy" => 0,
4949
"XML::Writer" => "0.625",
50-
"XML::XPath" => 0,
5150
"base" => 0,
5251
"constant" => 0,
5352
"namespace::autoclean" => 0,
@@ -122,7 +121,6 @@ my %FallbackPrereqs = (
122121
"XML::LibXML::XPathContext" => 0,
123122
"XML::Tidy" => 0,
124123
"XML::Writer" => "0.625",
125-
"XML::XPath" => 0,
126124
"base" => 0,
127125
"constant" => 0,
128126
"namespace::autoclean" => 0,

cpanfile

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ requires "XML::Generator" => "0";
3131
requires "XML::LibXML" => "0";
3232
requires "XML::Tidy" => "0";
3333
requires "XML::Writer" => "0.625";
34-
requires "XML::XPath" => "0";
3534
requires "base" => "0";
3635
requires "constant" => "0";
3736
requires "namespace::autoclean" => "0";

lib/Net/SAML2/Binding/SOAP.pm

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Net::SAML2::Binding::Artifact - SOAP binding for SAML2
2323
=cut
2424

2525
use Net::SAML2::XML::Sig;
26-
use XML::XPath;
26+
use XML::LibXML;
2727
use LWP::UserAgent;
2828
use HTTP::Request::Common;
2929

@@ -135,9 +135,15 @@ sub handle_response {
135135
my $subject = sprintf("%s (verified)", $cert->subject);
136136

137137
# parse the SOAP response and return the payload
138-
my $parser = XML::XPath->new( xml => no_comments($response) );
139-
$parser->set_namespace('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
140-
$parser->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
138+
my $dom = XML::LibXML->load_xml(
139+
string => no_comments($response),
140+
no_network => 1,
141+
load_ext_dtd => 0,
142+
expand_entities => 0 );
143+
144+
my $parser = XML::LibXML::XPathContext->new($dom);
145+
$parser->registerNs('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
146+
$parser->registerNs('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
141147

142148
my $saml = $parser->findnodes_as_string('/soap-env:Envelope/soap-env:Body/*');
143149
return ($subject, $saml);

lib/Net/SAML2/IdP.pm

+11-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use Crypt::OpenSSL::Verify;
2020
use Crypt::OpenSSL::X509;
2121
use HTTP::Request::Common;
2222
use LWP::UserAgent;
23-
use XML::XPath;
23+
use XML::LibXML;
2424

2525
=head2 new( )
2626
@@ -74,9 +74,15 @@ document.
7474
sub new_from_xml {
7575
my($class, %args) = @_;
7676

77-
my $xpath = XML::XPath->new(xml => no_comments($args{xml}));
78-
$xpath->set_namespace('md', 'urn:oasis:names:tc:SAML:2.0:metadata');
79-
$xpath->set_namespace('ds', 'http://www.w3.org/2000/09/xmldsig#');
77+
my $dom = XML::LibXML->load_xml(
78+
string => no_comments($args{xml}),
79+
no_network => 1,
80+
load_ext_dtd => 0,
81+
expand_entities => 0 );
82+
83+
my $xpath = XML::LibXML::XPathContext->new($dom);
84+
$xpath->registerNs('md', 'urn:oasis:names:tc:SAML:2.0:metadata');
85+
$xpath->registerNs('ds', 'http://www.w3.org/2000/09/xmldsig#');
8086

8187
my $data;
8288

@@ -157,7 +163,7 @@ sub new_from_xml {
157163
}
158164

159165
my $self = $class->new(
160-
entityid => $xpath->findvalue('//md:EntityDescriptor/@entityID')->value,
166+
entityid => $xpath->findvalue('//md:EntityDescriptor/@entityID'),
161167
sso_urls => $data->{SSO},
162168
slo_urls => $data->{SLO} || {},
163169
art_urls => $data->{Art} || {},

lib/Net/SAML2/Protocol/Assertion.pm

+19-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
55
use DateTime;
66
use DateTime::Format::XSD;
77
use Net::SAML2::XML::Util qw/ no_comments /;
8-
use XML::XPath;
8+
use XML::LibXML;
99

1010
with 'Net::SAML2::Role::ProtocolMessage';
1111

@@ -27,7 +27,7 @@ has 'nameid' => (isa => 'Str', is => 'ro', required =>
2727
has 'not_before' => (isa => DateTime, is => 'ro', required => 1);
2828
has 'not_after' => (isa => DateTime, is => 'ro', required => 1);
2929
has 'audience' => (isa => NonEmptySimpleStr, is => 'ro', required => 1);
30-
has 'xpath' => (isa => 'XML::XPath', is => 'ro', required => 1);
30+
has 'xpath' => (isa => 'XML::LibXML::XPathContext', is => 'ro', required => 1);
3131
has 'in_response_to' => (isa => 'Str', is => 'ro', required => 1);
3232
has 'response_status' => (isa => 'Str', is => 'ro', required => 1);
3333

@@ -55,10 +55,15 @@ XML data
5555
sub new_from_xml {
5656
my($class, %args) = @_;
5757

58-
my $xpath = XML::XPath->new(xml => no_comments($args{xml}));
58+
my $dom = XML::LibXML->load_xml(
59+
string => no_comments($args{xml}),
60+
no_network => 1,
61+
load_ext_dtd => 0,
62+
expand_entities => 0 );
5963

60-
$xpath->set_namespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
61-
$xpath->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
64+
my $xpath = XML::LibXML::XPathContext->new($dom);
65+
$xpath->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
66+
$xpath->registerNs('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
6267

6368
my $attributes = {};
6469
for my $node (
@@ -73,7 +78,7 @@ sub new_from_xml {
7378
my $not_before;
7479
if($xpath->findvalue('//saml:Conditions/@NotBefore')) {
7580
$not_before = DateTime::Format::XSD->parse_datetime(
76-
$xpath->findvalue('//saml:Conditions/@NotBefore')->value);
81+
$xpath->findvalue('//saml:Conditions/@NotBefore'));
7782
}
7883
else {
7984
$not_before = DateTime->now();
@@ -82,24 +87,24 @@ sub new_from_xml {
8287
my $not_after;
8388
if($xpath->findvalue('//saml:Conditions/@NotOnOrAfter')) {
8489
$not_after = DateTime::Format::XSD->parse_datetime(
85-
$xpath->findvalue('//saml:Conditions/@NotOnOrAfter')->value);
90+
$xpath->findvalue('//saml:Conditions/@NotOnOrAfter'));
8691
}
8792
else {
8893
$not_after = DateTime->from_epoch(epoch => time() + 1000);
8994
}
9095

9196
my $self = $class->new(
92-
issuer => $xpath->findvalue('//saml:Assertion/saml:Issuer')->value,
93-
destination => $xpath->findvalue('/samlp:Response/@Destination')->value,
97+
issuer => $xpath->findvalue('//saml:Assertion/saml:Issuer'),
98+
destination => $xpath->findvalue('/samlp:Response/@Destination'),
9499
attributes => $attributes,
95-
session => $xpath->findvalue('//saml:AuthnStatement/@SessionIndex')->value,
96-
nameid => $xpath->findvalue('//saml:Subject/saml:NameID')->value,
97-
audience => $xpath->findvalue('//saml:Conditions/saml:AudienceRestriction/saml:Audience')->value,
100+
session => $xpath->findvalue('//saml:AuthnStatement/@SessionIndex'),
101+
nameid => $xpath->findvalue('//saml:Subject/saml:NameID'),
102+
audience => $xpath->findvalue('//saml:Conditions/saml:AudienceRestriction/saml:Audience'),
98103
not_before => $not_before,
99104
not_after => $not_after,
100105
xpath => $xpath,
101-
in_response_to => $xpath->findvalue('//saml:Subject/saml:SubjectConfirmation/saml:SubjectConfirmationData/@InResponseTo')->value,
102-
response_status => $xpath->findvalue('//saml2p:Response/saml2p:Status/saml2p:StatusCode/@Value')->value,
106+
in_response_to => $xpath->findvalue('//saml:Subject/saml:SubjectConfirmation/saml:SubjectConfirmationData/@InResponseTo'),
107+
response_status => $xpath->findvalue('//samlp:Response/samlp:Status/samlp:StatusCode/@Value'),
103108
);
104109

105110
return $self;

lib/Net/SAML2/Protocol/LogoutRequest.pm

+15-9
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,23 @@ XML data
7676
sub new_from_xml {
7777
my ($class, %args) = @_;
7878

79-
my $xpath = XML::XPath->new( xml => no_comments($args{xml}) );
80-
$xpath->set_namespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
81-
$xpath->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
79+
my $dom = XML::LibXML->load_xml(
80+
string => no_comments($args{xml}),
81+
no_network => 1,
82+
load_ext_dtd => 0,
83+
expand_entities => 0 );
84+
85+
my $xpath = XML::LibXML::XPathContext->new($dom);
86+
$xpath->registerNs('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
87+
$xpath->registerNs('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
8288

8389
my $self = $class->new(
84-
id => $xpath->findvalue('/samlp:LogoutRequest/@ID')->value,
85-
session => $xpath->findvalue('/samlp:LogoutRequest/samlp:SessionIndex')->value,
86-
issuer => $xpath->findvalue('/samlp:LogoutRequest/saml:Issuer')->value,
87-
nameid => $xpath->findvalue('/samlp:LogoutRequest/saml:NameID')->value,
88-
nameid_format => $xpath->findvalue('/samlp:LogoutRequest/saml:NameID/@Format')->value,
89-
destination => $xpath->findvalue('/samlp:LogoutRequest/saml:NameID/@NameQualifier')->value,
90+
id => $xpath->findvalue('/samlp:LogoutRequest/@ID'),
91+
session => $xpath->findvalue('/samlp:LogoutRequest/samlp:SessionIndex'),
92+
issuer => $xpath->findvalue('/samlp:LogoutRequest/saml:Issuer'),
93+
nameid => $xpath->findvalue('/samlp:LogoutRequest/saml:NameID'),
94+
nameid_format => $xpath->findvalue('/samlp:LogoutRequest/saml:NameID/@Format'),
95+
destination => $xpath->findvalue('/samlp:LogoutRequest/saml:NameID/@NameQualifier'),
9096
);
9197

9298
return $self;

0 commit comments

Comments
 (0)