Lines 34-40
use POSIX qw/strftime/;
Link Here
|
34 |
use List::MoreUtils qw/ any /; |
34 |
use List::MoreUtils qw/ any /; |
35 |
|
35 |
|
36 |
# use utf8; |
36 |
# use utf8; |
37 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout); |
37 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $shib $shib_login); |
38 |
|
38 |
|
39 |
BEGIN { |
39 |
BEGIN { |
40 |
sub psgi_env { any { /^psgi\./ } keys %ENV } |
40 |
sub psgi_env { any { /^psgi\./ } keys %ENV } |
Lines 54-65
BEGIN {
Link Here
|
54 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
54 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
55 |
$ldap = C4::Context->config('useldapserver') || 0; |
55 |
$ldap = C4::Context->config('useldapserver') || 0; |
56 |
$cas = C4::Context->preference('casAuthentication'); |
56 |
$cas = C4::Context->preference('casAuthentication'); |
|
|
57 |
$shib = C4::Context->preference('shibbolethAuthentication'); |
57 |
$caslogout = C4::Context->preference('casLogout'); |
58 |
$caslogout = C4::Context->preference('casLogout'); |
58 |
require C4::Auth_with_cas; # no import |
59 |
require C4::Auth_with_cas; # no import |
|
|
60 |
require C4::Auth_with_Shibboleth; |
59 |
if ($ldap) { |
61 |
if ($ldap) { |
60 |
require C4::Auth_with_ldap; |
62 |
require C4::Auth_with_ldap; |
61 |
import C4::Auth_with_ldap qw(checkpw_ldap); |
63 |
import C4::Auth_with_ldap qw(checkpw_ldap); |
62 |
} |
64 |
} |
|
|
65 |
if ($shib) { |
66 |
import C4::Auth_with_Shibboleth qw(checkpw_shib logout_shib login_shib_url get_login_shib); |
67 |
# Getting user login |
68 |
$shib_login = get_login_shib(); |
69 |
} |
63 |
if ($cas) { |
70 |
if ($cas) { |
64 |
import C4::Auth_with_cas qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url); |
71 |
import C4::Auth_with_cas qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url); |
65 |
} |
72 |
} |
Lines 651-658
sub checkauth {
Link Here
|
651 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
658 |
# when using authentication against multiple CAS servers, as configured in Auth_cas_servers.yaml |
652 |
my $casparam = $query->param('cas'); |
659 |
my $casparam = $query->param('cas'); |
653 |
|
660 |
|
654 |
if ( $userid = $ENV{'REMOTE_USER'} ) { |
661 |
# Basic authentication is incompatible with the use of Shibboleth, |
655 |
# Using Basic Authentication, no cookies required |
662 |
# as Shibboleth may return REMOTE_USER as a Shibboleth attribute, |
|
|
663 |
# and it may not be the attribute we want to use to match the koha login. |
664 |
# |
665 |
# Also, do not consider an empty REMOTE_USER. |
666 |
# |
667 |
# Finally, after those tests, we can assume (although if it would be better with |
668 |
# a syspref) that if we get a REMOTE_USER, that's from basic authentication, |
669 |
# and we can affect it to $userid. |
670 |
if ( !$shib and $ENV{'REMOTE_USER'} ne '' and $userid = $ENV{'REMOTE_USER'} ) { |
671 |
|
672 |
# Using Basic Authentication, no cookies required |
656 |
$cookie = $query->cookie( |
673 |
$cookie = $query->cookie( |
657 |
-name => 'CGISESSID', |
674 |
-name => 'CGISESSID', |
658 |
-value => '', |
675 |
-value => '', |
Lines 707-717
sub checkauth {
Link Here
|
707 |
$sessionID = undef; |
724 |
$sessionID = undef; |
708 |
$userid = undef; |
725 |
$userid = undef; |
709 |
|
726 |
|
710 |
if ($cas and $caslogout) { |
727 |
if ($cas and $caslogout) { |
711 |
logout_cas($query); |
728 |
logout_cas($query); |
712 |
} |
729 |
} |
|
|
730 |
|
731 |
# If we are in a shibboleth session (shibboleth is enabled, and a shibboleth username is set) |
732 |
if ( $shib and $shib_login and $type eq 'opac') { |
733 |
# (Note: $type eq 'opac' condition should be removed when shibboleth authentication for intranet will be implemented) |
734 |
logout_shib($query); |
735 |
} |
713 |
} |
736 |
} |
714 |
elsif ( $lasttime < time() - $timeout ) { |
737 |
elsif ( $lasttime < time() - $timeout ) { |
|
|
738 |
|
715 |
# timed logout |
739 |
# timed logout |
716 |
$info{'timed_out'} = 1; |
740 |
$info{'timed_out'} = 1; |
717 |
$session->delete() if $session; |
741 |
$session->delete() if $session; |
Lines 759-774
sub checkauth {
Link Here
|
759 |
-value => $session->id, |
783 |
-value => $session->id, |
760 |
-HttpOnly => 1 |
784 |
-HttpOnly => 1 |
761 |
); |
785 |
); |
762 |
$userid = $query->param('userid'); |
786 |
$userid = $query->param('userid'); |
763 |
if ( ( $cas && $query->param('ticket') ) |
787 |
if ( ( $cas && $query->param('ticket') ) |
764 |
|| $userid |
788 |
|| $userid |
|
|
789 |
|| $shib |
765 |
|| ( my $pki_field = C4::Context->preference('AllowPKIAuth') ) ne |
790 |
|| ( my $pki_field = C4::Context->preference('AllowPKIAuth') ) ne |
766 |
'None' || $persona ) |
791 |
'None' || $persona ) |
767 |
{ |
792 |
{ |
768 |
my $password = $query->param('password'); |
793 |
my $password = $query->param('password'); |
769 |
|
794 |
|
770 |
my ( $return, $cardnumber ); |
795 |
my ( $return, $cardnumber ); |
771 |
if ( $cas && $query->param('ticket') ) { |
796 |
if ($shib && $shib_login && $type eq 'opac' && !$password) { |
|
|
797 |
my $retuserid; |
798 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
799 |
$userid = $retuserid; |
800 |
$info{'invalidShibLogin'} = 1 unless ($return); |
801 |
|
802 |
} elsif ( $cas && $query->param('ticket') ) { |
772 |
my $retuserid; |
803 |
my $retuserid; |
773 |
( $return, $cardnumber, $retuserid ) = |
804 |
( $return, $cardnumber, $retuserid ) = |
774 |
checkpw( $dbh, $userid, $password, $query ); |
805 |
checkpw( $dbh, $userid, $password, $query ); |
Lines 1013-1018
sub checkauth {
Link Here
|
1013 |
login => 1, |
1044 |
login => 1, |
1014 |
INPUTS => \@inputs, |
1045 |
INPUTS => \@inputs, |
1015 |
casAuthentication => C4::Context->preference("casAuthentication"), |
1046 |
casAuthentication => C4::Context->preference("casAuthentication"), |
|
|
1047 |
shibbolethAuthentication => C4::Context->preference("shibbolethAuthentication"), |
1016 |
suggestion => C4::Context->preference("suggestion"), |
1048 |
suggestion => C4::Context->preference("suggestion"), |
1017 |
virtualshelves => C4::Context->preference("virtualshelves"), |
1049 |
virtualshelves => C4::Context->preference("virtualshelves"), |
1018 |
LibraryName => "" . C4::Context->preference("LibraryName"), |
1050 |
LibraryName => "" . C4::Context->preference("LibraryName"), |
Lines 1084-1089
sub checkauth {
Link Here
|
1084 |
); |
1116 |
); |
1085 |
} |
1117 |
} |
1086 |
|
1118 |
|
|
|
1119 |
if ($shib) { |
1120 |
$template->param( |
1121 |
shibbolethLoginUrl => login_shib_url($query), |
1122 |
); |
1123 |
} |
1124 |
|
1087 |
my $self_url = $query->url( -absolute => 1 ); |
1125 |
my $self_url = $query->url( -absolute => 1 ); |
1088 |
$template->param( |
1126 |
$template->param( |
1089 |
url => $self_url, |
1127 |
url => $self_url, |
Lines 1510-1515
sub checkpw {
Link Here
|
1510 |
return 0; |
1548 |
return 0; |
1511 |
} |
1549 |
} |
1512 |
|
1550 |
|
|
|
1551 |
# If we are in a shibboleth session (shibboleth is enabled and no password has been provided) |
1552 |
if ($shib && !$password) { |
1553 |
|
1554 |
$debug and print STDERR "## checkpw - checking Shibboleth\n"; |
1555 |
# In case of a Shibboleth authentication, we expect a shibboleth user attribute |
1556 |
# (defined in the shibbolethLoginAttribute) tto contain the login of the |
1557 |
# shibboleth-authenticated user |
1558 |
|
1559 |
# Shibboleth attributes are mapped into http environmement variables, |
1560 |
# so we're getting the login of the user this way |
1561 |
my $attributename = C4::Context->preference('shibbolethLoginAttribute'); |
1562 |
my $attributevalue = $ENV{$attributename}; |
1563 |
|
1564 |
# Then, we check if it matches a valid koha user |
1565 |
if ($shib_login) { |
1566 |
my ( $retval, $retcard, $retuserid ) = C4::Auth_with_Shibboleth::checkpw_shib( $dbh, $shib_login ); # EXTERNAL AUTH |
1567 |
($retval) and return ( $retval, $retcard, $retuserid ); |
1568 |
return 0; |
1569 |
} |
1570 |
} |
1571 |
|
1572 |
# INTERNAL AUTH |
1513 |
return checkpw_internal(@_) |
1573 |
return checkpw_internal(@_) |
1514 |
} |
1574 |
} |
1515 |
|
1575 |
|