Permalink
Browse files

LWP/Protocol/ldap.pm: use Authorization header to get user & password

If user is not given using $uri->userinfo, try to get it from the
Authorization HTTP header.

Currently only Basic authorization is supported.
  • Loading branch information...
1 parent f4ffcc8 commit 214f442128ecedf95f3f8e5d844fcd17fc07b234 @marschap marschap committed Sep 6, 2012
Showing with 11 additions and 1 deletion.
  1. +11 −1 lib/LWP/Protocol/ldap.pm
View
@@ -13,7 +13,7 @@ use LWP::MediaTypes ();
require LWP::Protocol;
@ISA = qw(LWP::Protocol);
-$VERSION = "1.15";
+$VERSION = "1.16";
use strict;
eval {
@@ -71,6 +71,16 @@ sub request {
$format = 'ldif' if $accept =~ m!\btext/(x-)?ldif\b!;
}
+ if (!$user) {
+ if (my $authorization = $request->header('Authorization')) {
+ # we only accept Basic authorization for now
+ if ($authorization =~ /^Basic\s+([A-Z0-9+\/=]+)$/i) {
+ require MIME::Base64;
+ ($user, $password) = split(":", MIME::Base64::decode_base64($1), 2);
+ }
+ }
+ }
+
# Create an initial response object
my $response = new HTTP::Response HTTP_OK, "Document follows";
$response->request($request);

0 comments on commit 214f442

Please sign in to comment.