| 1 | package Mojo::SAML::Document::AttributeConsumingService; | ||
| 2 | |||
| 3 | use Mojo::Base 'Mojo::SAML::Document'; | ||
| 4 | |||
| 5 | has template => sub { shift->build_template(<<'XML') }; | ||
| 6 | %= tag AttributeConsumingService => $self->tag_attrs => begin | ||
| 7 | % my $lang = $self->lang; | ||
| 8 | % for my $name (@{ $self->service_names }) { | ||
| 9 | <%= tag ServiceName => 'xml:lang' => $lang => $name %> | ||
| 10 | % } | ||
| 11 | % for my $desc (@{ $self->service_descriptions }) { | ||
| 12 | <%= tag ServiceDescriptor => 'xml:lang' => $lang => $desc %> | ||
| 13 | % } | ||
| 14 | % for my $attr (@{ $self->requested_attributes }) { | ||
| 15 | <%= $attr %> | ||
| 16 | % } | ||
| 17 | % end | ||
| 18 | XML | ||
| 19 | |||
| 20 | has index => sub { Carp::croak 'index is required' }; | ||
| 21 | has lang => 'en'; | ||
| 22 | has [qw/requested_attributes service_descriptions service_names/] => sub { [] }; | ||
| 23 | has [qw/is_default/]; | ||
| 24 | |||
| 25 | sub before_render { | ||
| 26 | my $self = shift; | ||
| 27 | Carp::croak 'index must be defined' | ||
| 28 | unless defined($self->index); | ||
| 29 | for my $method (qw/requested_attributes service_names/) { | ||
| 30 | Carp::croak "$method cannot be empty" unless @{$self->$method}; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | sub tag_attrs { | ||
| 35 | my $self = shift; | ||
| 36 | my @attrs = ( | ||
| 37 | xmlns => 'urn:oasis:names:tc:SAML:2.0:metadata', | ||
| 38 | index => $self->index, | ||
| 39 | ); | ||
| 40 | |||
| 41 | if (defined(my $default = $self->is_default)) { | ||
| 42 | push @attrs, isDefault => $default ? 'true' : 'false'; | ||
| 43 | } | ||
| 44 | |||
| 45 | return @attrs; | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | =head1 NAME | ||
| 51 | |||
| 52 | Mojo::SAML::Document::AttributeConsumingService | ||
| 53 | |||
| 54 | =head1 DESCRIPTION | ||
| 55 | |||
| 56 | Represents an AttributeConsumingService SAML metadata tag | ||
| 57 | |||
| 58 | =head1 ATTRIBUTES | ||
| 59 | |||
| 60 | L<Mojo::SAML::Document::AttributeConsumingService> inherits all attributes from L<Mojo::SAML::Document> and implements the following new ones. | ||
| 61 | |||
| 62 | =head2 index | ||
| 63 | |||
| 64 | Required. | ||
| 65 | The numerical index of the service for reference at a later time. | ||
| 66 | |||
| 67 | =head2 is_default | ||
| 68 | |||
| 69 | A boolean indicating whether this service should be considered the default. | ||
| 70 | May be omitted, but assumed false if not given. | ||
| 71 | Note that if no services are marked as default, the first one will be used as de-facto default. | ||
| 72 | |||
| 73 | =head2 lang | ||
| 74 | |||
| 75 | The X<xml:lang> attribute value to apply to L</name> and L</service_name> | ||
| 76 | Optional, defaults to C<en>. | ||
| 77 | |||
| 78 | =head2 requested_attributes | ||
| 79 | |||
| 80 | An array reference of L<Mojo::SAML::Document::RequestedAttribute> instance. | ||
| 81 | Must not be empty at render time. | ||
| 82 | |||
| 83 | =head2 service_descriptions | ||
| 84 | |||
| 85 | An array reference of strings describing the service for human consumption. | ||
| 86 | |||
| 87 | =head2 service_names | ||
| 88 | |||
| 89 | An array reference of strings with than name of service for human consumption. | ||
| 90 | Must not be empty at render time. | ||
| 91 | |||
| 92 | =head2 template | ||
| 93 | |||
| 94 | A template specific to the document type. | ||
| 95 | |||
| 96 | =head1 METHODS | ||
| 97 | |||
| 98 | L<Mojo::SAML::Document::AttributeConsumingService> inherits all methods from L<Mojo::SAML::Document> and implements the following new ones. | ||
| 99 | |||
| 100 | =head2 before_render | ||
| 101 | |||
| 102 | Enforces that L</index> is defined and that L</requested_attributes> and L</service_names> are not empty at render time. | ||
| 103 | |||
| 104 | =head2 tag_attrs | ||
| 105 | |||
| 106 | Generates a list of attributes for the tag. | ||
| 107 | |||
| 108 |