Advertisement
lucianoes

ExternalAuth.pm patch LDAP uid

Oct 3rd, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.76 KB | None | 0 0
  1. --- ExternalAuth.pm 2011-08-29 11:06:30.000000000 -0300
  2. +++ ExternalAuth.pm 2011-10-03 15:04:01.000000000 -0300
  3. @@ -112,18 +112,22 @@
  4.          # We are now sure that we're talking about a valid RT user.
  5.          # If the user already exists, load up their info. If they don't
  6.          # then we need to create the user in RT.
  7. -
  8. +   #MODIF
  9. +   my $MagicUid = "a";
  10. +   #END_MODIF
  11.          # Does user already exist internally to RT?
  12. +   $RT::Logger->debug("Auto-Create process, this is where the magic really happens!! Put the A letter befone the UID");
  13.          $session->{'CurrentUser'} = RT::CurrentUser->new();
  14. -        $session->{'CurrentUser'}->Load($username);
  15. -
  16. +        $session->{'CurrentUser'}->Load($MagicUid . $username);
  17. +        #$session->{'CurrentUser'}->Load($username);
  18. +  
  19.          # Unless we have loaded a valid user with a UserID create one.
  20.          unless ($session->{'CurrentUser'}->Id) {
  21.             my $UserObj = RT::User->new($RT::SystemUser);
  22.             my ($val, $msg) =
  23.                $UserObj->Create(%{ref($RT::AutoCreate) ? $RT::AutoCreate : {}},
  24. -                               Name   => $username,
  25. -                               Gecos  => $username,
  26. +                               Name   => ("a" . $username),
  27. +                  Gecos  => $username,
  28.                                );
  29.              unless ($val) {
  30.                  $RT::Logger->error( "Couldn't create user $username: $msg" );
  31. @@ -138,9 +142,9 @@
  32.              $RT::Logger->debug("Loading new user (",
  33.                                 $username,
  34.                                 ") into current session");
  35. -            $session->{'CurrentUser'}->Load($username);
  36. +            $session->{'CurrentUser'}->Load("a" . $username);
  37. +        $RT::Logger->debug("Did the system load the the userseme with a ? Otherwise the next step will fail.");
  38.          }
  39. -        
  40.          ####################################################################
  41.          ########## Authentication ##########################################
  42.          ####################################################################
  43. @@ -279,7 +283,8 @@
  44.      # Update their info from external service using the username as the lookup key
  45.      # CanonicalizeUserInfo will work out for itself which service to use
  46.      # Passing it a service instead could break other RT code
  47. -    my %args = (Name => $username);
  48. +    #MODIFICACAO - Incluido o substring no $username para remover o caracter a
  49. +    my %args = (Name => substr($username,1));
  50.      $UserObj->CanonicalizeUserInfo(\%args);
  51.  
  52.      # For each piece of information returned by CanonicalizeUserInfo,
  53. @@ -295,10 +300,10 @@
  54.          # uncomment the following logging statements
  55.          if ($method_success) {
  56.              # At DEBUG level, log that method succeeded
  57. -            # $RT::Logger->debug((caller(0))[3],"$method Succeeded. $method_msg");
  58. +             $RT::Logger->debug((caller(0))[3],"$method Succeeded. $method_msg");
  59.          } else {
  60.              # At DEBUG level, log that method failed
  61. -            # $RT::Logger->debug((caller(0))[3],"$method Failed. $method_msg");
  62. +             $RT::Logger->debug((caller(0))[3],"$method Failed. $method_msg");
  63.          }
  64.      }
  65.  
  66. @@ -343,7 +348,8 @@
  67.  
  68.      # Request a username/password check from the specified service
  69.      # This is only valid for non-SSO services.
  70. -
  71. +#    my $removemagic = substr($username, 1);  
  72. +#    my ($removemagic,$service) = @_;
  73.      my ($username,$service) = @_;
  74.  
  75.      my $success = 0;
  76. @@ -356,7 +362,9 @@
  77.      if ($config->{'type'} eq 'db') {
  78.          $success = RT::Authen::ExternalAuth::DBI::UserExists($username,$service);
  79.      } elsif ($config->{'type'} eq 'ldap') {
  80. -        $success = RT::Authen::ExternalAuth::LDAP::UserExists($username,$service);
  81. +   my $magicnewname = substr($username, '0', 8);
  82. +   my $username = $magicnewname;
  83. +   $success = RT::Authen::ExternalAuth::LDAP::UserExists($username,$service);
  84.      } else {
  85.          $RT::Logger->debug("Invalid service type for UserExists:",$service);
  86.      }
  87. @@ -365,7 +373,7 @@
  88.  }
  89.  
  90.  sub UserDisabled {
  91. -    
  92. +    $RT::Logger->debug("Now is starting UserDisabled function");  
  93.      my $username = shift;
  94.      my $user_disabled = 0;
  95.      
  96. @@ -403,8 +411,8 @@
  97.              $user_disabled = RT::Authen::ExternalAuth::DBI::UserDisabled($username,$service);
  98.              
  99.          } elsif ($config->{'type'} eq 'ldap') {
  100. -            
  101. -            unless(RT::Authen::ExternalAuth::LDAP::UserExists($username,$service)) {
  102. +   $RT::Logger->debug("Removing special character A from the username.");            
  103. +            unless(RT::Authen::ExternalAuth::LDAP::UserExists(substr($username,1),$service)) {
  104.                  $RT::Logger->debug("User (",
  105.                                      $username,
  106.                                      ") doesn't exist in service (",
  107. @@ -412,7 +420,8 @@
  108.                                      ") - Cannot update information - Skipping...");
  109.                  next;
  110.              }
  111. -            $user_disabled = RT::Authen::ExternalAuth::LDAP::UserDisabled($username,$service);
  112. +   $RT::Logger->debug("New check on LDAP the username, but removing the special character A from the username.")
  113. +            $user_disabled = RT::Authen::ExternalAuth::LDAP::UserDisabled(substr($username,1),$service);
  114.                      
  115.          } elsif ($config->{'type'} eq 'cookie') {
  116.              RT::Logger->error("You cannot use SSO Cookies as an information service.");
  117. @@ -429,7 +438,7 @@
  118.  }
  119.  
  120.  sub CanonicalizeUserInfo {
  121. -    
  122. +     $RT::Logger->debug("Now is starting CanonicalizeUserInfo function");
  123.      # Careful, this $args hashref was given to RT::User::CanonicalizeUserInfo and
  124.      # then transparently passed on to this function. The whole purpose is to update
  125.      # the original hash as whatever passed it to RT::User is expecting to continue its
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement