|
Lines 58-71
BEGIN {
Link Here
|
| 58 |
$shib = C4::Context->config('useshibboleth') || 0; |
58 |
$shib = C4::Context->config('useshibboleth') || 0; |
| 59 |
$caslogout = C4::Context->preference('casLogout'); |
59 |
$caslogout = C4::Context->preference('casLogout'); |
| 60 |
require C4::Auth_with_cas; # no import |
60 |
require C4::Auth_with_cas; # no import |
| 61 |
require C4::Auth_with_Shibboleth; |
61 |
require C4::Auth_with_shibboleth; |
| 62 |
if ($ldap) { |
62 |
if ($ldap) { |
| 63 |
require C4::Auth_with_ldap; |
63 |
require C4::Auth_with_ldap; |
| 64 |
import C4::Auth_with_ldap qw(checkpw_ldap); |
64 |
import C4::Auth_with_ldap qw(checkpw_ldap); |
| 65 |
} |
65 |
} |
| 66 |
if ($shib) { |
66 |
if ($shib) { |
| 67 |
import C4::Auth_with_Shibboleth qw(checkpw_shib logout_shib login_shib_url get_login_shib); |
67 |
import C4::Auth_with_shibboleth |
| 68 |
# Getting user login |
68 |
qw(checkpw_shib logout_shib login_shib_url get_login_shib); |
|
|
69 |
|
| 70 |
# Get shibboleth login attribute |
| 69 |
$shib_login = get_login_shib(); |
71 |
$shib_login = get_login_shib(); |
| 70 |
} |
72 |
} |
| 71 |
if ($cas) { |
73 |
if ($cas) { |
|
Lines 296-301
sub get_template_and_user {
Link Here
|
| 296 |
} |
298 |
} |
| 297 |
else { # if this is an anonymous session, setup to display public lists... |
299 |
else { # if this is an anonymous session, setup to display public lists... |
| 298 |
|
300 |
|
|
|
301 |
# If shibboleth is enabled, and we're in an anonymous session, we should allow |
| 302 |
# the user to attemp login via shibboleth. |
| 303 |
if ( $shib ) { |
| 304 |
$template->param( shibbolethAuthentication => $shib, |
| 305 |
shibbolethLoginUrl => login_shib_url($in->{'query'}), |
| 306 |
); |
| 307 |
# If shibboleth is enabled and we have a shibboleth login attribute, |
| 308 |
# but we are in an anonymous session, then we clearly have an invalid |
| 309 |
# shibboleth koha account. |
| 310 |
if ( $shib_login ) { |
| 311 |
$template->param( invalidShibLogin => '1'); |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 299 |
$template->param( sessionID => $sessionID ); |
315 |
$template->param( sessionID => $sessionID ); |
| 300 |
|
316 |
|
| 301 |
my ($total, $pubshelves) = C4::VirtualShelves::GetSomeShelfNames(undef, 'MASTHEAD'); |
317 |
my ($total, $pubshelves) = C4::VirtualShelves::GetSomeShelfNames(undef, 'MASTHEAD'); |
|
Lines 713-719
sub checkauth {
Link Here
|
| 713 |
$session->param('surname'), $session->param('branch'), |
729 |
$session->param('surname'), $session->param('branch'), |
| 714 |
$session->param('branchname'), $session->param('flags'), |
730 |
$session->param('branchname'), $session->param('flags'), |
| 715 |
$session->param('emailaddress'), $session->param('branchprinter'), |
731 |
$session->param('emailaddress'), $session->param('branchprinter'), |
| 716 |
$session->param('persona') |
732 |
$session->param('persona'), $session->param('shibboleth') |
| 717 |
); |
733 |
); |
| 718 |
C4::Context::set_shelves_userenv('bar',$session->param('barshelves')); |
734 |
C4::Context::set_shelves_userenv('bar',$session->param('barshelves')); |
| 719 |
C4::Context::set_shelves_userenv('pub',$session->param('pubshelves')); |
735 |
C4::Context::set_shelves_userenv('pub',$session->param('pubshelves')); |
|
Lines 725-731
sub checkauth {
Link Here
|
| 725 |
$sessiontype = $session->param('sessiontype') || ''; |
741 |
$sessiontype = $session->param('sessiontype') || ''; |
| 726 |
} |
742 |
} |
| 727 |
if ( ( $query->param('koha_login_context') && ($q_userid ne $s_userid) ) |
743 |
if ( ( $query->param('koha_login_context') && ($q_userid ne $s_userid) ) |
| 728 |
|| ( $cas && $query->param('ticket') ) ) { |
744 |
|| ( $cas && $query->param('ticket') ) || ( $shib && $shib_login && !$logout ) ) { |
| 729 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
745 |
#if a user enters an id ne to the id in the current session, we need to log them in... |
| 730 |
#first we need to clear the anonymous session... |
746 |
#first we need to clear the anonymous session... |
| 731 |
$debug and warn "query id = $q_userid but session id = $s_userid"; |
747 |
$debug and warn "query id = $q_userid but session id = $s_userid"; |
|
Lines 738-743
sub checkauth {
Link Here
|
| 738 |
} |
754 |
} |
| 739 |
elsif ($logout) { |
755 |
elsif ($logout) { |
| 740 |
# voluntary logout the user |
756 |
# voluntary logout the user |
|
|
757 |
# check wether the user was using their shibboleth session or a local one |
| 758 |
my $shibSuccess = C4::Context->userenv->{'shibboleth'}; |
| 741 |
$session->delete(); |
759 |
$session->delete(); |
| 742 |
$session->flush; |
760 |
$session->flush; |
| 743 |
C4::Context->_unset_userenv($sessionID); |
761 |
C4::Context->_unset_userenv($sessionID); |
|
Lines 749-756
sub checkauth {
Link Here
|
| 749 |
logout_cas($query); |
767 |
logout_cas($query); |
| 750 |
} |
768 |
} |
| 751 |
|
769 |
|
| 752 |
# If we are in a shibboleth session (shibboleth is enabled, and a shibboleth username is set) |
770 |
# If we are in a shibboleth session (shibboleth is enabled, a shibboleth match attribute is set and matches koha matchpoint) |
| 753 |
if ( $shib and $shib_login and $type eq 'opac') { |
771 |
if ( $shib and $shib_login and $shibSuccess and $type eq 'opac') { |
| 754 |
# (Note: $type eq 'opac' condition should be removed when shibboleth authentication for intranet will be implemented) |
772 |
# (Note: $type eq 'opac' condition should be removed when shibboleth authentication for intranet will be implemented) |
| 755 |
logout_shib($query); |
773 |
logout_shib($query); |
| 756 |
} |
774 |
} |
|
Lines 823-842
sub checkauth {
Link Here
|
| 823 |
} |
841 |
} |
| 824 |
if ( ( $cas && $query->param('ticket') ) |
842 |
if ( ( $cas && $query->param('ticket') ) |
| 825 |
|| $userid |
843 |
|| $userid |
| 826 |
|| $shib |
844 |
|| ( $shib && $shib_login ) |
| 827 |
|| $pki_field ne 'None' |
845 |
|| $pki_field ne 'None' |
| 828 |
|| $persona ) |
846 |
|| $persona ) |
| 829 |
{ |
847 |
{ |
| 830 |
my $password = $query->param('password'); |
848 |
my $password = $query->param('password'); |
|
|
849 |
my $shibSuccess = 0; |
| 831 |
|
850 |
|
| 832 |
my ( $return, $cardnumber ); |
851 |
my ( $return, $cardnumber ); |
| 833 |
if ($shib && $shib_login && $type eq 'opac' && !$password) { |
852 |
# If shib is enabled and we have a shib login, does the login match a valid koha user |
|
|
853 |
if ( $shib && $shib_login && $type eq 'opac' ) { |
| 834 |
my $retuserid; |
854 |
my $retuserid; |
| 835 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
855 |
# Do not pass password here, else shib will not be checked in checkpw. |
|
|
856 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, undef, $query ); |
| 836 |
$userid = $retuserid; |
857 |
$userid = $retuserid; |
|
|
858 |
$shibSuccess = $return; |
| 837 |
$info{'invalidShibLogin'} = 1 unless ($return); |
859 |
$info{'invalidShibLogin'} = 1 unless ($return); |
| 838 |
|
860 |
} |
| 839 |
} elsif ( $cas && $query->param('ticket') ) { |
861 |
# If shib login and match were successfull, skip further login methods |
|
|
862 |
unless ( $shibSuccess ) { |
| 863 |
if ( $cas && $query->param('ticket') ) { |
| 840 |
my $retuserid; |
864 |
my $retuserid; |
| 841 |
( $return, $cardnumber, $retuserid ) = |
865 |
( $return, $cardnumber, $retuserid ) = |
| 842 |
checkpw( $dbh, $userid, $password, $query ); |
866 |
checkpw( $dbh, $userid, $password, $query ); |
|
Lines 903-909
sub checkauth {
Link Here
|
| 903 |
( $return, $cardnumber, $retuserid ) = |
927 |
( $return, $cardnumber, $retuserid ) = |
| 904 |
checkpw( $dbh, $userid, $password, $query ); |
928 |
checkpw( $dbh, $userid, $password, $query ); |
| 905 |
$userid = $retuserid if ( $retuserid ); |
929 |
$userid = $retuserid if ( $retuserid ); |
| 906 |
} |
930 |
$info{'invalid_username_or_password'} = 1 unless ($return); |
|
|
931 |
} } |
| 907 |
if ($return) { |
932 |
if ($return) { |
| 908 |
#_session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime)); |
933 |
#_session_log(sprintf "%20s from %16s logged in at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime)); |
| 909 |
if ( $flags = haspermission( $userid, $flagsrequired ) ) { |
934 |
if ( $flags = haspermission( $userid, $flagsrequired ) ) { |
|
Lines 991-996
sub checkauth {
Link Here
|
| 991 |
$session->param('emailaddress',$emailaddress); |
1016 |
$session->param('emailaddress',$emailaddress); |
| 992 |
$session->param('ip',$session->remote_addr()); |
1017 |
$session->param('ip',$session->remote_addr()); |
| 993 |
$session->param('lasttime',time()); |
1018 |
$session->param('lasttime',time()); |
|
|
1019 |
$session->param('shibboleth',$shibSuccess); |
| 994 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; |
1020 |
$debug and printf STDERR "AUTH_4: (%s)\t%s %s - %s\n", map {$session->param($_)} qw(cardnumber firstname surname branch) ; |
| 995 |
} |
1021 |
} |
| 996 |
elsif ( $return == 2 ) { |
1022 |
elsif ( $return == 2 ) { |
|
Lines 1017-1023
sub checkauth {
Link Here
|
| 1017 |
$session->param('surname'), $session->param('branch'), |
1043 |
$session->param('surname'), $session->param('branch'), |
| 1018 |
$session->param('branchname'), $session->param('flags'), |
1044 |
$session->param('branchname'), $session->param('flags'), |
| 1019 |
$session->param('emailaddress'), $session->param('branchprinter'), |
1045 |
$session->param('emailaddress'), $session->param('branchprinter'), |
| 1020 |
$session->param('persona') |
1046 |
$session->param('persona'), $session->param('shibboleth') |
| 1021 |
); |
1047 |
); |
| 1022 |
|
1048 |
|
| 1023 |
} |
1049 |
} |
|
Lines 1156-1161
sub checkauth {
Link Here
|
| 1156 |
|
1182 |
|
| 1157 |
if ($shib) { |
1183 |
if ($shib) { |
| 1158 |
$template->param( |
1184 |
$template->param( |
|
|
1185 |
shibbolethAuthentication => $shib, |
| 1159 |
shibbolethLoginUrl => login_shib_url($query), |
1186 |
shibbolethLoginUrl => login_shib_url($query), |
| 1160 |
); |
1187 |
); |
| 1161 |
} |
1188 |
} |
|
Lines 1576-1582
sub get_session {
Link Here
|
| 1576 |
|
1603 |
|
| 1577 |
sub checkpw { |
1604 |
sub checkpw { |
| 1578 |
my ( $dbh, $userid, $password, $query ) = @_; |
1605 |
my ( $dbh, $userid, $password, $query ) = @_; |
| 1579 |
|
|
|
| 1580 |
if ($ldap) { |
1606 |
if ($ldap) { |
| 1581 |
$debug and print STDERR "## checkpw - checking LDAP\n"; |
1607 |
$debug and print STDERR "## checkpw - checking LDAP\n"; |
| 1582 |
my ($retval,$retcard,$retuserid) = checkpw_ldap(@_); # EXTERNAL AUTH |
1608 |
my ($retval,$retcard,$retuserid) = checkpw_ldap(@_); # EXTERNAL AUTH |
|
Lines 1594-1610
sub checkpw {
Link Here
|
| 1594 |
return 0; |
1620 |
return 0; |
| 1595 |
} |
1621 |
} |
| 1596 |
|
1622 |
|
| 1597 |
# If we are in a shibboleth session (shibboleth is enabled and no password has been provided) |
1623 |
# If we are in a shibboleth session (shibboleth is enabled, and a shibboleth match attribute is present) |
| 1598 |
if ($shib && !$password) { |
1624 |
# Check for password to asertain whether we want to be testing against shibboleth or another method this |
|
|
1625 |
# time around. |
| 1626 |
if ($shib && $shib_login && !$password) { |
| 1599 |
|
1627 |
|
| 1600 |
$debug and print STDERR "## checkpw - checking Shibboleth\n"; |
1628 |
$debug and print STDERR "## checkpw - checking Shibboleth\n"; |
| 1601 |
# In case of a Shibboleth authentication, we expect a shibboleth user attribute |
1629 |
# In case of a Shibboleth authentication, we expect a shibboleth user attribute |
| 1602 |
# (defined in the shibbolethLoginAttribute) tto contain the login of the |
1630 |
# (defined under shibboleth mapping in koha-conf.xml) to contain the login of the |
| 1603 |
# shibboleth-authenticated user |
1631 |
# shibboleth-authenticated user |
| 1604 |
|
1632 |
|
| 1605 |
# Then, we check if it matches a valid koha user |
1633 |
# Then, we check if it matches a valid koha user |
| 1606 |
if ($shib_login) { |
1634 |
if ($shib_login) { |
| 1607 |
my ( $retval, $retcard, $retuserid ) = C4::Auth_with_Shibboleth::checkpw_shib( $dbh, $shib_login ); # EXTERNAL AUTH |
1635 |
my ( $retval, $retcard, $retuserid ) = C4::Auth_with_shibboleth::checkpw_shib( $dbh, $shib_login ); # EXTERNAL AUTH |
| 1608 |
($retval) and return ( $retval, $retcard, $retuserid ); |
1636 |
($retval) and return ( $retval, $retcard, $retuserid ); |
| 1609 |
return 0; |
1637 |
return 0; |
| 1610 |
} |
1638 |
} |