|
Lines 22-27
use Modern::Perl;
Link Here
|
| 22 |
use base qw(Koha::Object Koha::Object::JSONFields); |
22 |
use base qw(Koha::Object Koha::Object::JSONFields); |
| 23 |
|
23 |
|
| 24 |
use Koha::Auth::Identity::Provider::Domains; |
24 |
use Koha::Auth::Identity::Provider::Domains; |
|
|
25 |
use Koha::Auth::Identity::Provider::Hostnames; |
| 26 |
use Koha::Auth::Identity::Provider::Mappings; |
| 25 |
use Koha::Exceptions; |
27 |
use Koha::Exceptions; |
| 26 |
|
28 |
|
| 27 |
=head1 NAME |
29 |
=head1 NAME |
|
Lines 46-51
sub domains {
Link Here
|
| 46 |
return Koha::Auth::Identity::Provider::Domains->_new_from_dbic( scalar $self->_result->domains ); |
48 |
return Koha::Auth::Identity::Provider::Domains->_new_from_dbic( scalar $self->_result->domains ); |
| 47 |
} |
49 |
} |
| 48 |
|
50 |
|
|
|
51 |
=head3 mappings |
| 52 |
|
| 53 |
my $mappings = $provider->mappings; |
| 54 |
|
| 55 |
Returns the related I<Koha::Auth::Identity::Provider::Mappings> iterator. |
| 56 |
|
| 57 |
=cut |
| 58 |
|
| 59 |
sub mappings { |
| 60 |
my ($self) = @_; |
| 61 |
|
| 62 |
return Koha::Auth::Identity::Provider::Mappings->_new_from_dbic( |
| 63 |
scalar $self->_result->identity_provider_mappings ); |
| 64 |
} |
| 65 |
|
| 66 |
=head3 hostnames |
| 67 |
|
| 68 |
my $hostnames = $provider->hostnames; |
| 69 |
|
| 70 |
Returns the related I<Koha::Auth::Identity::Provider::Hostnames> iterator. |
| 71 |
|
| 72 |
=cut |
| 73 |
|
| 74 |
sub hostnames { |
| 75 |
my ($self) = @_; |
| 76 |
|
| 77 |
return Koha::Auth::Identity::Provider::Hostnames->_new_from_dbic( scalar $self->_result->hostnames ); |
| 78 |
} |
| 79 |
|
| 49 |
=head3 get_config |
80 |
=head3 get_config |
| 50 |
|
81 |
|
| 51 |
my $config = $provider->get_config; |
82 |
my $config = $provider->get_config; |
|
Lines 81-86
sub get_config {
Link Here
|
| 81 |
} |
112 |
} |
| 82 |
); |
113 |
); |
| 83 |
|
114 |
|
|
|
115 |
# SAML2 (config holds protocol-specific settings like autocreate/sync/welcome) |
| 116 |
$provider->set_config( |
| 117 |
{ |
| 118 |
autocreate => 1, |
| 119 |
sync => 1, |
| 120 |
welcome => 0, |
| 121 |
} |
| 122 |
); |
| 123 |
|
| 84 |
This method stores the passed config in JSON format. |
124 |
This method stores the passed config in JSON format. |
| 85 |
|
125 |
|
| 86 |
=cut |
126 |
=cut |
|
Lines 99-151
sub set_config {
Link Here
|
| 99 |
return $self->set_encoded_json_field( { data => $config, field => 'config' } ); |
139 |
return $self->set_encoded_json_field( { data => $config, field => 'config' } ); |
| 100 |
} |
140 |
} |
| 101 |
|
141 |
|
| 102 |
=head3 get_mapping |
142 |
=head3 store |
| 103 |
|
143 |
|
| 104 |
my $mapping = $provider->get_mapping; |
144 |
Identity provider specific store method to ensure config population before saving to db |
| 105 |
|
|
|
| 106 |
Returns a I<hashref> containing the attribute mapping for the provider. |
| 107 |
|
145 |
|
| 108 |
=cut |
146 |
=cut |
| 109 |
|
147 |
|
| 110 |
sub get_mapping { |
148 |
sub store { |
| 111 |
my ($self) = @_; |
149 |
my ($self) = @_; |
| 112 |
|
150 |
$self->config( $self->config // '{}' ); |
| 113 |
return $self->decode_json_field( { field => 'mapping' } ); |
151 |
return $self->SUPER::store(); |
| 114 |
} |
|
|
| 115 |
|
| 116 |
=head3 set_mapping |
| 117 |
|
| 118 |
$provider->mapping( $mapping ); |
| 119 |
|
| 120 |
This method stores the passed mappings in JSON format. |
| 121 |
|
| 122 |
=cut |
| 123 |
|
| 124 |
sub set_mapping { |
| 125 |
my ( $self, $mapping ) = @_; |
| 126 |
|
| 127 |
return $self->set_encoded_json_field( { data => $mapping, field => 'mapping' } ); |
| 128 |
} |
| 129 |
|
| 130 |
=head3 upgrade_class |
| 131 |
|
| 132 |
my $upgraded_object = $provider->upgrade_class |
| 133 |
|
| 134 |
Returns a new instance of the object, with the right class. |
| 135 |
|
| 136 |
=cut |
| 137 |
|
| 138 |
sub upgrade_class { |
| 139 |
my ($self) = @_; |
| 140 |
my $protocol = $self->protocol; |
| 141 |
|
| 142 |
my $class = $self->protocol_to_class_mapping->{$protocol}; |
| 143 |
|
| 144 |
Koha::Exception->throw( $protocol . ' is not a valid protocol' ) |
| 145 |
unless $class; |
| 146 |
|
| 147 |
eval "require $class"; |
| 148 |
return $class->_new_from_dbic( $self->_result ); |
| 149 |
} |
152 |
} |
| 150 |
|
153 |
|
| 151 |
=head2 Internal methods |
154 |
=head2 Internal methods |
|
Lines 162-173
suitable for API output.
Link Here
|
| 162 |
sub to_api { |
165 |
sub to_api { |
| 163 |
my ( $self, $params ) = @_; |
166 |
my ( $self, $params ) = @_; |
| 164 |
|
167 |
|
| 165 |
my $config = $self->get_config; |
168 |
my $config = $self->get_config; |
| 166 |
my $mapping = $self->get_mapping; |
|
|
| 167 |
|
169 |
|
| 168 |
my $json = $self->SUPER::to_api($params); |
170 |
my $json = $self->SUPER::to_api($params); |
| 169 |
$json->{config} = $config; |
171 |
$json->{config} = $config; |
| 170 |
$json->{mapping} = $mapping; |
|
|
| 171 |
|
172 |
|
| 172 |
return $json; |
173 |
return $json; |
| 173 |
} |
174 |
} |
|
Lines 180-201
sub _type {
Link Here
|
| 180 |
return 'IdentityProvider'; |
181 |
return 'IdentityProvider'; |
| 181 |
} |
182 |
} |
| 182 |
|
183 |
|
| 183 |
=head3 protocol_to_class_mapping |
|
|
| 184 |
|
| 185 |
my $mapping = Koha::Auth::Identity::Provider::protocol_to_class_mapping |
| 186 |
|
| 187 |
Internal method that returns a mapping between I<protocol> codes and |
| 188 |
implementing I<classes>. To be used by B<upgrade_class>. |
| 189 |
|
| 190 |
=cut |
| 191 |
|
| 192 |
sub protocol_to_class_mapping { |
| 193 |
return { |
| 194 |
OAuth => 'Koha::Auth::Identity::Provider::OAuth', |
| 195 |
OIDC => 'Koha::Auth::Identity::Provider::OIDC', |
| 196 |
}; |
| 197 |
} |
| 198 |
|
| 199 |
=head3 mandatory_config_attributes |
184 |
=head3 mandatory_config_attributes |
| 200 |
|
185 |
|
| 201 |
Stub method for raising exceptions on invalid protocols. |
186 |
Stub method for raising exceptions on invalid protocols. |