View | Details | Raw Unified | Return to bug 24539
Collapse All | Expand All

(-)a/C4/Auth.pm (-1 / +36 lines)
Lines 48-53 use Encode qw( encode is_utf8); Link Here
48
use C4::Auth_with_shibboleth;
48
use C4::Auth_with_shibboleth;
49
use Net::CIDR;
49
use Net::CIDR;
50
use C4::Log qw/logaction/;
50
use C4::Log qw/logaction/;
51
use Koha::AuthN::Plugin;
51
52
52
# use utf8;
53
# use utf8;
53
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout);
54
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout);
Lines 817-822 sub checkauth { Link Here
817
    my $type            = shift;
818
    my $type            = shift;
818
    my $emailaddress    = shift;
819
    my $emailaddress    = shift;
819
    my $template_name   = shift;
820
    my $template_name   = shift;
821
822
    my $extensions = shift // {};
823
824
    my $auth_plugin = $extensions->{auth_plugin};
825
820
    $type = 'opac' unless $type;
826
    $type = 'opac' unless $type;
821
827
822
    unless ( C4::Context->preference("OpacPublic") ) {
828
    unless ( C4::Context->preference("OpacPublic") ) {
Lines 904-909 sub checkauth { Link Here
904
        if ( ( $query->param('koha_login_context') && ( $q_userid ne $s_userid ) )
910
        if ( ( $query->param('koha_login_context') && ( $q_userid ne $s_userid ) )
905
            || ( $cas && $query->param('ticket') && !C4::Context->userenv->{'id'} )
911
            || ( $cas && $query->param('ticket') && !C4::Context->userenv->{'id'} )
906
            || ( $shib && $shib_login && !$logout && !C4::Context->userenv->{'id'} )
912
            || ( $shib && $shib_login && !$logout && !C4::Context->userenv->{'id'} )
913
            || ( $auth_plugin && ! $logout )
907
        ) {
914
        ) {
908
915
909
            #if a user enters an id ne to the id in the current session, we need to log them in...
916
            #if a user enters an id ne to the id in the current session, we need to log them in...
Lines 917-922 sub checkauth { Link Here
917
            $userid    = undef;
924
            $userid    = undef;
918
        }
925
        }
919
        elsif ($logout) {
926
        elsif ($logout) {
927
            #NOTE: Get authentication plugin if we logged in using one
928
            $auth_plugin = Koha::AuthN::Plugin->get_from_session({
929
                session => $session,
930
            });
920
931
921
            # voluntary logout the user
932
            # voluntary logout the user
922
            # check wether the user was using their shibboleth session or a local one
933
            # check wether the user was using their shibboleth session or a local one
Lines 929-934 sub checkauth { Link Here
929
            $sessionID = undef;
940
            $sessionID = undef;
930
            $userid    = undef;
941
            $userid    = undef;
931
942
943
            #NOTE: Logout using authentication plugin
944
            if ( $auth_plugin && $auth_plugin->can('do_logout') ){
945
                $auth_plugin->do_logout({
946
                    controller => $query,
947
                    type => $type,
948
                });
949
                #Nullify the auth_plugin now that we're logging out
950
                $auth_plugin = undef;
951
            }
952
932
            if ($cas and $caslogout) {
953
            if ($cas and $caslogout) {
933
                logout_cas($query, $type);
954
                logout_cas($query, $type);
934
            }
955
            }
Lines 1010-1015 sub checkauth { Link Here
1010
        }
1031
        }
1011
        if ( ( $cas && $query->param('ticket') )
1032
        if ( ( $cas && $query->param('ticket') )
1012
            || $q_userid
1033
            || $q_userid
1034
            || $auth_plugin
1013
            || ( $shib && $shib_login )
1035
            || ( $shib && $shib_login )
1014
            || $pki_field ne 'None'
1036
            || $pki_field ne 'None'
1015
            || $emailaddress )
1037
            || $emailaddress )
Lines 1038-1044 sub checkauth { Link Here
1038
                    $userid = $retuserid;
1060
                    $userid = $retuserid;
1039
                    $info{'invalidCasLogin'} = 1 unless ($return);
1061
                    $info{'invalidCasLogin'} = 1 unless ($return);
1040
                }
1062
                }
1041
1063
                elsif ( $auth_plugin ){
1064
                    ($return,$userid) = $auth_plugin->do_login({
1065
                        controller => $query,
1066
                        cookie => $cookie,
1067
                        session => $session,
1068
                        info => \%info,
1069
                    });
1070
                }
1042
                elsif ( $emailaddress ) {
1071
                elsif ( $emailaddress ) {
1043
                    my $value = $emailaddress;
1072
                    my $value = $emailaddress;
1044
1073
Lines 1221-1226 sub checkauth { Link Here
1221
                            $branchname    = $branches->{$br}->{'branchname'};
1250
                            $branchname    = $branches->{$br}->{'branchname'};
1222
                        }
1251
                        }
1223
                    }
1252
                    }
1253
                    if ($auth_plugin){
1254
                        Koha::AuthN::Plugin->set_login_session({
1255
                            auth_plugin => $auth_plugin,
1256
                            session => $session,
1257
                        });
1258
                    }
1224
                    $session->param( 'number',       $borrowernumber );
1259
                    $session->param( 'number',       $borrowernumber );
1225
                    $session->param( 'id',           $userid );
1260
                    $session->param( 'id',           $userid );
1226
                    $session->param( 'cardnumber',   $cardnumber );
1261
                    $session->param( 'cardnumber',   $cardnumber );
(-)a/Koha/AuthN/Plugin.pm (-1 / +49 lines)
Line 0 Link Here
0
- 
1
package Koha::AuthN::Plugin;
2
3
use Modern::Perl;
4
use Module::Load::Conditional qw(can_load);
5
6
sub get_from_session {
7
    my ($class,$args) = @_;
8
    my $auth_plugin;
9
    my $session = $args->{session};
10
    if ($session){
11
        my $auth_plugin_module = $session->param("auth_plugin_module");
12
        if ( $auth_plugin_module ){
13
            eval {
14
                if ( can_load( modules => { $auth_plugin_module => undef } ) ){
15
                    my $auth_plugin_data = $session->param("auth_plugin_data");
16
                    $auth_plugin = $auth_plugin_module->new({
17
                        data => $auth_plugin_data,
18
                    });
19
                }
20
            };
21
            if ($@){
22
                warn $@;
23
            }
24
25
        }
26
27
    }
28
    return $auth_plugin;
29
}
30
31
sub set_login_session {
32
    my ($class,$args) = @_;
33
    my $rv;
34
    my $auth_plugin = $args->{auth_plugin};
35
    my $session = $args->{session};
36
    if ( $session && $auth_plugin){
37
        $session->param( 'auth_plugin_module', ref $auth_plugin );
38
        if ( $auth_plugin->can('get_data') ){
39
            my $auth_plugin_data = $auth_plugin->get_data();
40
            if ($auth_plugin_data){
41
                $session->param( 'auth_plugin_data', $auth_plugin_data );
42
            }
43
        }
44
        $rv = 1;
45
    }
46
    return $rv;
47
}
48
49
1;

Return to bug 24539