Skip to content

Commit c53ba9d

Browse files
committed
Rename id to issuer for Net::SAML2::SP
We've had generate_sp_desciptor_id to override the ID, but this could very well become a parameter for the constructor. The current ID attribute was actually used as the issuer. Rename ID to issuer and and reintroduce ID. We add some deprecation warnings to users so they are aware of the change. Signed-off-by: Wesley Schwengle <waterkip@cpan.org>
1 parent 0588768 commit c53ba9d

File tree

4 files changed

+53
-29
lines changed

4 files changed

+53
-29
lines changed

lib/Net/SAML2/Protocol/AuthnRequest.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
77
use XML::Generator;
88
use List::Util qw(any);
99
use URN::OASIS::SAML2 qw(:urn BINDING_HTTP_POST);
10+
use Net::SAML2::Util ();
1011

1112
with 'Net::SAML2::Role::ProtocolMessage';
1213

@@ -179,9 +180,10 @@ around BUILDARGS => sub {
179180

180181
my %params = @_;
181182
if ($params{nameid_format} && !defined $params{nameidpolicy_format}) {
182-
warn "You are using nameid_format, this field has changed to "
183-
. "nameidpolicy_format. This field will be used for other purposes "
184-
. "in an upcoming release. Please change your code ASAP.";
183+
Net::SAML2::Util::deprecation_warning "You are using nameid_format, "
184+
. "this field has changed to nameidpolicy_format. This field will "
185+
. "be used for other purposes in an upcoming release. Please change "
186+
. "your code ASAP.";
185187
$params{nameidpolicy_format} = $params{nameid_format};
186188
}
187189

lib/Net/SAML2/SP.pm

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ use Net::SAML2::Protocol::LogoutRequest;
1919
use Net::SAML2::Util ();
2020
use URN::OASIS::SAML2 qw(:bindings :urn);
2121
use XML::Generator;
22+
use Net::SAML2::Types qw(XsdID);
2223

2324
# ABSTRACT: SAML Service Provider object
2425

2526
=head1 SYNOPSIS
2627
27-
my $sp = Net::SAML2::SP->new(
28-
id => 'http://localhost:3000',
29-
url => 'http://localhost:3000',
30-
cert => 'sign-nopw-cert.pem',
31-
key => 'sign-nopw-key.pem',
32-
);
28+
my $sp = Net::SAML2::SP->new(
29+
issuer => 'http://localhost:3000',
30+
url => 'http://localhost:3000',
31+
cert => 'sign-nopw-cert.pem',
32+
key => 'sign-nopw-key.pem',
33+
);
3334
3435
=head1 METHODS
3536
@@ -44,6 +45,10 @@ Arguments:
4445
4546
=over
4647
48+
=item B<id>
49+
50+
The ID attribute used in the EntityDescription tag
51+
4752
=item B<url>
4853
4954
Base for all SP service URLs
@@ -52,7 +57,7 @@ Base for all SP service URLs
5257
5358
The error URI. Can be relative to the base URI or a regular URI
5459
55-
=item B<id>
60+
=item B<issuer>
5661
5762
SP's identity URI.
5863
@@ -156,7 +161,10 @@ Consumer Services.
156161
=cut
157162

158163
has 'url' => (isa => Uri, is => 'ro', required => 1, coerce => 1);
159-
has 'id' => (isa => 'Str', is => 'ro', required => 1);
164+
165+
has 'id' => (isa => XsdID, is => 'ro', builder => '_build_id');
166+
has 'issuer' => (isa => 'Str', is => 'ro', required => 1);
167+
160168
has 'cert' => (isa => 'Str', is => 'ro', required => 1, predicate => 'has_cert');
161169
has 'key' => (isa => 'Str', is => 'ro', required => 1);
162170
has 'cacert' => (isa => 'Str', is => 'rw', required => 0, predicate => 'has_cacert');
@@ -196,6 +204,12 @@ around BUILDARGS => sub {
196204

197205
my %args = @_;
198206

207+
if (!exists $args{issuer} && exists $args{id}) {
208+
Net::SAML2::Util::deprecation_warning
209+
"id has been renamed to issuer and should be used instead";
210+
$args{issuer} = delete $args{id};
211+
}
212+
199213
if (!$args{single_logout_service}) {
200214
#warn "Deprecation warning, please upgrade your code to use ..";
201215
my @slo;
@@ -270,6 +284,20 @@ around BUILDARGS => sub {
270284
return $self->$orig(%args);
271285
};
272286

287+
sub _build_id {
288+
my $self = shift;
289+
290+
# This allows current clients to override the builder without changing
291+
# their code
292+
if (my $f = $self->can('generate_sp_desciptor_id')) {
293+
Net::SAML2::Util::deprecation_warning
294+
"generate_sp_desciptor_id has been deprecated, please override " .
295+
"_build_id yourself or supply the ID to the constructor";
296+
return $f->();
297+
}
298+
return Net::SAML2::Util::generate_id();
299+
}
300+
273301
sub _build_encryption_key_text {
274302
my ($self) = @_;
275303

@@ -323,7 +351,7 @@ sub authn_request {
323351

324352
return Net::SAML2::Protocol::AuthnRequest->new(
325353
issueinstant => DateTime->now,
326-
issuer => $self->id,
354+
issuer => $self->issuer,
327355
destination => $destination,
328356
nameidpolicy_format => $nameid_format || '',
329357
%params,
@@ -356,7 +384,7 @@ sub logout_request {
356384
my ($self, $destination, $nameid, $nameid_format, $session, $params) = @_;
357385

358386
my $logout_req = Net::SAML2::Protocol::LogoutRequest->new(
359-
issuer => $self->id,
387+
issuer => $self->issuer,
360388
destination => $destination,
361389
nameid => $nameid,
362390
session => $session,
@@ -391,7 +419,7 @@ sub logout_response {
391419

392420
my $status_uri = Net::SAML2::Protocol::LogoutResponse->status_uri($status);
393421
my $logout_req = Net::SAML2::Protocol::LogoutResponse->new(
394-
issuer => $self->id,
422+
issuer => $self->issuer,
395423
destination => $destination,
396424
status => $status_uri,
397425
response_to => $response_to,
@@ -412,7 +440,7 @@ sub artifact_request {
412440
my ($self, $destination, $artifact) = @_;
413441

414442
my $artifact_request = Net::SAML2::Protocol::ArtifactResolve->new(
415-
issuer => $self->id,
443+
issuer => $self->issuer,
416444
destination => $destination,
417445
artifact => $artifact,
418446
issueinstant => DateTime->now,
@@ -539,17 +567,6 @@ sub post_binding {
539567
);
540568
}
541569

542-
=head2 generate_sp_desciptor_id ( )
543-
544-
Returns the Net::SAML2 unique ID from Net::SAML2::Util::generate_id.
545-
546-
=cut
547-
548-
sub generate_sp_desciptor_id {
549-
my $self = shift;
550-
return Net::SAML2::Util::generate_id();
551-
}
552-
553570
=head2 generate_metadata( )
554571
555572
Generate the metadata XML document for this SP.
@@ -572,8 +589,8 @@ sub generate_metadata {
572589
return $x->xml( $x->EntityDescriptor(
573590
$md,
574591
{
575-
entityID => $self->id,
576-
ID => $self->generate_sp_desciptor_id(),
592+
entityID => $self->issuer,
593+
ID => $self->id,
577594
},
578595
$x->SPSSODescriptor(
579596
$md,

lib/Net/SAML2/Util.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ use Exporter qw(import);
1111

1212
our @EXPORT_OK = qw(
1313
generate_id
14+
deprecation_warning
1415
);
1516

1617
sub generate_id {
1718
return 'NETSAML2_' . unpack 'H*', random_pseudo_bytes(32);
1819
}
1920

21+
sub deprecation_warning {
22+
warn "NET::SAML2 deprecation warning: " . shift . "\n";
23+
}
24+
2025

2126
1;
2227

t/lib/Test/Net/SAML2/Util.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ our %EXPORT_TAGS = (
4141

4242
sub net_saml2_sp {
4343
return Net::SAML2::SP->new(
44-
id => 'Some entity ID',
44+
issuer => 'Some entity ID',
4545
cert => 't/sign-nopw-cert.pem',
4646
key => 't/sign-nopw-cert.pem',
4747
cacert => 't/cacert.pem',

0 commit comments

Comments
 (0)