@@ -, +, @@ --- C4/Auth.pm | 31 ++++++++++++++++--- C4/Auth_with_cas.pm | 21 ++++++++++--- koha-tmpl/opac-tmpl/prog/en/modules/opac-auth.tmpl | 14 ++++++++- 3 files changed, 55 insertions(+), 11 deletions(-) --- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -943,12 +943,33 @@ sub checkauth { $template->param( OpacPublic => C4::Context->preference("OpacPublic")); $template->param( loginprompt => 1 ) unless $info{'nopermission'}; - if ($cas) { + if ($cas) { + + # Is authentication against multiple CAS servers enabled? + + if (C4::Auth_with_cas::multipleAuth && !$casparam) { + my $casservers = C4::Auth_with_cas::getMultipleAuth(); +# warn Data::Dumper::Dumper($casservers); + my @tmplservers; + foreach my $key (keys %$casservers) { + warn $key, $casservers->{$key}; + push @tmplservers, {name => $key, value => login_cas_url($query, $key)}; + } + #warn Data::Dumper::Dumper(\@tmplservers); + $template->param( + casServersLoop => \@tmplservers + ); + } else { + $template->param( + casServerUrl => login_cas_url($query), + ); + } + $template->param( - casServerUrl => login_cas_url($query), - invalidCasLogin => $info{'invalidCasLogin'} - ); - } + invalidCasLogin => $info{'invalidCasLogin'} + ); + } + my $self_url = $query->url( -absolute => 1 ); $template->param( url => $self_url, --- a/C4/Auth_with_cas.pm +++ a/C4/Auth_with_cas.pm @@ -40,11 +40,12 @@ BEGIN { my $context = C4::Context->new() or die 'C4::Context->new failed'; my $defaultcasserver; my $casservers; +my $yamlauthfile = "../C4/Auth_cas_servers.yaml"; # If there's a configuration for multiple cas servers, then we get it -if (-e qq($FindBin::Bin/../C4/Auth_cas_servers.yaml)) { - ($defaultcasserver, $casservers) = YAML::LoadFile(qq($FindBin::Bin/../C4/Auth_cas_servers.yaml)); +if (multipleAuth()) { + ($defaultcasserver, $casservers) = YAML::LoadFile(qq($FindBin::Bin/$yamlauthfile)); $defaultcasserver = $defaultcasserver->{'default'}; } else { # Else, we fall back to casServerUrl syspref @@ -52,6 +53,16 @@ if (-e qq($FindBin::Bin/../C4/Auth_cas_servers.yaml)) { $casservers = { 'default' => C4::Context->preference('casServerUrl') }; } +# Is there a configuration file for multiple cas servers? +sub multipleAuth { + return (-e qq($FindBin::Bin/$yamlauthfile)); +} + +# Returns configured CAS servers' list if multiple authentication is enabled +sub getMultipleAuth { + return $casservers; +} + # Logout from CAS sub logout_cas { my ($query) = @_; @@ -71,7 +82,6 @@ sub login_cas { my $casparam = $query->param('cas'); # FIXME: This should be more generic and handle whatever parameters there might be $uri .= "?cas=" . $casparam if (defined $casparam); - warn $defaultcasserver; $casparam = $defaultcasserver if (not defined $casparam); my $cas = Authen::CAS::Client->new($casservers->{$casparam}); print $query->redirect( $cas->login_url($uri)); @@ -79,13 +89,14 @@ sub login_cas { # Returns CAS login URL with callback to the requesting URL sub login_cas_url { - my ($query) = @_; + + my ($query, $key) = @_; my $uri = $ENV{'SCRIPT_URI'}; my $casparam = $query->param('cas'); # FIXME: This should be more generic and handle whatever parameters there might be $uri .= "?cas=" . $casparam if (defined $casparam); $casparam = $defaultcasserver if (not defined $casparam); - warn $defaultcasserver; + $casparam = $key if (defined $key); my $cas = Authen::CAS::Client->new($casservers->{$casparam}); return $cas->login_url($uri); } --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth.tmpl +++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth.tmpl @@ -53,7 +53,19 @@

Sorry, the CAS login failed.

-

If you have a CAS account, please ">click here to login.

+

If you have a CAS account, + + please ">click here to login.

+ + + +please choose against which one you would like to authenticate:

+

Local Login

If you do not have a CAS account, but a local account, you can still log in :

--