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

(-)a/C4/Auth.pm (+32 lines)
Lines 36-41 use Koha::AuthUtils qw(get_script_name hash_password); Link Here
36
use Koha::Library::Groups;
36
use Koha::Library::Groups;
37
use Koha::Libraries;
37
use Koha::Libraries;
38
use Koha::Patrons;
38
use Koha::Patrons;
39
use Koha::Plugins;
39
use POSIX qw/strftime/;
40
use POSIX qw/strftime/;
40
use List::MoreUtils qw/ any /;
41
use List::MoreUtils qw/ any /;
41
use Encode qw( encode is_utf8);
42
use Encode qw( encode is_utf8);
Lines 1765-1770 sub checkpw { Link Here
1765
    my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
1766
    my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
1766
    $type = 'opac' unless $type;
1767
    $type = 'opac' unless $type;
1767
1768
1769
    if ( my $module = enabled_auth_module() ) {
1770
        return $module->checkpw(@_);
1771
    }
1772
1768
    my @return;
1773
    my @return;
1769
    my $patron = Koha::Patrons->find({ userid => $userid });
1774
    my $patron = Koha::Patrons->find({ userid => $userid });
1770
    my $check_internal_as_fallback = 0;
1775
    my $check_internal_as_fallback = 0;
Lines 2088-2093 sub getborrowernumber { Link Here
2088
    return 0;
2093
    return 0;
2089
}
2094
}
2090
2095
2096
=head2 enabled_auth_module
2097
2098
  my $module = enabled_auth_module();
2099
2100
  Instantiate and return the module (object) enable for
2101
  authentication (AuthenticationModule syspref).
2102
2103
=cut
2104
2105
sub enabled_auth_module {
2106
    my $module = C4::Context->preference('AuthenticationModule');
2107
2108
    return if $module eq 'default';
2109
2110
    my @plugins = Koha::Plugins->new()->GetPlugins({
2111
        method => 'checkpw',
2112
    });
2113
2114
    foreach my $plugin (@plugins) {
2115
        if ( $plugin->{class} eq $module ) {
2116
            return $plugin;
2117
        }
2118
    }
2119
2120
    return;
2121
}
2122
2091
END { }    # module clean-up code here (global destructor)
2123
END { }    # module clean-up code here (global destructor)
2092
1;
2124
1;
2093
__END__
2125
__END__
(-)a/Koha/Plugins.pm (+1 lines)
Lines 82-87 sub GetPlugins { Link Here
82
            # Limit results by method or metadata
82
            # Limit results by method or metadata
83
            next if $method && !$plugin->can($method);
83
            next if $method && !$plugin->can($method);
84
            my $plugin_metadata = $plugin->get_metadata;
84
            my $plugin_metadata = $plugin->get_metadata;
85
85
            next if $plugin_metadata
86
            next if $plugin_metadata
86
                and %$req_metadata
87
                and %$req_metadata
87
                and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
88
                and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
(-)a/admin/preferences.pl (+12 lines)
Lines 29-34 use C4::Log; Link Here
29
use C4::Output;
29
use C4::Output;
30
use C4::Templates;
30
use C4::Templates;
31
use Koha::Acquisition::Currencies;
31
use Koha::Acquisition::Currencies;
32
use Koha::Plugins;
32
use File::Spec;
33
use File::Spec;
33
use IO::File;
34
use IO::File;
34
use YAML::Syck qw();
35
use YAML::Syck qw();
Lines 92-97 sub _get_chunk { Link Here
92
                $options{'choices'} = { map { $_ => $_ } getallthemes( 'opac' ) }
93
                $options{'choices'} = { map { $_ => $_ } getallthemes( 'opac' ) }
93
            } elsif ( $options{'choices'} eq 'staff-templates' ) {
94
            } elsif ( $options{'choices'} eq 'staff-templates' ) {
94
                $options{'choices'} = { map { $_ => $_ } getallthemes( 'intranet' ) }
95
                $options{'choices'} = { map { $_ => $_ } getallthemes( 'intranet' ) }
96
            } elsif ( $options{'choices'} eq 'auth-plugins' ) {
97
                my $choices = {'default' => 'default Koha'};
98
                my @plugins = Koha::Plugins->new()->GetPlugins({
99
                    method => 'checkpw',
100
                });
101
102
                foreach my $plugin ( @plugins ) {
103
                    my $metadata = $plugin->get_metadata;
104
                    $choices->{ $metadata->{class} } = $metadata->{name};
105
                }
106
                $options{'choices'} = $choices;
95
            } else {
107
            } else {
96
                die 'Unrecognized source of preference values: ' . $options{'choices'};
108
                die 'Unrecognized source of preference values: ' . $options{'choices'};
97
            }
109
            }
(-)a/installer/data/mysql/atomicupdate/add-AuthenticationModule-syspref.sql (+2 lines)
Line 0 Link Here
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
2
('AuthenticationModule','default','','Define the current authentication module','Plugin');
(-)a/installer/data/mysql/sysprefs.sql (-1 / +2 lines)
Lines 603-607 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
603
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
603
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
604
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
604
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
605
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
605
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
606
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
606
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
607
('AuthenticationModule','default','','Define the current authentication module','Plugin')
607
;
608
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+6 lines)
Lines 111-116 Administration: Link Here
111
              choices:
111
              choices:
112
                  yes: "Yes"
112
                  yes: "Yes"
113
                  no: "No"
113
                  no: "No"
114
    Authentication:
115
        -
116
            - Use
117
            - pref: AuthenticationModule
118
              choices: auth-plugins
119
            - module for authentication.
114
    CAS authentication:
120
    CAS authentication:
115
        -
121
        -
116
            - "Use CAS for login authentication: "
122
            - "Use CAS for login authentication: "
(-)a/t/Koha/Plugin/TestAuth.pm (+60 lines)
Line 0 Link Here
1
package Koha::Plugin::TestAuth;
2
3
use Modern::Perl;
4
5
use base 'Koha::Plugins::Base';
6
7
our $VERSION = '1.0';
8
our $metadata = {
9
    name => 'Authentication test plugin',
10
    author => 'Alex Arnaud <alex.arnaud@biblibre.com>',
11
    description => 'Plugin for testing authentication plugin API',
12
    date_authored => '2018-02-28',
13
    date_updated => '2018-02-28',
14
    minimum_version => '17.05',
15
    maximum_version => undef,
16
    type => 'authentication',
17
    version => $VERSION,
18
};
19
20
=head1 METHODS
21
22
=head2 new
23
24
    Koha::Plugin::TestAuth->new();
25
26
    Create new object
27
28
=cut
29
30
sub new {
31
    my ($class, $args) = @_;
32
33
    $args->{metadata} = $metadata;
34
    $args->{metadata}->{class} = $class;
35
36
    my $self = $class->SUPER::new($args);
37
38
    return $self;
39
}
40
41
=head2 checkpw
42
43
  ($result, cardnumber, $userid) =
44
    checkpw($self, $dbh, $userid, $password, $query, $type, $no_set_userenv);
45
46
  Authenticate a patron using login/password.
47
48
=cut
49
50
sub checkpw {
51
    my ( $self, $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
52
53
    if ( $userid = 'test' && $password eq 'test' ) {
54
        return (1, 'test', 'test');
55
    }
56
57
    return (0, '', '');
58
}
59
60
1;
(-)a/t/db_dependent/Auth.t (-2 / +15 lines)
Lines 10-16 use CGI qw ( -utf8 ); Link Here
10
use Test::MockObject;
10
use Test::MockObject;
11
use Test::MockModule;
11
use Test::MockModule;
12
use List::MoreUtils qw/all any none/;
12
use List::MoreUtils qw/all any none/;
13
use Test::More tests => 21;
13
use Test::More tests => 27;
14
use Test::Warn;
14
use Test::Warn;
15
use t::lib::Mocks;
15
use t::lib::Mocks;
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
Lines 20-27 use C4::Members; Link Here
20
use Koha::AuthUtils qw/hash_password/;
20
use Koha::AuthUtils qw/hash_password/;
21
use Koha::Database;
21
use Koha::Database;
22
use Koha::Patrons;
22
use Koha::Patrons;
23
use File::Basename;
23
24
24
BEGIN {
25
BEGIN {
26
    push( @INC, dirname(__FILE__) . '/..' );
27
25
    use_ok('C4::Auth');
28
    use_ok('C4::Auth');
26
}
29
}
27
30
Lines 32-37 my $dbh = C4::Context->dbh; Link Here
32
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction
35
# FIXME: SessionStorage defaults to mysql, but it seems to break transaction
33
# handling
36
# handling
34
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
37
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
38
t::lib::Mocks::mock_preference( 'AuthenticationModule', 'default' );
35
39
36
$schema->storage->txn_begin;
40
$schema->storage->txn_begin;
37
41
Lines 88-93 my $hash2 = hash_password('password'); Link Here
88
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
92
    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
89
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
93
    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
90
    isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
94
    isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
95
96
    t::lib::Mocks::mock_preference( 'AuthenticationModule', 'Koha::Plugin::TestAuth' );
97
    my @result = checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 );
98
    is( $result[0], 0, 'With TestAuth plugin, checkpw returns 0' );
99
    is( $result[1], '', 'With TestAuth plugin, checkpw returns empty cardnumber' );
100
    is( $result[2], '', 'With TestAuth plugin, checkpw returns empty userid' );
101
    @result = checkpw( $dbh, 'test', 'test', undef, undef, 1 );
102
    is( $result[0], 1, 'With TestAuth plugin, checkpw returns 1' );
103
    is( $result[1], 'test', 'With TestAuth plugin, checkpw returns test cardnumber' );
104
    is( $result[2], 'test', 'With TestAuth plugin, checkpw returns test userid' );
91
}
105
}
92
106
93
# get_template_and_user tests
107
# get_template_and_user tests
94
- 

Return to bug 20340