3 # Copyright 2022 Theke Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Scalar::Util qw( blessed );
24 use Try::Tiny qw( catch try );
26 use C4::Auth qw( get_template_and_user );
27 use C4::Output qw( output_html_with_http_headers );
29 use Koha::Auth::Providers;
32 my $op = $input->param('op') || 'list';
33 my $domain_ops = $input->param('domain_ops');
34 my $auth_provider_id = $input->param('auth_provider_id');
37 $auth_provider = Koha::Auth::Providers->find($auth_provider_id)
38 unless !$auth_provider_id;
40 my $template_name = $domain_ops ? 'admin/authentication_provider_domains.tt' : 'admin/authentication_providers.tt';
42 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43 { template_name => $template_name,
46 flagsrequired => { parameters => 'manage_authentication_providers' },
52 if ( !$domain_ops && $op eq 'add' ) {
54 my $code = $input->param('code');
55 my $config = $input->param('config');
56 my $description = $input->param('description');
57 my $icon_url = $input->param('icon_url');
58 my $mapping = $input->param('mapping');
59 my $matchpoint = $input->param('matchpoint'),
60 my $protocol = $input->param('protocol');
63 my $provider = Koha::Auth::Provider->new(
66 description => $description,
67 icon_url => $icon_url,
69 matchpoint => $matchpoint,
70 protocol => $protocol,
74 Koha::Auth::Provider::Domain->new(
76 auth_provider_id => $provider->auth_provider_id,
80 push @messages, { type => 'message', code => 'success_on_insert' };
83 if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
87 code => 'error_on_insert',
88 reason => 'duplicate_id'
93 # list servers after adding
96 elsif ( $domain_ops && $op eq 'add' ) {
98 my $allow_opac = $input->param('allow_opac');
99 my $allow_staff = $input->param('allow_staff');
100 my $auth_provider_id = $input->param('auth_provider_id');
101 my $auto_register = $input->param('auto_register');
102 my $default_category_id = $input->param('default_category_id');
103 my $default_library_id = $input->param('default_library_id');
104 my $domain = $input->param('domain');
105 my $update_on_auth = $input->param('update_on_auth');
109 Koha::Auth::Provider::Domain->new(
111 allow_opac => $allow_opac,
112 allow_staff => $allow_staff,
113 auth_provider_id => $auth_provider_id,
114 auto_register => $auto_register,
115 default_category_id => $default_category_id,
116 default_library_id => $default_library_id,
118 update_on_auth => $update_on_auth,
122 push @messages, { type => 'message', code => 'success_on_insert' };
125 if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
129 code => 'error_on_insert',
130 reason => 'duplicate_id'
135 # list servers after adding
138 elsif ( !$domain_ops && $op eq 'edit_form' ) {
140 if ( $auth_provider ) {
142 auth_provider => $auth_provider
149 code => 'error_on_edit',
150 reason => 'invalid_id'
154 elsif ( $domain_ops && $op eq 'edit_form' ) {
155 my $auth_provider_domain_id = $input->param('auth_provider_domain_id');
156 my $auth_provider_domain;
158 $auth_provider_domain = Koha::Auth::Provider::Domains->find($auth_provider_domain_id)
159 unless !$auth_provider_domain_id;
161 if ( $auth_provider_domain ) {
163 auth_provider_domain => $auth_provider_domain
170 code => 'error_on_edit',
171 reason => 'invalid_id'
175 elsif ( !$domain_ops && $op eq 'edit_save' ) {
177 if ( $auth_provider ) {
179 my $code = $input->param('code');
180 my $config = $input->param('config');
181 my $description = $input->param('description');
182 my $icon_url = $input->param('icon_url');
183 my $mapping = $input->param('mapping');
184 my $matchpoint = $input->param('matchpoint');
185 my $protocol = $input->param('protocol');
192 description => $description,
193 icon_url => $icon_url,
195 matchpoint => $matchpoint,
196 protocol => $protocol,
203 code => 'success_on_update'
210 code => 'error_on_update'
214 # list servers after adding
221 code => 'error_on_update',
222 reason => 'invalid_id'
226 elsif ( $domain_ops && $op eq 'edit_save' ) {
228 my $auth_provider_domain_id = $input->param('auth_provider_domain_id');
229 my $auth_provider_domain;
231 $auth_provider_domain = Koha::Auth::Provider::Domains->find($auth_provider_domain_id)
232 unless !$auth_provider_domain_id;
234 if ( $auth_provider_domain ) {
236 my $auth_provider_id = $input->param('auth_provider_id');
237 my $domain = $input->param('domain');
238 my $auto_register = $input->param('auto_register');
239 my $update_on_auth = $input->param('update_on_auth');
240 my $default_library_id = $input->param('default_library_id');
241 my $default_category_id = $input->param('default_category_id');
242 my $allow_opac = $input->param('allow_opac');
243 my $allow_staff = $input->param('allow_staff');
247 $auth_provider_domain->set(
249 auth_provider_id => $auth_provider_id,
251 auto_register => $auto_register,
252 update_on_auth => $update_on_auth,
253 default_library_id => $default_library_id,
254 default_category_id => $default_category_id,
255 allow_opac => $allow_opac,
256 allow_staff => $allow_staff,
263 code => 'success_on_update'
270 code => 'error_on_update'
274 # list servers after adding
281 code => 'error_on_update',
282 reason => 'invalid_id'
289 auth_provider_code => $auth_provider->code,
290 auth_provider_id => $auth_provider_id,
296 messages => \@messages,
299 output_html_with_http_headers $input, $cookie, $template->output;