Apache-Auth-AuthMemCookie
view release on metacpan or search on metacpan
README
Changes
MANIFEST
Makefile.PL
META.yml
lib/Apache/Auth/AuthMemCookie.pm
t/00use.t
META.json Module JSON meta-data (added by MakeMaker)
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Apache-Auth-AuthMemCookie",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Apache2::Const" : "0",
"Apache2::Log" : "0",
"CGI::Cookie" : "0",
"Cache::Memcached" : "0",
"Test::More" : "0"
}
}
},
"release_status" : "stable",
"version" : "0.04"
}
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.120921'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Apache-Auth-AuthMemCookie
no_index:
directory:
- t
- inc
requires:
Apache2::Const: 0
Apache2::Log: 0
CGI::Cookie: 0
Cache::Memcached: 0
Test::More: 0
version: 0.04
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
require 5.008;
WriteMakefile(
'PREREQ_PM' => { 'Test::More' => 0, CGI::Cookie => 0, Apache2::Const => 0, Apache2::Log => 0, Cache::Memcached => 0 },
'AUTHOR' => 'Piers Harding <piers@cpan.org>',
'ABSTRACT' => 'mod_perl replacement for Apache2 authmemcookie authentication module',
'VERSION_FROM' => 'lib/Apache/Auth/AuthMemCookie.pm',
'NAME' => 'Apache::Auth::AuthMemCookie',
'clean' => { 'FILES' },
'dist' => { 'TARFLAGS' => 'cvf',
'COMPRESS' => 'gzip -9f',
'SUFFIX' => '.tar.gz' },
);
Apache::Auth:AuthMemCookie - mod_perl replacement for
Apache2 authmemcookie
Copyright (c) 2009 - 2014 Piers Harding.
All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of either:
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
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;
lib/Apache/Auth/AuthMemCookie.pm view on Meta::CPAN
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) {
my @memd_servers = split /\s*(?:,)\s*/, ($r->dir_config("AuthMemServers") ? $r->dir_config("AuthMemServers") : '127.0.0.1:11211, /var/sock/memcached');
$memd = new Cache::Memcached {
'servers' => [ @memd_servers ],
'debug' => 0,
'compress_threshold' => 10_000,
};
mydebug("memcache servers: ".Dumper(\@memd_servers));
}
# get and process the cookies
my $cookies = $r->headers_in->get('Cookie');
$cookies = parse CGI::Cookie($cookies);
my $auth_cookie = exists $cookies->{$cookie_name} ? $cookies->{$cookie_name}->value() : "";
# do we have the AuthMemCookie?
unless ($auth_cookie) {
mydebug("AuthMemCookie does not exist ($cookie_name) -> forcing login");
return Apache2::Const::AUTH_REQUIRED;
}
my $val = $memd->get($auth_cookie);
# Do we have a valid Memcached session?
unless ($val) {
mydebug("Memcached session not found for AuthMemCookie ($cookie_name): $auth_cookie");
return Apache2::Const::AUTH_REQUIRED;
}
mydebug("AuthMemCookie value: $val");
# we found a valid MemCache session so push it into the environment and let them go
my %vars = map { my ($k, $v) = split(/=/, $_, 2); $k => $v } (split(/\r\n/, $val));
# should the values be set in the headers
my $header_switch = $r->dir_config("AuthMemAttrsInHeaders") ? $r->dir_config("AuthMemAttrsInHeaders") : 0;
my $user = "";
foreach my $k (keys %vars) {
if ($k eq "UserName") {
$user = $vars{$k};
# Need to suppress warinings ?
BEGIN { $^W = 0; $| = 1; print "1..1\n"; }
END {print "not ok 1\n" unless $loaded;}
use Apache::Auth::AuthMemCookie;
$loaded = 1;
print "ok 1\n";
( run in 0.316 second using v1.01-cache-2.11-cpan-e9199f4ba4c )