SAML2/SP.pm

filter: Statementstmt 93.5% 216 / 231 Branchbran 75.5% 65 / 86 Conditioncond 62.5% 10 / 16 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 93.0% 40 / 43 Podpod 100% 14 / 14 totaltotal 86.9% 347 / 399 CC 51 SCAR 16.3
CC
51
Cov
87%
__ANON__
13.9
_generate_key_descriptors
8.3
sp_post_binding
7.9
CRAP 5.1
« SAML2/IdP.pm ↑ Summary SAML2/Protocol/AuthnRequest.pm »
1 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Net::SAML2::SP;
4 32 our $VERSION = '0.89'; # VERSION
5  
6 32 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 32 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 32 ▶use Crypt::OpenSSL::X509;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 32 ▶use Digest::MD5 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 32 ▶use List::Util qw(first none);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 32 ▶use MooseX::Types::URI qw/ Uri /;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 32 ▶use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 32 ▶use Net::SAML2::Binding::POST;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 32 ▶use Net::SAML2::Binding::Redirect;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 32 ▶use Net::SAML2::Binding::SOAP;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 32 ▶use Net::SAML2::Protocol::AuthnRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 32 ▶use Net::SAML2::Protocol::LogoutRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 32 ▶use Net::SAML2::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 32 ▶use URN::OASIS::SAML2 qw(:bindings :urn);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 32 ▶use XML::Generator;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 32 ▶use Net::SAML2::Types qw(XsdID);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 32 with 'Net::SAML2::Role::XMLLang';
25  
26 # ABSTRACT: SAML Service Provider object
27  
28  
29  
30  
31 32 has 'url' => (isa => Uri, is => 'ro', required => 1, coerce => 1);
32  
33 32 has '_id' => (
34 isa => XsdID,
35 is => 'ro',
36 builder => '_build_id',
37 init_arg => 'id'
38 );
39  
40 32 has 'issuer' => (isa => 'Str', is => 'ro', required => 1);
41  
42 32 has 'cert' => (isa => 'Str', is => 'ro', required => 1, predicate => 'has_cert');
43 32 has 'key' => (isa => 'Str', is => 'ro', required => 1);
44 32 has 'cacert' => (isa => 'Str', is => 'rw', required => 0, predicate => 'has_cacert');
45  
46 32 has 'signing_only' => (isa => 'Bool', is => 'ro', required => 0);
47  
48 32 has 'encryption_key' => (isa => 'Str', is => 'ro', required => 0, predicate => 'has_encryption_key');
49 32 has 'error_url' => (isa => Uri, is => 'ro', required => 1, coerce => 1);
50 32 has 'org_name' => (isa => 'Str', is => 'ro', required => 1);
51 32 has 'org_display_name' => (isa => 'Str', is => 'ro', required => 1);
52 32 has 'org_contact' => (isa => 'Str', is => 'ro', required => 1);
53 32 has 'org_url' => (isa => 'Str', is => 'ro', required => 0);
54  
55 # These are no longer in use, but are not removed by the off change that
56 # someone that extended us or added a role to us with these params.
57 32 has 'slo_url_soap' => (isa => 'Str', is => 'ro', required => 0);
58 32 has 'slo_url_post' => (isa => 'Str', is => 'ro', required => 0);
59 32 has 'slo_url_redirect' => (isa => 'Str', is => 'ro', required => 0);
60 32 has 'acs_url_post' => (isa => 'Str', is => 'ro', required => 0);
61 32 has 'acs_url_artifact' => (isa => 'Str', is => 'ro', required => 0);
62  
63 32 has 'attribute_consuming_service' =>
64 (isa => 'Net::SAML2::AttributeConsumingService', is => 'ro', predicate => 'has_attribute_consuming_service');
65  
66 32 has '_cert_text' => (isa => 'Str', is => 'ro', init_arg => undef, builder => '_build_cert_text', lazy => 1);
67  
68 32 has '_encryption_key_text' => (isa => 'Str', is => 'ro', init_arg => undef, builder => '_build_encryption_key_text', lazy => 1);
69 32 has 'authnreq_signed' => (isa => 'Bool', is => 'ro', required => 0, default => 1);
70 32 has 'want_assertions_signed' => (isa => 'Bool', is => 'ro', required => 0, default => 1);
71  
72 32 has 'sign_metadata' => (isa => 'Bool', is => 'ro', required => 0, default => 1);
73  
74 32 has assertion_consumer_service => (is => 'ro', isa => 'ArrayRef', required => 1);
75 32 has single_logout_service => (is => 'ro', isa => 'ArrayRef', required => 1);
76  
77 32 has 'insecure_trust_embedded_cert' => (
78 isa => 'Bool',
79 is => 'ro',
80 default => 0,
81 );
82  
83 25 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=13 SCAR=26.3
84 25 my $orig = shift;
85 25 my $self = shift;
86  
87 25 my %args = @_;
88  
89 25 ▶ if (!exists $args{issuer} && exists $args{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $args{"issuer"} and exists $args{"id"}) 0 25 25
Condition33%1/3
not exists $args{"issuer"} and exists $args{"id"}
!ll&&!rl&&r
2500
MC/DC0%0/2
not exists $args{"issuer"} and exists $args{"id"}
not exists $args{"issuer"} exists $args{"id"}
Truth table33%1/3
not(A) and B
A= not exists $args{"issuer"}B= exists $args{"id"}
ABresult
0X0
100
111
90 0 Net::SAML2::Util::deprecation_warning
91 "id has been renamed to issuer and should be used instead";
92 0 $args{issuer} = delete $args{id};
93 }
94  
95 25 ▶ if (!$args{single_logout_service}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"single_logout_service"}) 20 5 25
96 #warn "Deprecation warning, please upgrade your code to use ..";
97 20 my @slo;
98 20 ▶ if (my $slo = $args{slo_url_soap}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $slo = $args{"slo_url_soap"}) 3 17 20
99 push(
100 @slo,
101 {
102 Binding => BINDING_SOAP,
103 3 Location => $args{url} . $slo,
104 }
105 );
106 }
107 20 ▶ if (my $slo = $args{slo_url_redirect}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $slo = $args{"slo_url_redirect"}) 0 20 20
108 push(
109 @slo,
110 {
111 Binding => BINDING_HTTP_REDIRECT,
112 0 Location => $args{url} . $slo,
113 }
114 );
115 }
116 20 ▶ if (my $slo = $args{slo_url_post}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $slo = $args{"slo_url_post"}) 3 17 20
117 push(
118 @slo,
119 {
120 Binding => BINDING_HTTP_POST,
121 3 Location => $args{url} . $slo,
122 }
123 );
124 }
125 20 $args{single_logout_service} = \@slo;
126 }
127  
128 25 ▶ if (!$args{assertion_consumer_service}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"assertion_consumer_service"}) 21 4 25
129 #warn "Deprecation warning, please upgrade your code to use ..";
130 21 my @acs;
131 21 ▶ if (my $acs = delete $args{acs_url_post}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $acs = delete $args{"acs_url_post"}) 21 0 21
132 push(
133 @acs,
134 {
135 Binding => BINDING_HTTP_POST,
136 21 Location => $args{url} . $acs,
137 isDefault => 'true',
138 }
139 );
140 }
141 21 ▶ if (my $acs = $args{acs_url_artifact}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $acs = $args{"acs_url_artifact"}) 21 0 21
142 push(
143 @acs,
144 {
145 Binding => BINDING_HTTP_ARTIFACT,
146 21 Location => $args{url} . $acs,
147 isDefault => 'false',
148 }
149 );
150 }
151  
152 21 $args{assertion_consumer_service} = \@acs;
153 }
154 25 ▶ if (!@{$args{assertion_consumer_service}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$args{"assertion_consumer_service"};}) 1 24 25
155 1 croak("You don't have any Assertion Consumer Services configured!");
156 }
157  
158 24 my $acs_index = 1;
159 24 ▶ if (none { $_->{index} } @{$args{assertion_consumer_service}}) {
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if (&none(sub { $_->{"index"}; } , @{$args{"assertion_consumer_service"};})) 24 0 24
160 24 foreach (@{$args{assertion_consumer_service}}) {
161 48 $_->{index} = $acs_index;
162 48 ++$acs_index;
163 }
164 }
165  
166 24 return $self->$orig(%args);
167 32 };
168  
169 24 ▶sub _build_id {
Subroutine _build_id: called CC=1 SCAR=0.0
170 24 my $self = shift;
171 24 return Net::SAML2::Util::generate_id();
172 }
173  
174 1 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
175 1 my $self = shift;
176 1 Net::SAML2::Util::deprecation_warning
177 "id() has been renamed to issuer()";
178 1 return $self->issuer;
179 }
180  
181  
182 2 ▶sub _build_encryption_key_text {
Subroutine _build_encryption_key_text: called CC=2 SCAR=6.9
183 2 my ($self) = @_;
184  
185 2 ▶ return '' unless $self->has_encryption_key;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_encryption_key 1 1 2
186 1 my $cert = Crypt::OpenSSL::X509->new_from_file($self->encryption_key);
187 1 my $text = $cert->as_string;
188 1 $text =~ s/-----[^-]*-----//gm;
189 1 return $text;
190 }
191  
192 12 ▶sub _build_cert_text {
Subroutine _build_cert_text: called CC=2 SCAR=7.0
193 12 my ($self) = @_;
194  
195 12 ▶ return '' unless $self->has_cert;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_cert 0 12 12
196 12 my $cert = Crypt::OpenSSL::X509->new_from_file($self->cert);
197 12 my $text = $cert->as_string;
198 12 $text =~ s/-----[^-]*-----//gm;
199 12 return $text;
200 }
201  
202  
203 4 ▶sub authn_request {
Subroutine authn_request: called CC=2 SCAR=6.9
Pod documented
204 4 my $self = shift;
205 4 my $destination = shift;
206 4 my $nameid_format = shift;
207 4 my (%params) = @_;
208  
209 4 ▶ return Net::SAML2::Protocol::AuthnRequest->new(
Condition100%2/2
$nameid_format || ''
l!l
31
MC/DC100%1/1
$nameid_format || ''
$nameid_format
Truth table100%2/2
A
A= $nameid_format
Aresult
11
00
210 issueinstant => DateTime->now,
211 issuer => $self->issuer,
212 destination => $destination,
213 nameidpolicy_format => $nameid_format || '',
214 %params,
215 );
216  
217 }
218  
219  
220 3 ▶sub logout_request {
Subroutine logout_request: called CC=5 SCAR=16.4
Pod documented
221 3 my ($self, $destination, $nameid, $nameid_format, $session, $params) = @_;
222  
223 my $logout_req = Net::SAML2::Protocol::LogoutRequest->new(
224 issuer => $self->issuer,
225 destination => $destination,
226 nameid => $nameid,
227 session => $session,
228 NonEmptySimpleStr->check($nameid_format)
229 ? (nameid_format => $nameid_format)
230 : (),
231 (defined $params->{sp_name_qualifier})
232 ? (affiliation_group_id => $params->{sp_name_qualifier})
233 : (),
234 (defined $params->{name_qualifier})
235 ? (name_qualifier => $params->{name_qualifier})
236 : (),
237 (defined $params->{include_name_qualifier})
238 ? ( include_name_qualifier => $params->{include_name_qualifier} )
239 3 ▶ : ( include_name_qualifier => 1),
Branch: 4 branches
BranchTrueFalseTotal
NonEmptySimpleStr()->check($nameid_format) ? : 3 0 3
defined $params->{'sp_name_qualifier'} ? : 1 2 3
defined $params->{'name_qualifier'} ? : 1 2 3
defined $params->{'include_name_qualifier'} ? : 0 3 3
240 );
241 3 return $logout_req;
242 }
243  
244  
245 0 ▶sub logout_response {
Subroutine logout_response: not called CC=1 SCAR=6.9
Pod documented
246 0 my ($self, $destination, $status, $in_response_to) = @_;
247  
248 0 my $status_uri = Net::SAML2::Protocol::LogoutResponse->status_uri($status);
249 0 my $logout_req = Net::SAML2::Protocol::LogoutResponse->new(
250 issuer => $self->issuer,
251 destination => $destination,
252 status => $status_uri,
253 in_response_to => $in_response_to,
254 );
255  
256 0 return $logout_req;
257 }
258  
259  
260 0 ▶sub artifact_request {
Subroutine artifact_request: not called CC=1 SCAR=6.9
Pod documented
261 0 my ($self, $destination, $artifact) = @_;
262  
263 0 my $artifact_request = Net::SAML2::Protocol::ArtifactResolve->new(
264 issuer => $self->issuer,
265 destination => $destination,
266 artifact => $artifact,
267 issueinstant => DateTime->now,
268 );
269  
270 0 return $artifact_request;
271 }
272  
273  
274 3 ▶sub sp_post_binding {
Subroutine sp_post_binding: called CC=6 SCAR=20.7
Pod documented
275 3 my ($self, $idp, $param) = @_;
276  
277 3 ▶ unless ($idp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($idp) 0 3 3
278 0 croak("Unable to create a post binding without an IDP");
279 }
280  
281 3 ▶ $param //= 'SAMLRequest';
Condition50%1/2
$param //= "SAMLRequest"
l!l
30
MC/DC0%0/1
$param //= "SAMLRequest"
$param
Truth table50%1/2
A
A= $param
Aresult
11
00
282  
283 3 ▶ my $post = Net::SAML2::Binding::POST->new(
Branch: 3 branches
BranchTrueFalseTotal
$self->authnreq_signed ? : 3 0 3
$self->cacert ? : 3 0 3
$self->insecure_trust_embedded_cert ? : 0 3 3
284 url => $idp->sso_url('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'),
285 cert => ($self->cert,),
286 $self->authnreq_signed ? (
287 key => $self->key,
288 ) : (
289 insecure => 1,
290 ),
291 $self->cacert ? (cacert => $self->cacert) : (),
292 $self->insecure_trust_embedded_cert ? (
293 insecure_trust_embedded_cert => $self->insecure_trust_embedded_cert
294 ) : (),
295 param => $param,
296 );
297  
298 3 return $post;
299 }
300  
301  
302 2 ▶sub sso_redirect_binding {
Subroutine sso_redirect_binding: called CC=4 SCAR=14.5
Pod documented
303 2 my ($self, $idp, $param) = @_;
304  
305 2 ▶ unless ($idp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($idp) 0 2 2
306 0 croak("Unable to create a redirect binding without an IDP");
307 }
308  
309 2 ▶ $param = 'SAMLRequest' unless $param;
Branch: 1 branch
BranchTrueFalseTotal
unless $param 0 2 2
310  
311 2 ▶ my $redirect = Net::SAML2::Binding::Redirect->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->authnreq_signed ? : 1 1 2
312 url => $idp->sso_url('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'),
313 cert => $idp->cert('signing'),
314 $self->authnreq_signed ? (
315 key => $self->key,
316 ) : (
317 insecure => 1,
318 ),
319 param => $param,
320 );
321  
322 2 return $redirect;
323 }
324  
325  
326 0 ▶sub slo_redirect_binding {
Subroutine slo_redirect_binding: not called CC=1 SCAR=6.9
Pod documented
327 0 my ($self, $idp, $param) = @_;
328  
329 0 my $redirect = Net::SAML2::Binding::Redirect->new(
330 url => $idp->slo_url('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'),
331 cert => $idp->cert('signing'),
332 key => $self->key,
333 param => $param,
334 );
335 0 return $redirect;
336 }
337  
338  
339 1 ▶sub soap_binding {
Subroutine soap_binding: called CC=2 SCAR=7.2
Pod documented
340 1 my ($self, $ua, $idp_url, $idp_cert) = @_;
341  
342 1 ▶ return Net::SAML2::Binding::SOAP->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->has_cacert ? : 1 0 1
343 ua => $ua,
344 key => $self->key,
345 cert => $self->cert,
346 url => $idp_url,
347 idp_cert => $idp_cert,
348 $self->has_cacert ? (cacert => $self->cacert) : (),
349 );
350 }
351  
352  
353 2 ▶sub post_binding {
Subroutine post_binding: called CC=3 SCAR=12.0
Pod documented
354 2 my ($self, %args) = @_;
355  
356 2 ▶ return Net::SAML2::Binding::POST->new(
Branch: 2 branches
BranchTrueFalseTotal
$self->has_cacert ? : 2 0 2
$self->insecure_trust_embedded_cert ? : 0 2 2
357 $self->has_cacert ? (cacert => $self->cacert) : (),
358 $self->insecure_trust_embedded_cert ? (
359 insecure_trust_embedded_cert => $self->insecure_trust_embedded_cert
360 ) : (),
361 %args,
362 );
363 }
364  
365  
366 32 my $md = ['md' => URN_METADATA];
367 32 my $ds = ['ds' => URN_SIGNATURE];
368  
369 12 ▶sub generate_metadata {
Subroutine generate_metadata: called CC=7 SCAR=19.5
Pod documented
370 12 my $self = shift;
371  
372 12 my $x = XML::Generator->new(conformance => 'loose', xml => { version => "1.0", encoding => 'UTF-8' });
373  
374 12 my $error_uri = $self->error_url;
375 12 ▶ if (!$error_uri->scheme) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error_uri->scheme) 11 1 12
376 11 $error_uri = $self->url . $self->error_url;
377 }
378  
379 12 ▶ return $x->xml( $x->EntityDescriptor(
Branch: 5 branches
BranchTrueFalseTotal
$self->authnreq_signed ? : 11 1 12
$self->want_assertions_signed ? : 11 1 12
$self->has_encryption_key ? : 1 11 12
$self->has_attribute_consuming_service ? : 1 11 12
defined $self->org_url ? : 12 0 12
380 $md,
381 {
382 entityID => $self->issuer,
383 ID => $self->_id,
384 },
385 $x->SPSSODescriptor(
386 $md,
387 {
388 AuthnRequestsSigned => $self->authnreq_signed ? 'true' : 'false',
389 WantAssertionsSigned => $self->want_assertions_signed ? 'true' : 'false',
390 errorURL => $error_uri,
391 protocolSupportEnumeration => URN_PROTOCOL,
392 },
393  
394 $self->has_encryption_key
395 ? ($self->_generate_key_descriptors($x, 'encryption'),
396 $self->_generate_key_descriptors($x, 'signing'))
397 : $self->_generate_key_descriptors($x, 'both'),
398  
399  
400 $self->_generate_single_logout_service($x),
401  
402 $self->_generate_assertion_consumer_service($x),
403 $self->has_attribute_consuming_service ? $self->attribute_consuming_service->to_xml : (),
404  
405 ),
406 $x->Organization(
407 $md,
408 $x->OrganizationName(
409 $md, $self->lang, $self->org_name,
410 ),
411 $x->OrganizationDisplayName(
412 $md, $self->lang,
413 $self->org_display_name,
414 ),
415 $x->OrganizationURL(
416 $md,
417 $self->lang,
418 defined($self->org_url) ? $self->org_url : $self->url
419 )
420 ),
421 $x->ContactPerson(
422 $md,
423 { contactType => 'other' },
424 $x->Company($md, $self->org_display_name,),
425 $x->EmailAddress($md, $self->org_contact,),
426 )
427 ));
428 }
429  
430 13 ▶sub _generate_key_descriptors {
Subroutine _generate_key_descriptors: called CC=8 SCAR=21.2
431 13 my $self = shift;
432 13 my $x = shift;
433 13 my $use = shift;
434  
435 return
436 13 ▶ if !$self->authnreq_signed
Branch: 1 branch
BranchTrueFalseTotal
unless $self->authnreq_signed or $self->want_assertions_signed or $self->sign_metadata 0 13 13
Condition66%4/6
$self->authnreq_signed or $self->want_assertions_signed or $self->sign_metadata
l!l&&r!l&&!r
1210
$self->authnreq_signed or $self->want_assertions_signed
l!l&&r!l&&!r
1201
MC/DC0%0/3
$self->authnreq_signed or $self->want_assertions_signed or $self->sign_metadata
$self->authnreq_signed $self->want_assertions_signed $self->sign_metadata
Truth table50%2/4
A or B or C
A= $self->authnreq_signedB= $self->want_assertions_signedC= $self->sign_metadata
ABCresult
1XX1
01X1
0011
0000
437 && !$self->want_assertions_signed
438 && !$self->sign_metadata;
439  
440 13 ▶ my $key = $use eq 'encryption' ? $self->_encryption_key_text : $self->_cert_text;
Branch: 1 branch
BranchTrueFalseTotal
$use eq 'encryption' ? : 1 12 13
441  
442 13 ▶ $use = 'signing' if $self->signing_only && $use eq 'both';
Branch: 1 branch
BranchTrueFalseTotal
if $self->signing_only and $use eq "both" 1 12 13
Condition66%2/3
$self->signing_only and $use eq "both"
!ll&&!rl&&r
1201
MC/DC50%1/2
$self->signing_only and $use eq "both"
$self->signing_only $use eq "both"
Truth table66%2/3
A and B
A= $self->signing_onlyB= $use eq "both"
ABresult
0X0
100
111
443  
444 13 ▶ return $x->KeyDescriptor(
Branch: 1 branch
BranchTrueFalseTotal
$use ne 'both' ? : 3 10 13
445 $md,
446 $use ne 'both' ? { use => $use } : {},
447 $x->KeyInfo(
448 $ds,
449 $x->X509Data($ds, $x->X509Certificate($ds, $key)),
450 $x->KeyName($ds, $self->key_name($use)),
451 ),
452 );
453 }
454  
455  
456 17 ▶sub key_name {
Subroutine key_name: called CC=3 SCAR=11.0
Pod documented
457 17 my $self = shift;
458 17 my $use = shift;
459 17 ▶ my $key = $use eq 'encryption' ? $self->_encryption_key_text : $self->_cert_text;
Branch: 1 branch
BranchTrueFalseTotal
$use eq 'encryption' ? : 3 14 17
460 17 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 1 16 17
461 16 return Digest::MD5::md5_hex($key);
462 }
463  
464 12 ▶sub _generate_single_logout_service {
Subroutine _generate_single_logout_service: called CC=1 SCAR=0.0
465 12 my $self = shift;
466 12 my $x = shift;
467 12 return map { $x->SingleLogoutService($md, $_) } @{ $self->single_logout_service };
468 }
469  
470 12 ▶sub _generate_assertion_consumer_service {
Subroutine _generate_assertion_consumer_service: called CC=1 SCAR=0.0
471 12 my $self = shift;
472 12 my $x = shift;
473 12 return map { $x->AssertionConsumerService($md, $_) } @{ $self->assertion_consumer_service };
474 }
475  
476  
477  
478 12 ▶sub metadata {
Subroutine metadata: called CC=3 SCAR=11.0
Pod documented
479 12 my $self = shift;
480  
481 12 my $metadata = $self->generate_metadata();
482 12 ▶ return $metadata->stringify unless $self->sign_metadata;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sign_metadata 1 11 12
483  
484 32 ▶ use Net::SAML2::XML::Sig;
Subroutine BEGIN: called CC=1 SCAR=0.0
485 11 my $signer = Net::SAML2::XML::Sig->new(
486 {
487 key => $self->key,
488 cert => $self->cert,
489 sig_hash => 'sha256',
490 digest_hash => 'sha256',
491 x509 => 1,
492 ns => { md => URN_METADATA },
493 id_attr => '/md:EntityDescriptor[@ID]',
494 }
495 );
496 11 my $md = $signer->sign($metadata);
497  
498 11 my $xp = XML::LibXML::XPathContext->new(
499 XML::LibXML->load_xml(string =>$md)
500 );
501 11 $xp->registerNs('md', URN_METADATA);
502 11 $xp->registerNs('dsig', URN_SIGNATURE);
503  
504 11 my $nodes = $xp->findnodes('/md:EntityDescriptor[@ID]');
505 11 my $rootnode = $nodes->get_node(1);
506  
507 11 my $child = $rootnode->firstChild;
508 11 ▶ return $md if $child->nodeName() eq 'dsig:Signature';
Branch: 1 branch
BranchTrueFalseTotal
if $child->nodeName eq "dsig:Signature" 0 11 11
509  
510 11 $nodes = $xp->findnodes('//dsig:Signature');
511 11 my $signode = $nodes->get_node(1);
512  
513 11 $signode->unbindNode;
514 11 $rootnode->insertBefore($signode, $child);
515  
516 11 return '<?xml version="1.0" encoding="UTF-8"?>' . $rootnode->toString;
517 }
518  
519  
520 3 ▶sub get_default_assertion_service {
Subroutine get_default_assertion_service: called CC=3 SCAR=11.0
Pod documented
521 3 my $self = shift;
522 4 ▶ my $default = first { $_->{isDefault} eq 1 || $_->{isDefault} eq 'true' }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_->{"isDefault"} eq 1 or $_->{"isDefault"} eq "true" 0 4 4
523 3 grep { defined $_->{isDefault} } @{ $self->assertion_consumer_service };
524 3 ▶ return $default if $default;
Branch: 1 branch
BranchTrueFalseTotal
if $default 1 2 3
525  
526 2 ▶ $default = first { ! defined $_->{isDefault} } @{ $self->assertion_consumer_service };
Subroutine __ANON__: called CC=1 SCAR=0.0
527 2 ▶ return $default if $default;
Branch: 1 branch
BranchTrueFalseTotal
if $default 1 1 2
528  
529 1 return $self->assertion_consumer_service->[0];
530 }
531  
532 32 __PACKAGE__->meta->make_immutable;
533  
534 __END__
« SAML2/IdP.pm ↑ Summary SAML2/Protocol/AuthnRequest.pm »