[Bps-public-commit] r16715 - in RT-Authen-ExternalAuth/trunk: html/Callbacks/ExternalAuth/autohandler lib/RT/Authen lib/RT/Authen/ExternalAuth

zordrak at bestpractical.com zordrak at bestpractical.com
Thu Nov 6 12:03:02 EST 2008


Author: zordrak
Date: Thu Nov  6 12:03:02 2008
New Revision: 16715

Modified:
   RT-Authen-ExternalAuth/trunk/html/Callbacks/ExternalAuth/autohandler/Auth
   RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth.pm
   RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth/LDAP.pm
   RT-Authen-ExternalAuth/trunk/lib/RT/User_Vendor.pm

Log:
RT::Authen::ExternalAuth v0.07_01-prealpha : First functional commit

Modified: RT-Authen-ExternalAuth/trunk/html/Callbacks/ExternalAuth/autohandler/Auth
==============================================================================
--- RT-Authen-ExternalAuth/trunk/html/Callbacks/ExternalAuth/autohandler/Auth	(original)
+++ RT-Authen-ExternalAuth/trunk/html/Callbacks/ExternalAuth/autohandler/Auth	Thu Nov  6 12:03:02 2008
@@ -2,16 +2,14 @@
 
 use RT::Authen::ExternalAuth;
 
-# Since refactoring at 0.07_01 I believe the following workaround is now not required.
-######################################################################################
 # If the RT::User::UpdateFromExternal method is not available, then we are in
 # RT-3.8.0 or RT-3.8.1 and we need to work around a bug in the plugin system:
 # Temporarily force RT to reload RT::User, since it isn't being loaded
 # correctly as a plugin.
 #unless (RT::User->can('UpdateFromExternal')) {
-#    $RT::Logger->error("Working around bug in RT and reloading RT::User");
-#    delete $INC{'RT/User.pm'};
-#    require RT::User;
+    $RT::Logger->error("Working around bug in RT and reloading RT::User");
+    delete $INC{'RT/User.pm'};
+    require RT::User;
 #}
 ######################################################################################
 
@@ -32,14 +30,14 @@
         $session{'CurrentUser'}->Load($user);
 
         # Unless we have loaded a valid user with a UserID
+        # check if user exists externally and autocreate if it does
         unless ($session{'CurrentUser'}->Id) {
             
-            my $UserObj = RT::User->new($RT::SystemUser);
+            $session{'CurrentUser'} = RT::User->new($RT::SystemUser);
             my ($val, $ret, $msg); 
-            # Check if user exists externally - autocreate user if it does
             if(RT::Authen::ExternalAuth::UserExists($user)){
                 ($val, $msg) = 
-                  $UserObj->Create(%{ref($RT::AutoCreate) ? $RT::AutoCreate : {}},
+                  $session{'CurrentUser'}->Create(%{ref($RT::AutoCreate) ? $RT::AutoCreate : {}},
                                    Name   => $user,
                                    Gecos  => $user,
                                   );
@@ -48,29 +46,25 @@
                     return;
                 }
                 $RT::Logger->info(  "Autocreated authenticated user",
-                                    $UserObj->Name,
+                                    $session{'CurrentUser'}->Name,
                                     "(",
-                                    $UserObj->Id,
+                                    $session{'CurrentUser'}->Id,
                                     ")");
 
-                ($val, $msg) = $UserObj->SetName($user);
+                ($val, $msg) = $session{'CurrentUser'}->SetName($user);
                 $RT::Logger->debug("Set Name result: Val:",$val,"Msg:",$msg);
-                # If a password was given on the login page, validate it
-                if (defined($pass)) {
-                    $RT::Logger->debug("\$pass defined ($pass), Running IsPassword");
-                    $password_validated = $UserObj->IsPassword($pass);
-                }
-            
-                if($password_validated) {
-$RT::Logger->debug("Pass validated");
-                    if ($UserObj->Id) {
-                        ($ret, $msg) = $session{'CurrentUser'}->Load($user);
-                        unless ($ret) {
-                            $RT::Logger->error("Couldn't load user $user: $msg");
-                        }
-                    }
-                }
             }
+        } 
+       
+        # If a password was given on the login page, validate it
+        if (defined($pass)) {
+            $RT::Logger->debug("\$pass defined ($pass), Running IsPassword");
+            $password_validated = $session{'CurrentUser'}->IsPassword($pass);
+        }
+            
+        unless($password_validated) {
+            $RT::Logger->debug("Password Incorrect");
+            delete $session{'CurrentUser'};
         }
     }
     

Modified: RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth.pm
==============================================================================
--- RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth.pm	(original)
+++ RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth.pm	Thu Nov  6 12:03:02 2008
@@ -328,7 +328,7 @@
     if ($found) {
         # It's important that we always have a canonical email address
         if ($params{'EmailAddress'}) {
-            $params{'EmailAddress'} = $self->CanonicalizeEmailAddress($params{'EmailAddress'});
+            $params{'EmailAddress'} = $UserObj->CanonicalizeEmailAddress($params{'EmailAddress'});
         } 
         %$args = (%$args, %params);
     }

Modified: RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth/LDAP.pm
==============================================================================
--- RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth/LDAP.pm	(original)
+++ RT-Authen-ExternalAuth/trunk/lib/RT/Authen/ExternalAuth/LDAP.pm	Thu Nov  6 12:03:02 2008
@@ -31,7 +31,7 @@
     $filter = Net::LDAP::Filter->new(   '(&(' . 
                                         $attr_map->{'Name'} . 
                                         '=' . 
-                                        $self->Name . 
+                                        $username . 
                                         ')' . 
                                         $filter . 
                                         ')'
@@ -73,12 +73,12 @@
                         $ldap_dn);
 
     # THIS bind determines success or failure on the password.
-    $ldap_msg = $ldap->bind($ldap_dn, password => $pass_to_auth);
+    $ldap_msg = $ldap->bind($ldap_dn, password => $password);
 
     unless ($ldap_msg->code == LDAP_SUCCESS) {
         $RT::Logger->info(  $service,
                             "AUTH FAILED", 
-                            $self->Name, 
+                            $username, 
                             "(can't bind:", 
                             ldap_error_name($ldap_msg->code), 
                             $ldap_msg->code, 
@@ -123,7 +123,7 @@
         unless ($ldap_msg->count == 1) {
             $RT::Logger->info(  $service,
                                 "AUTH FAILED:", 
-                                $self->Name);
+                                $username);
                                 
             # Fail auth - jump to next external auth service
             return 0;
@@ -267,8 +267,8 @@
 }
 
 sub UserExists {
-    my ($self,$called_by,$service,$username) = @_;
-   $RT::Logger->debug("UserExists params:\nself: $self , called_by: $called_by , service: $service , username: $username"); 
+    my ($username,$service) = @_;
+   $RT::Logger->debug("UserExists params:\nusername: $username , service: $service"); 
     my $config              = $RT::ExternalSettings->{$service};
     
     my $base                = $config->{'base'};

Modified: RT-Authen-ExternalAuth/trunk/lib/RT/User_Vendor.pm
==============================================================================
--- RT-Authen-ExternalAuth/trunk/lib/RT/User_Vendor.pm	(original)
+++ RT-Authen-ExternalAuth/trunk/lib/RT/User_Vendor.pm	Thu Nov  6 12:03:02 2008
@@ -21,7 +21,7 @@
         return (undef);
     }
 
-
+    $RT::Logger->debug("Trying External Authentication (",$self->Name,")");
     if(RT::Authen::ExternalAuth::GetAuth($self->Name,$value)) {
         $RT::Logger->debug( (caller(0))[3], 
                             "EXTERNAL AUTH OKAY");
@@ -84,7 +84,7 @@
 sub CanonicalizeUserInfo {
     my $self = shift;
     my $args = shift;
-    return($RT::Authen::ExternalAuth::CanonicalizeUserInfo($self,$args));
+    return(RT::Authen::ExternalAuth::CanonicalizeUserInfo($self,$args));
 }
 # }}}
 



More information about the Bps-public-commit mailing list