Lines 36-42
use POSIX qw/strftime/;
Link Here
|
36 |
use List::MoreUtils qw/ any /; |
36 |
use List::MoreUtils qw/ any /; |
37 |
|
37 |
|
38 |
# use utf8; |
38 |
# use utf8; |
39 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout); |
39 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $shib $shib_login); |
40 |
|
40 |
|
41 |
BEGIN { |
41 |
BEGIN { |
42 |
sub psgi_env { any { /^psgi\./ } keys %ENV } |
42 |
sub psgi_env { any { /^psgi\./ } keys %ENV } |
Lines 55-66
BEGIN {
Link Here
|
55 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
55 |
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] ); |
56 |
$ldap = C4::Context->config('useldapserver') || 0; |
56 |
$ldap = C4::Context->config('useldapserver') || 0; |
57 |
$cas = C4::Context->preference('casAuthentication'); |
57 |
$cas = C4::Context->preference('casAuthentication'); |
|
|
58 |
$shib = C4::Context->preference('shibbolethAuthentication'); |
58 |
$caslogout = C4::Context->preference('casLogout'); |
59 |
$caslogout = C4::Context->preference('casLogout'); |
59 |
require C4::Auth_with_cas; # no import |
60 |
require C4::Auth_with_cas; # no import |
|
|
61 |
require C4::Auth_with_Shibboleth; |
60 |
if ($ldap) { |
62 |
if ($ldap) { |
61 |
require C4::Auth_with_ldap; |
63 |
require C4::Auth_with_ldap; |
62 |
import C4::Auth_with_ldap qw(checkpw_ldap); |
64 |
import C4::Auth_with_ldap qw(checkpw_ldap); |
63 |
} |
65 |
} |
|
|
66 |
if ($shib) { |
67 |
import C4::Auth_with_Shibboleth qw(checkpw_shib logout_shib login_shib_url get_login_shib); |
68 |
# Getting user login |
69 |
$shib_login = get_login_shib(); |
70 |
} |
64 |
if ($cas) { |
71 |
if ($cas) { |
65 |
import C4::Auth_with_cas qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url); |
72 |
import C4::Auth_with_cas qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url); |
66 |
} |
73 |
} |
Lines 666-673
sub checkauth {
Link Here
|
666 |
my $casparam = $query->param('cas'); |
673 |
my $casparam = $query->param('cas'); |
667 |
my $q_userid = $query->param('userid') // ''; |
674 |
my $q_userid = $query->param('userid') // ''; |
668 |
|
675 |
|
669 |
if ( $userid = $ENV{'REMOTE_USER'} ) { |
676 |
# Basic authentication is incompatible with the use of Shibboleth, |
670 |
# Using Basic Authentication, no cookies required |
677 |
# as Shibboleth may return REMOTE_USER as a Shibboleth attribute, |
|
|
678 |
# and it may not be the attribute we want to use to match the koha login. |
679 |
# |
680 |
# Also, do not consider an empty REMOTE_USER. |
681 |
# |
682 |
# Finally, after those tests, we can assume (although if it would be better with |
683 |
# a syspref) that if we get a REMOTE_USER, that's from basic authentication, |
684 |
# and we can affect it to $userid. |
685 |
if ( !$shib and $ENV{'REMOTE_USER'} ne '' and $userid = $ENV{'REMOTE_USER'} ) { |
686 |
|
687 |
# Using Basic Authentication, no cookies required |
671 |
$cookie = $query->cookie( |
688 |
$cookie = $query->cookie( |
672 |
-name => 'CGISESSID', |
689 |
-name => 'CGISESSID', |
673 |
-value => '', |
690 |
-value => '', |
Lines 725-733
sub checkauth {
Link Here
|
725 |
$sessionID = undef; |
742 |
$sessionID = undef; |
726 |
$userid = undef; |
743 |
$userid = undef; |
727 |
|
744 |
|
728 |
if ($cas and $caslogout) { |
745 |
if ($cas and $caslogout) { |
729 |
logout_cas($query); |
746 |
logout_cas($query); |
730 |
} |
747 |
} |
|
|
748 |
|
749 |
# If we are in a shibboleth session (shibboleth is enabled, and a shibboleth username is set) |
750 |
if ( $shib and $shib_login and $type eq 'opac') { |
751 |
# (Note: $type eq 'opac' condition should be removed when shibboleth authentication for intranet will be implemented) |
752 |
logout_shib($query); |
753 |
} |
731 |
} |
754 |
} |
732 |
elsif ( !$lasttime || ($lasttime < time() - $timeout) ) { |
755 |
elsif ( !$lasttime || ($lasttime < time() - $timeout) ) { |
733 |
# timed logout |
756 |
# timed logout |
Lines 797-809
sub checkauth {
Link Here
|
797 |
} |
820 |
} |
798 |
if ( ( $cas && $query->param('ticket') ) |
821 |
if ( ( $cas && $query->param('ticket') ) |
799 |
|| $userid |
822 |
|| $userid |
|
|
823 |
|| $shib |
800 |
|| $pki_field ne 'None' |
824 |
|| $pki_field ne 'None' |
801 |
|| $persona ) |
825 |
|| $persona ) |
802 |
{ |
826 |
{ |
803 |
my $password = $query->param('password'); |
827 |
my $password = $query->param('password'); |
804 |
|
828 |
|
805 |
my ( $return, $cardnumber ); |
829 |
my ( $return, $cardnumber ); |
806 |
if ( $cas && $query->param('ticket') ) { |
830 |
if ($shib && $shib_login && $type eq 'opac' && !$password) { |
|
|
831 |
my $retuserid; |
832 |
( $return, $cardnumber, $retuserid ) = checkpw( $dbh, $userid, $password, $query ); |
833 |
$userid = $retuserid; |
834 |
$info{'invalidShibLogin'} = 1 unless ($return); |
835 |
|
836 |
} elsif ( $cas && $query->param('ticket') ) { |
807 |
my $retuserid; |
837 |
my $retuserid; |
808 |
( $return, $cardnumber, $retuserid ) = |
838 |
( $return, $cardnumber, $retuserid ) = |
809 |
checkpw( $dbh, $userid, $password, $query ); |
839 |
checkpw( $dbh, $userid, $password, $query ); |
Lines 1050-1055
sub checkauth {
Link Here
|
1050 |
login => 1, |
1080 |
login => 1, |
1051 |
INPUTS => \@inputs, |
1081 |
INPUTS => \@inputs, |
1052 |
casAuthentication => C4::Context->preference("casAuthentication"), |
1082 |
casAuthentication => C4::Context->preference("casAuthentication"), |
|
|
1083 |
shibbolethAuthentication => C4::Context->preference("shibbolethAuthentication"), |
1053 |
suggestion => C4::Context->preference("suggestion"), |
1084 |
suggestion => C4::Context->preference("suggestion"), |
1054 |
virtualshelves => C4::Context->preference("virtualshelves"), |
1085 |
virtualshelves => C4::Context->preference("virtualshelves"), |
1055 |
LibraryName => "" . C4::Context->preference("LibraryName"), |
1086 |
LibraryName => "" . C4::Context->preference("LibraryName"), |
Lines 1121-1126
sub checkauth {
Link Here
|
1121 |
); |
1152 |
); |
1122 |
} |
1153 |
} |
1123 |
|
1154 |
|
|
|
1155 |
if ($shib) { |
1156 |
$template->param( |
1157 |
shibbolethLoginUrl => login_shib_url($query), |
1158 |
); |
1159 |
} |
1160 |
|
1124 |
my $self_url = $query->url( -absolute => 1 ); |
1161 |
my $self_url = $query->url( -absolute => 1 ); |
1125 |
$template->param( |
1162 |
$template->param( |
1126 |
url => $self_url, |
1163 |
url => $self_url, |
Lines 1554-1559
sub checkpw {
Link Here
|
1554 |
return 0; |
1591 |
return 0; |
1555 |
} |
1592 |
} |
1556 |
|
1593 |
|
|
|
1594 |
# If we are in a shibboleth session (shibboleth is enabled and no password has been provided) |
1595 |
if ($shib && !$password) { |
1596 |
|
1597 |
$debug and print STDERR "## checkpw - checking Shibboleth\n"; |
1598 |
# In case of a Shibboleth authentication, we expect a shibboleth user attribute |
1599 |
# (defined in the shibbolethLoginAttribute) tto contain the login of the |
1600 |
# shibboleth-authenticated user |
1601 |
|
1602 |
# Shibboleth attributes are mapped into http environmement variables, |
1603 |
# so we're getting the login of the user this way |
1604 |
my $attributename = C4::Context->preference('shibbolethLoginAttribute'); |
1605 |
my $attributevalue = $ENV{$attributename}; |
1606 |
|
1607 |
# Then, we check if it matches a valid koha user |
1608 |
if ($shib_login) { |
1609 |
my ( $retval, $retcard, $retuserid ) = C4::Auth_with_Shibboleth::checkpw_shib( $dbh, $shib_login ); # EXTERNAL AUTH |
1610 |
($retval) and return ( $retval, $retcard, $retuserid ); |
1611 |
return 0; |
1612 |
} |
1613 |
} |
1614 |
|
1615 |
# INTERNAL AUTH |
1557 |
return checkpw_internal(@_) |
1616 |
return checkpw_internal(@_) |
1558 |
} |
1617 |
} |
1559 |
|
1618 |
|