[Rt-commit] r12624 - in rt/branches/3.8-TESTING: bin

alexmv at bestpractical.com alexmv at bestpractical.com
Thu May 22 15:28:27 EDT 2008


Author: alexmv
Date: Thu May 22 15:28:15 2008
New Revision: 12624

Modified:
   rt/branches/3.8-TESTING/   (props changed)
   rt/branches/3.8-TESTING/bin/rt.in

Log:
 r32077 at kohr-ah:  chmrr | 2008-05-22 15:27:50 -0400
  * Apply a variant of #7643 -- HTTP basic auth support


Modified: rt/branches/3.8-TESTING/bin/rt.in
==============================================================================
--- rt/branches/3.8-TESTING/bin/rt.in	(original)
+++ rt/branches/3.8-TESTING/bin/rt.in	Thu May 22 15:28:15 2008
@@ -58,6 +58,7 @@
 use LWP;
 use Text::ParseWords;
 use HTTP::Request::Common;
+use HTTP::Headers;
 use Term::ReadLine;
 
 # We derive configuration information from hardwired defaults, dotfiles,
@@ -70,12 +71,13 @@
            || ".";
 my %config = (
     (
-        debug   => 0,
-        user    => eval{(getpwuid($<))[0]} || $ENV{USER} || $ENV{USERNAME},
-        passwd  => undef,
-        server  => 'http://localhost/',
-        query   => undef,
-        orderby => undef,
+        debug        => 0,
+        user         => eval{(getpwuid($<))[0]} || $ENV{USER} || $ENV{USERNAME},
+        passwd       => undef,
+        server       => 'http://localhost/',
+        query        => undef,
+        orderby      => undef,
+        externalauth => undef,
     ),
     config_from_file($ENV{RTCONFIG} || ".rtrc"),
     config_from_env()
@@ -820,6 +822,7 @@
     my ($uri, $content) = @_;
     my ($req, $data);
     my $ua = new LWP::UserAgent(agent => "RT/3.0b", env_proxy => 1);
+    my $h = HTTP::Headers->new;
 
     # Did the caller specify any data to send with the request?
     $data = [];
@@ -844,8 +847,10 @@
         $data = $content;
     }
 
-    # Should we send authentication information to start a new session?
-    if (!defined $session->cookie) {
+
+    if ($config{externalauth}) {
+        $h->authorization_basic($config{user}, $config{passwd} || read_passwd() );
+    } elsif (!defined $session->cookie) {
         push @$data, ( user => $config{user} );
         push @$data, ( pass => $config{passwd} || read_passwd() );
     }
@@ -858,6 +863,9 @@
         $req = GET($uri);
     }
     $session->add_cookie_header($req);
+    if ($config{externalauth}) {
+        $req->header(%$h);
+    }
 
     # Then we send the request and parse the response.
     DEBUG(3, $req->as_string);
@@ -874,7 +882,7 @@
         $text =~ s/\n*$/\n/ if ($text);
 
         # "RT/3.0.1 401 Credentials required"
-	if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) {
+        if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) {
             warn "rt: Malformed RT response from $config{server}.\n";
             warn "(Rerun with RTDEBUG=3 for details.)\n" if $config{debug} < 3;
             exit -1;
@@ -1251,7 +1259,7 @@
             chomp;
             next if (/^#/ || /^\s*$/);
 
-            if (/^(user|passwd|server|query|orderby)\s+(.*)\s?$/) {
+            if (/^(externalauth|user|passwd|server|query|orderby)\s+(.*)\s?$/) {
                 $cfg{$1} = $2;
             }
             else {


More information about the Rt-commit mailing list