[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.5-166-g7363325
jesse
jesse at bestpractical.com
Tue Sep 29 15:52:26 EDT 2009
The branch, 3.8-trunk has been updated
via 736332582a108dedef15e14249d5eb7fedcd43f4 (commit)
from 0966ecc1a8a0561c062dbee32e71e92f163f4827 (commit)
Summary of changes:
lib/RT/Interface/Web.pm | 88 +++++++++++++++++++++++++++++++++++++++++++++++
share/html/autohandler | 80 ++-----------------------------------------
2 files changed, 91 insertions(+), 77 deletions(-)
- Log -----------------------------------------------------------------
commit 736332582a108dedef15e14249d5eb7fedcd43f4
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Wed Sep 30 04:52:08 2009 +0900
Extract the "ExternalAuth" part of the autohandler into a function
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 8b63464..bf538a0 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -249,6 +249,94 @@ sub ShowRequestedPage {
}
+sub AttemptExternalAuth {
+ my $ARGS = shift;
+
+ return unless ( RT->Config->Get('WebExternalAuth') );
+
+ my $user = $ARGS->{user};
+ my $m = $HTML::Mason::Commands::m;
+
+ # If RT is configured for external auth, let's go through and get REMOTE_USER
+
+ # do we actually have a REMOTE_USER equivlent?
+ if ( RT::Interface::Web::WebCanonicalizeInfo() ) {
+ my $orig_user = $user;
+
+ $user = RT::Interface::Web::WebCanonicalizeInfo();
+ $HTML::Mason::Commands::session{'CurrentUser'} = RT::CurrentUser->new();
+ my $load_method = RT->Config->Get('WebExternalGecos') ? 'LoadByGecos' : 'Load';
+
+ if ( $^O eq 'MSWin32' and RT->Config->Get('WebExternalGecos') ) {
+ my $NodeName = Win32::NodeName();
+ $user =~ s/^\Q$NodeName\E\\//i;
+ }
+
+ $HTML::Mason::Commands::session{'CurrentUser'} = RT::CurrentUser->new();
+ $HTML::Mason::Commands::session{'CurrentUser'}->$load_method($user);
+
+ if ( RT->Config->Get('WebExternalAuto') && !$HTML::Mason::Commands::session{'CurrentUser'}->Id ) {
+
+ # Create users on-the-fly
+ my $UserObj = RT::User->new($RT::SystemUser);
+ my ( $val, $msg ) = $UserObj->Create(
+ %{ ref RT->Config->Get('AutoCreate') ? RT->Config->Get('AutoCreate') : {} },
+ Name => $user,
+ Gecos => $user,
+ );
+
+ if ($val) {
+
+ # now get user specific information, to better create our user.
+ my $new_user_info = RT::Interface::Web::WebExternalAutoInfo($user);
+
+ # set the attributes that have been defined.
+ foreach my $attribute ( $user->WritableAttributes ) {
+ $m->callback(
+ Attribute => $attribute,
+ User => $user,
+ UserInfo => $new_user_info,
+ CallbackName => 'NewUser',
+ CallbackPage => '/autohandler'
+ );
+ my $method = "Set$attribute";
+ $UserObj->$method( $new_user_info->{$attribute} ) if defined $new_user_info->{$attribute};
+ }
+ $HTML::Mason::Commands::session{'CurrentUser'}->Load($user);
+ } else {
+
+ # we failed to successfully create the user. abort abort abort.
+ delete $HTML::Mason::Commands::session{'CurrentUser'};
+ $m->abort unless RT->Config->Get('WebFallbackToInternalAuth');
+ $m->comp( '/Elements/Login', %$ARGS, Error => loc( 'Cannot create user: [_1]', $msg ) );
+ }
+ }
+
+ if ( $HTML::Mason::Commands::session{'CurrentUser'}->Id ) {
+ $m->callback( %$ARGS, CallbackName => 'ExternalAuthSuccessfulLogin', CallbackPage => '/autohandler' );
+ } else {
+ delete $HTML::Mason::Commands::session{'CurrentUser'};
+ $user = $orig_user;
+
+ if ( RT->Config->Get('WebExternalOnly') ) {
+ $m->comp( '/Elements/Login', %$ARGS, Error => loc('You are not an authorized user') );
+ $m->abort();
+ }
+ }
+ } elsif ( RT->Config->Get('WebFallbackToInternalAuth') ) {
+ unless ( defined $HTML::Mason::Commands::session{'CurrentUser'} ) {
+ $m->comp( '/Elements/Login', %$ARGS, Error => loc('You are not an authorized user') );
+ $m->abort();
+ }
+ } else {
+
+ # WebExternalAuth is set, but we don't have a REMOTE_USER. abort
+ # XXX: we must return AUTH_REQUIRED status or we fallback to
+ # internal auth here too.
+ delete $HTML::Mason::Commands::session{'CurrentUser'}
+ if defined $HTML::Mason::Commands::session{'CurrentUser'};
+ }
+}
=head2 Redirect URL
diff --git a/share/html/autohandler b/share/html/autohandler
index 3b59418..af574ff 100755
--- a/share/html/autohandler
+++ b/share/html/autohandler
@@ -81,83 +81,9 @@ RT::Interface::Web::MaybeShowNoAuthPage(\%ARGS);
-# If RT is configured for external auth, let's go through and get REMOTE_USER
-if ( RT->Config->Get('WebExternalAuth') ) {
+RT::Interface::Web::AttemptExternalAuth(\%ARGS);
- # do we actually have a REMOTE_USER equivlent?
- if ( RT::Interface::Web::WebCanonicalizeInfo() ) {
- my $orig_user = $user;
- $user = RT::Interface::Web::WebCanonicalizeInfo();
- $session{'CurrentUser'} = RT::CurrentUser->new();
- my $load_method = RT->Config->Get('WebExternalGecos') ? 'LoadByGecos' : 'Load';
-
- if ( $^O eq 'MSWin32' and RT->Config->Get('WebExternalGecos') ) {
- my $NodeName = Win32::NodeName();
- $user =~ s/^\Q$NodeName\E\\//i;
- }
-
- $session{'CurrentUser'} = RT::CurrentUser->new();
- $session{'CurrentUser'}->$load_method($user);
-
- if ( RT->Config->Get('WebExternalAuto') && !$session{'CurrentUser'}->Id ) {
-
- # Create users on-the-fly
- my $UserObj = RT::User->new( $RT::SystemUser );
- my ($val, $msg) = $UserObj->Create(
- %{ ref RT->Config->Get('AutoCreate') ? RT->Config->Get('AutoCreate') : {} },
- Name => $user,
- Gecos => $user,
- );
-
- if ( $val ) {
- # now get user specific information, to better create our user.
- my $new_user_info = RT::Interface::Web::WebExternalAutoInfo($user);
-
- # set the attributes that have been defined.
- foreach my $attribute ($user->WritableAttributes) {
- $m->callback( Attribute => $attribute, User => $user, UserInfo => $new_user_info, CallbackName => 'NewUser', CallbackPage => '/autohandler' );
- my $method = "Set$attribute";
- $UserObj->$method( $new_user_info->{$attribute} ) if defined $new_user_info->{$attribute};
- }
- $session{'CurrentUser'}->Load($user);
- }
- else {
-
- # we failed to successfully create the user. abort abort abort.
- delete $session{'CurrentUser'};
- $m->abort unless RT->Config->Get('WebFallbackToInternalAuth');
- $m->comp( '/Elements/Login', %ARGS, Error => loc( 'Cannot create user: [_1]', $msg ) );
- }
- }
-
- if ( $session{'CurrentUser'}->Id ) {
- $m->callback(%ARGS, CallbackName => 'ExternalAuthSuccessfulLogin', CallbackPage => '/autohandler')
- }
- else {
- delete $session{'CurrentUser'};
- $user = $orig_user;
-
- if ( RT->Config->Get('WebExternalOnly') ) {
- $m->comp( '/Elements/Login', %ARGS, Error => loc('You are not an authorized user') );
- $m->abort();
- }
- }
- }
- elsif (RT->Config->Get('WebFallbackToInternalAuth')) {
- unless ( defined $session{'CurrentUser'} ) {
- $m->comp( '/Elements/Login', %ARGS, Error => loc('You are not an authorized user') );
- $m->abort();
- }
- }
- else {
-
- # WebExternalAuth is set, but we don't have a REMOTE_USER. abort
- # XXX: we must return AUTH_REQUIRED status or we fallback to
- # internal auth here too.
- delete $session{'CurrentUser'} if defined $session{'CurrentUser'};
- }
-}
delete $session{'CurrentUser'} unless $session{'CurrentUser'} && $session{'CurrentUser'}->Id;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list