Net-Saml2
view release on metacpan or search on metacpan
lib/Net/SAML2/Binding/SOAP.pm view on Meta::CPAN
my $dom = no_comments($response);
my $parser = XML::LibXML::XPathContext->new($dom);
$parser->registerNs('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
$parser->registerNs('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
my $saml = $parser->findnodes_as_string('/soap-env:Envelope/soap-env:Body/*');
return ($subject, $saml);
}
sub handle_request {
my ($self, $request) = @_;
my $dom = no_comments($request);
my $parser = XML::LibXML::XPathContext->new($dom);
$parser->registerNs('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
$parser->registerNs('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
my ($nodes) = $parser->findnodes('/soap-env:Envelope/soap-env:Body/*');
my $saml = $nodes->toString;
if (defined $saml) {
my $x = Net::SAML2::XML::Sig->new({ x509 => 1, cert_text => $self->idp_cert, exclusive => 1, });
my $ret = $x->verify($saml);
die "bad signature" unless $ret;
my $cert = $x->signer_cert;
my $ca = Crypt::OpenSSL::Verify->new($self->cacert, { strict_certs => 0, });
$ret = $ca->verify($cert);
die "bad certificate in request: ".$cert->subject unless $ret;
my $subject = $cert->subject;
return ($subject, $saml);
}
return;
}
sub create_soap_envelope {
my ($self, $message) = @_;
# sign the message
my $sig = Net::SAML2::XML::Sig->new({
x509 => 1,
key => $self->key,
cert => $self->cert,
exclusive => 1,
no_xml_declaration => 1,
});
my $signed_message = $sig->sign($message);
# OpenSSO ArtifactResolve hack
#
# OpenSSO's ArtifactResolve parser is completely hateful. It demands that
# the order of child elements in an ArtifactResolve message be:
#
# 1: saml:Issuer
# 2: dsig:Signature
# 3: samlp:Artifact
#
# Really.
#
if ($signed_message =~ /ArtifactResolve/) {
$signed_message =~ s!(<dsig:Signature.*?</dsig:Signature>)!!s;
my $signature = $1;
$signed_message =~ s/(<\/saml:Issuer>)/$1$signature/;
}
# test verify
my $ret = $sig->verify($signed_message);
die "failed to sign" unless $ret;
my $soap = <<"SOAP";
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
$signed_message
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP
return $soap;
}
__PACKAGE__->meta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
Net::SAML2::Binding::SOAP
=head1 VERSION
version 0.40
=head1 SYNOPSIS
my $soap = Net::SAML2::Binding::SOAP->new(
url => $idp_url,
key => $key,
cert => $cert,
idp_cert => $idp_cert,
);
my $response = $soap->request($req);
=head1 NAME
Net::SAML2::Binding::Artifact - SOAP binding for SAML2
=head1 METHODS
=head2 new( ... )
Constructor. Returns an instance of the SOAP binding configured for
the given IdP service url.
Arguments:
=over
( run in 0.498 second using v1.01-cache-2.11-cpan-71847e10f99 )