Translate cookie domain in internal proxy (#459)

This commit is contained in:
Clément Oudot 2012-04-03 13:35:57 +00:00
parent 1562c3e49f
commit d6bbf7fdca

View File

@ -10,7 +10,7 @@ use strict;
use Lemonldap::NG::Handler::Simple qw(:apache :headers :traces); use Lemonldap::NG::Handler::Simple qw(:apache :headers :traces);
use LWP::UserAgent; use LWP::UserAgent;
our $VERSION = '1.1.0'; our $VERSION = '1.2.0';
########################################## ##########################################
# COMPATIBILITY WITH APACHE AND APACHE 2 # # COMPATIBILITY WITH APACHE AND APACHE 2 #
@ -132,13 +132,24 @@ sub headers {
# Scan LWP response headers to generate Apache response headers # Scan LWP response headers to generate Apache response headers
my ( $location_old, $location_new ) = split /[;,]+/, my ( $location_old, $location_new ) = split /[;,]+/,
$r->dir_config('LmLocationToReplace'); $r->dir_config('LmLocationToReplace');
my ( $cookieDomain_old, $cookieDomain_new ) = split /[;,]+/,
$r->dir_config('LmCookieDomainToReplace');
$response->scan( $response->scan(
sub { sub {
# Replace Location headers # Replace Location headers
$_[1] =~ s#$location_old#$location_new#o $_[1] =~ s#$location_old#$location_new#o
if ( $location_old and $location_new and $_[0] =~ /Location/i ); if ( $location_old and $location_new and $_[0] =~ /Location/i );
# Replace Set-Cookie headers
$_[1] =~ s#$cookieDomain_old#$cookieDomain_new#o
if ( $cookieDomain_old
and $cookieDomain_new
and $_[0] =~ /Set-Cookie/i );
lmSetErrHeaderOut( $r, @_ ); lmSetErrHeaderOut( $r, @_ );
$class->lmLog( $class->lmLog(
"$class: header pushed to the client: " . $_[0] . ": " . $_[1], "$class: header pushed to the client: " . $_[0] . ": " . $_[1],
'debug' 'debug'
@ -168,7 +179,8 @@ apache/conf/httpd.conf:
SetHandler perl-script SetHandler perl-script
PerlHandler Lemonldap::NG::Handler::Proxy PerlHandler Lemonldap::NG::Handler::Proxy
PerlSetVar LmProxyPass http://real-server.com/ PerlSetVar LmProxyPass http://real-server.com/
PerlSetVar LmLocationToReplace http://real-server/,https://lemon.server/ PerlSetVar LmLocationToReplace http://real-server.com/,https://lemon.server/
PerlSetVar LmCookieDomainToReplace real-server.com,lemon.server
# Or just on a Location # Or just on a Location
PerlModule Lemonldap::NG::Handler::Proxy PerlModule Lemonldap::NG::Handler::Proxy
@ -176,7 +188,8 @@ apache/conf/httpd.conf:
SetHandler perl-script SetHandler perl-script
PerlHandler Lemonldap::NG::Handler::Proxy PerlHandler Lemonldap::NG::Handler::Proxy
PerlSetVar LmProxyPass https://real-server.com/ PerlSetVar LmProxyPass https://real-server.com/
PerlSetVar LmLocationToReplace http://real-server/,https://lemon.server/ PerlSetVar LmLocationToReplace http://real-server.com/,https://lemon.server/
PerlSetVar LmCookieDomainToReplace real-server.com,lemon.server
</Location> </Location>
=head1 DESCRIPTION =head1 DESCRIPTION
@ -193,6 +206,9 @@ manage redirections if the remote host use it without the good domain.
=item * B<LmLocationToReplace> (optional): substitution to do to avoid bad =item * B<LmLocationToReplace> (optional): substitution to do to avoid bad
redirections. See synopsys for usage. redirections. See synopsys for usage.
=item * B<LmCookieDomainToReplace> (optional): substitution to do to set cookies
from proxied application. See synopsys for usage.
=back =back
=head2 EXPORT =head2 EXPORT