Apache-Auth-AuthMemCookie

 view release on metacpan or  search on metacpan

lib/Apache/Auth/AuthMemCookie.pm  view on Meta::CPAN

package Apache::Auth::AuthMemCookie;

use strict;
use CGI::Cookie ();
use Apache2::RequestUtil;
use Apache2::RequestIO;
use APR::Table;
use Apache2::RequestRec;
use Apache2::Const -compile => qw(OK REDIRECT FORBIDDEN AUTH_REQUIRED);
use Apache2::Log;
use Cache::Memcached;
use vars qw($VERSION);
$VERSION = '0.04';

use Data::Dumper;

=pod

=head1 B<Apache::Auth::AuthMemCookie - Authenticate using a memcache stored session>

=head2 B<Module Usage>

=over

  This module is used to take the place of Apache2 authmemcookie primarily for the use
  of integration with simpleSAMLphp L<http://rnd.feide.no/simplesamlphp> .

    Alias /simplesaml /home/piers/git/public/simplesamlphp/www
    perlModule Apache::Auth::AuthMemCookie
    ErrorDocument 401 "/simplesaml/authmemcookie.php"
    PerlRequire /path/to/authmemcookie/tools/startup.pl
    perlModule Apache::Auth::AuthMemCookie

    # Prompt for authentication:
    <Location /location_to_protect>
        AuthType Cookie
        AuthName "My Service"
        Require valid-user
        PerlAuthenHandler Apache::Auth::AuthMemCookie::authen_handler
        PerlSetVar AuthMemCookie "AuthMemCookie"
        PerlSetVar AuthMemServers "127.0.0.1:11211, /var/sock/memcached"
        PerlSetVar AuthMemAttrsInHeaders 1 # if you want to set headers instead of ENV vars
        PerlSetVar AuthMemDebug 1 # if you want to debug
    </Location>

=back

=cut

our $memd = undef;
our $DEBUG = 0;

     
sub authen_handler {
  
    my $r = shift;
    $DEBUG = $r->dir_config("AuthMemDebug") || 0;

    # first, remove all headers and env vars that might have been injected
    foreach my $k (keys %ENV) {
        delete $ENV{$k} if $k =~ /^(ATTR_|UserName)/;
    }
    foreach my $h (keys %{$r->headers_in}) {
        $r->headers_in->unset($h) if $h =~ /^(ATTR_|UserName|X_REMOTE_USER|HTTP_X_REMOTE_USER)/;
    }
    $r->headers_in->unset('UserName');
    $r->headers_in->unset('X_REMOTE_USER');
    $r->headers_in->unset('X-Remote-User');

    # what is our cookie called
    my $cookie_name = $r->dir_config("AuthMemCookie") ? $r->dir_config("AuthMemCookie") : 'AuthMemCookie';
    mydebug("Headers in: ".Dumper($r->headers_in));

    # sort out our memcached connection
    unless ($memd) {



( run in 1.253 second using v1.01-cache-2.11-cpan-5a3173703d6 )