Apache-AuthCookieNTLM
view release on metacpan or search on metacpan
lib/Apache/AuthCookieNTLM.pm view on Meta::CPAN
package Apache::AuthCookieNTLM;
# Small wrapper to Apache::AuthenNTLM to store user login details to cookie
# and reduce the number of PDC requests.
use strict;
use Data::Dumper;
use Apache::Constants ':common';
use Apache::Request;
use Apache::Cookie;
use Apache::AuthenNTLM;
use base ('Apache::AuthenNTLM');
use vars qw($VERSION);
$VERSION = 0.07;
# Global to store stuff in
my $cookie_values = {};
sub handler ($$) {
my ($self,$r) = @_;
# Get auth type and name
my ($auth_type, $auth_name) = ($r->auth_type, $r->auth_name);
# Get server config
my %config;
foreach my $var ( qw(Expires Path Domain Secure Name) ) {
$config{lc($var)} = $r->dir_config("$auth_name$var") || undef;
}
my $debug = $r->dir_config('ntlmdebug') || 0;
# Set cookie name
my $cname = $config{name} || $auth_type . '_' . $auth_name;
print STDERR "AuthCookieNTLM - Looking for Cookie Name: $cname\n" if $debug > 0;
# Look for cookie
my $t = Apache::Request->new($self);
my %cookiejar = Apache::Cookie->new($t)->parse;
if (!defined $cookiejar{$cname}
or ($r->method eq 'POST' and $r->header_in('content-length') == 0)){
# Don't have the cookie, try authenticate
my $v = Apache::AuthenNTLM::handler ($self, $r);
if ($v == 0 && $cookie_values ne {}) {
# Set the cookie as we have user details
my $cookie = Apache::Cookie->new($r,
-name => $cname,
-value => $cookie_values,
-path => $config{'path'} || "/",
);
$cookie->expires($config{'expires'}) if defined $config{'expires'};
$cookie->domain($config{'domain'}) if defined $config{'domain'};
$cookie->secure('1') if defined $config{'secure'};
# Set the cookie to header
$r->header_out('Set-Cookie' => $cookie->bake());
if($debug > 0) {
print STDERR "AuthCookieNTLM - Setting Cookie Expire: " . $config{'expires'} . "\n" if $debug > 0 && defined $config{'expires'};
print STDERR "AuthCookieNTLM - Setting Cookie Domain: " . $config{'domain'} . "\n" if $debug > 0 && defined $config{'domain'};
print STDERR "AuthCookieNTLM - Setting Cookie Secure: " . $config{'secure'} . "\n" if $debug > 1 && defined $config{'secure'};
print STDERR "AuthCookieNTLM - Setting Cookie values: " . Dumper($cookie_values) . "\n" if $debug > 1;
( run in 1.359 second using v1.01-cache-2.11-cpan-5b529ec07f3 )