From 70540fb131c58cf4fb012854759eef2d73528a30 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Thu, 7 Aug 2008 04:38:22 +0000 Subject: Bug 438435: Need code hooks for authentication Patch By Max Kanat-Alexander r=LpSolit, a=mkanat --- Bugzilla/Auth/Login/Stack.pm | 16 ++++++--- Bugzilla/Auth/Verify/Stack.pm | 16 ++++++--- Bugzilla/Config.pm | 12 +++++-- Bugzilla/Config/Common.pm | 8 +---- Bugzilla/Hook.pm | 82 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 17 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Auth/Login/Stack.pm b/Bugzilla/Auth/Login/Stack.pm index d51003861..ab9a93bce 100644 --- a/Bugzilla/Auth/Login/Stack.pm +++ b/Bugzilla/Auth/Login/Stack.pm @@ -26,16 +26,24 @@ use fields qw( _stack successful ); +use Hash::Util qw(lock_keys); +use Bugzilla::Hook; sub new { my $class = shift; my $self = $class->SUPER::new(@_); my $list = shift; + my %methods = map { $_ => "Bugzilla/Auth/Login/$_.pm" } split(',', $list); + lock_keys(%methods); + Bugzilla::Hook::process('auth-login_methods', { modules => \%methods }); + $self->{_stack} = []; - foreach my $login_method (split(',', $list)) { - require "Bugzilla/Auth/Login/${login_method}.pm"; - push(@{$self->{_stack}}, - "Bugzilla::Auth::Login::$login_method"->new(@_)); + foreach my $login_method (keys %methods) { + my $module = $methods{$login_method}; + require $module; + $module =~ s|/|::|g; + $module =~ s/.pm$//; + push(@{$self->{_stack}}, $module->new(@_)); } return $self; } diff --git a/Bugzilla/Auth/Verify/Stack.pm b/Bugzilla/Auth/Verify/Stack.pm index 577b5a22f..0ddb9a441 100644 --- a/Bugzilla/Auth/Verify/Stack.pm +++ b/Bugzilla/Auth/Verify/Stack.pm @@ -21,16 +21,24 @@ use fields qw( _stack successful ); +use Hash::Util qw(lock_keys); +use Bugzilla::Hook; sub new { my $class = shift; my $list = shift; my $self = $class->SUPER::new(@_); + my %methods = map { $_ => "Bugzilla/Auth/Verify/$_.pm" } split(',', $list); + lock_keys(%methods); + Bugzilla::Hook::process('auth-verify_methods', { modules => \%methods }); + $self->{_stack} = []; - foreach my $verify_method (split(',', $list)) { - require "Bugzilla/Auth/Verify/${verify_method}.pm"; - push(@{$self->{_stack}}, - "Bugzilla::Auth::Verify::$verify_method"->new(@_)); + foreach my $verify_method (keys %methods) { + my $module = $methods{$verify_method}; + require $module; + $module =~ s|/|::|g; + $module =~ s/.pm$//; + push(@{$self->{_stack}}, $module->new(@_)); } return $self; } diff --git a/Bugzilla/Config.pm b/Bugzilla/Config.pm index 428c13fe5..3666861f0 100644 --- a/Bugzilla/Config.pm +++ b/Bugzilla/Config.pm @@ -34,6 +34,7 @@ use strict; use base qw(Exporter); use Bugzilla::Constants; +use Bugzilla::Hook; use Data::Dumper; use File::Temp; @@ -54,15 +55,21 @@ our %params; # Load in the param definitions sub _load_params { my $panels = param_panels(); + my %hook_panels; foreach my $panel (keys %$panels) { my $module = $panels->{$panel}; eval("require $module") || die $@; - my @new_param_list = "$module"->get_param_list(); + my @new_param_list = $module->get_param_list(); + $hook_panels{lc($panel)} = { params => \@new_param_list }; foreach my $item (@new_param_list) { $params{$item->{'name'}} = $item; } push(@param_list, @new_param_list); } + # This hook is also called in editparams.cgi. This call here is required + # to make SetParam work. + Bugzilla::Hook::process('config-modify_panels', + { panels => \%hook_panels }); } # END INIT CODE @@ -77,7 +84,8 @@ sub param_panels { $param_panels->{$module} = "Bugzilla::Config::$module" unless $module eq 'Common'; } # Now check for any hooked params - Bugzilla::Hook::process('config', { config => $param_panels }); + Bugzilla::Hook::process('config-add_panels', + { panel_modules => $param_panels }); return $param_panels; } diff --git a/Bugzilla/Config/Common.pm b/Bugzilla/Config/Common.pm index e6f0398e3..39fc114d6 100644 --- a/Bugzilla/Config/Common.pm +++ b/Bugzilla/Config/Common.pm @@ -277,10 +277,7 @@ sub check_user_verify_class { for my $class (split /,\s*/, $list) { my $res = check_multi($class, $entry); return $res if $res; - if ($class eq 'DB') { - # No params - } - elsif ($class eq 'RADIUS') { + if ($class eq 'RADIUS') { eval "require Authen::Radius"; return "Error requiring Authen::Radius: '$@'" if $@; return "RADIUS servername (RADIUS_server) is missing" unless Bugzilla->params->{"RADIUS_server"}; @@ -292,9 +289,6 @@ sub check_user_verify_class { return "LDAP servername (LDAPserver) is missing" unless Bugzilla->params->{"LDAPserver"}; return "LDAPBaseDN is empty" unless Bugzilla->params->{"LDAPBaseDN"}; } - else { - return "Unknown user_verify_class '$class' in check_user_verify_class"; - } } return ""; } diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 1b4a5ad32..4fb1424f8 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -198,6 +198,88 @@ The definition is structured as: =back +=head2 auth-login_methods + +This allows you to add new login types to Bugzilla. +(See L.) + +Params: + +=over + +=item C + +This is a hash--a mapping from login-type "names" to the actual module on +disk. The keys will be all the values that were passed to +L for the C parameter. The values are the +actual path to the module on disk. (For example, if the key is C, the +value is F.) + +For your extension, the path will start with +F. (See the code in the example extension.) + +If your login type is in the hash as a key, you should set that key to the +right path to your module. That module's C method will be called, +probably with empty parameters. If your login type is I in the hash, +you should not set it. + +You will be prevented from adding new keys to the hash, so make sure your +key is in there before you modify it. (In other words, you can't add in +login methods that weren't passed to L.) + +=back + +=head2 auth-verify_methods + +This works just like L except it's for +login verification methods (See L.) It also +takes a C parameter, just like L. + +=head2 config-add_panels + +If you want to add new panels to the Parameters administrative interface, +this is where you do it. + +Params: + +=over + +=item C + +A hashref, where the keys are the "name" of the module and the value +is the Perl module containing that config module. For example, if +the name is C, the value would be C. + +For your extension, the Perl module name must start with +C. (See the code in the example +extension.) + +=back + +=head2 config-modify_panels + +This is how you modify already-existing panels in the Parameters +administrative interface. For example, if you wanted to add a new +Auth method (modifying Bugzilla::Config::Auth) this is how you'd +do it. + +Params: + +=over + +=item C + +A hashref, where the keys are lower-case panel "names" (like C, +C, etc.) and the values are hashrefs. The hashref contains a +single key, C. C is an arrayref--the return value from +C for that module. You can modify C and +your changes will be reflected in the interface. + +Adding new keys to C will have no effect. You should use +L if you want to add new panels. + +=back + =head2 enter_bug-entrydefaultvars This happens right before the template is loaded on enter_bug.cgi. -- cgit v1.2.3-24-g4f1b