Apache-AuthCookieNTLM

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
Revision history for Perl extension Apache::AuthCookieNTLM
 
0.07 Sat Sep 3 2004
        - Applied patch from Steve Keay for 'POST' data
 
0.06  Mon Nov 11 10:11 2003
        - Changed the way this module should be inherited (see docs)
          as I'd forgotten about the global, much cleaner now.
        - Found bug in the way I'd suggested to inherit - it didn't
          work!

Changes  view on Meta::CPAN

22
23
24
25
26
27
28
29
30
31
32
        - First CPAN release
        - Clean up code & docs
        - Add debuging
        - Added domain and secure cookie settings
         
0.02  Wed Nov 5 17:22 2003
        - First public release 
         
0.01  Tue Nov  4 11:05:31 2003
        - original version; created by h2xs 1.21 with options
                -A -X -n Apache::AuthCookieNTLM

MANIFEST  view on Meta::CPAN

1
2
3
4
5
6
7
lib/Apache/AuthCookieNTLM.pm
Changes
Makefile.PL
MANIFEST
README
test.pl
META.yml                                Module meta-data (added by MakeMaker)

META.yml  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
name:         Apache-AuthCookieNTLM
version:      0.07
version_from: lib/Apache/AuthCookieNTLM.pm
installdirs:  site
requires:
    Apache::Constants:             0.01
    Test::More:                    0.01
    Apache::AuthenNTLM:            2.07
    Apache::Cookie:                0.01
    Apache::Request:               0.01
 
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.12

Makefile.PL  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    'NAME'              => 'Apache::AuthCookieNTLM',
    'VERSION_FROM'      => 'lib/Apache/AuthCookieNTLM.pm', # finds $VERSION
    'PREREQ_PM'         => {
                'Test::More'         => 0.01,
                'Apache::AuthenNTLM' => 2.07,
                'Apache::Request'    => 0.01,
                'Apache::Cookie'     => 0.01,       
                'Apache::Constants'  => 0.01,
        }, # e.g., Module::Name => 1.1
    ($] >= 5.005 ?    ## Add these new keywords supported since 5.005
      ( AUTHOR     => 'Leo Lapworth <llap@cuckoo.org>, Francoise Dehinbo') : ()),
);

README  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Apache/AuthCookieNTLM version 0.06
==================================
 
As explained in the Apache::AuthenNTLM module, depending on the user's
config, IE will supply your Windows logon credentials to the web server
when the server asks for NTLM authentication. This saves the user typing in
their windows login and password.
 
Apache::AuthCookieNTLM is an interface to Shannon Peevey's
Apache::AuthenNTLM module. The main aim is to authenticate a user
using their Windows login and authenticating against the Windows
PDC, but to also store their login name into a cookie. This means
that it can be accessed from other pages and stops the system
having to authenticate for every request.
 
INSTALLATION
 
To install this module type the following:

README  view on Meta::CPAN

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
   make test
   make install
 
DEPENDENCIES
 
This module requires these other modules and libraries:
 
                'Test::More'         => 0.01,
                'Apache::AuthenNTLM' => 2.07,
                'Apache::Request'    => 0.01,
                'Apache::Cookie'     => 0.01,       
 
COPYRIGHT AND LICENCE
 
This module is free software; you can redistribute it or modify it
under the same terms as Perl itself.
 
Copyright (C) 2003 Leo Lapworth <llap@cuckoo.org>, Francoise Dehinbo

lib/Apache/AuthCookieNTLM.pm  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
# Small wrapper to Apache::AuthenNTLM to store user login details to cookie
# and reduce the number of PDC requests.
 
use strict;
use Apache::Constants ':common';
 
use base ('Apache::AuthenNTLM');
 
use vars qw($VERSION);
$VERSION = 0.07;
 
# Global to store stuff in
my $cookie_values = {};
 
sub handler ($$) {

lib/Apache/AuthCookieNTLM.pm  view on Meta::CPAN

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
        # 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;
                        }                      
                }
                # AuthenNTLM loops so have to behave like it does
                # and return $v
                return $v;
        } else {
                print STDERR "AuthCookieNTLM - Found Cookies for '$cname'\n" if $debug > 0;
                my %c = $cookiejar{$cname}->parse();
                if(defined $c{$cname}) {
                        print STDERR "AuthCookieNTLM - Cookie Matched \n" if $debug > 1;
                        my %v = $c{$cname}->value();
                        print STDERR "AuthCookieNTLM - Cookie values " . Dumper(\%v) . "\n" if $debug > 1;
                        if(defined $v{'username'} && defined $v{'userdomain'}) {
                                my $user = lc($v{'userdomain'} . '\\' . $v{'username'});
                        $r ->user($user) if ref($r) eq 'Apache';
                                print STDERR "AuthCookieNTLM - REMOVE_USER SET: " . $user . "\n" if $debug > 1;
                        }
                }
        }
 
        return OK;
}
 
sub check_cookie {
        my $self = shift;
        return 1 if ( $cookie_values eq {} || $cookie_values->{username} ne $self->{username} );

lib/Apache/AuthCookieNTLM.pm  view on Meta::CPAN

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    return lc("$self->{userdomain}\\$self->{username}");
}
 
 
1;
 
__END__
 
=head1 NAME
 
Apache::AuthCookieNTLM - NTLM (Windows domain) authentication with cookies
 
=head1 SYNOPSIS
 
'WhatEver' should be replaced with the AuthName you choose
for this location's authentication.
 
    <Location />
        PerlAuthenHandler Apache::AuthCookieNTLM
 
        # NTLM CONFIG
        AuthType ntlm,basic
        AuthName WhatEver
        require valid-user
 
        #                   domain          pdc               bdc
        PerlAddVar ntdomain "name_domain1   name_of_pdc1"
        PerlAddVar ntdomain "other_domain   pdc_for_domain    bdc_for_domain"

lib/Apache/AuthCookieNTLM.pm  view on Meta::CPAN

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
    </Location>
 
 
=head1 DESCRIPTION
 
As explained in the Apache::AuthenNTLM module, depending on the user's
config, IE will supply your Windows logon credentials to the web server
when the server asks for NTLM authentication. This saves the user typing in
their windows login and password.
 
Apache::AuthCookieNTLM is an interface to Shannon Peevey's
Apache::AuthenNTLM module. This modules authenticates a user
using their Windows login against the Windows PDC, but to also
stores their login name into a cookie. This means that it can be
accessed from other pages and stops the system having to
authenticate for every request.
 
We did consider using Apache::AuthCookie to store the details in a
cookie but since using NTLM is basicaly there to remove the need
to login and is almost exclusively for intranets (as it needs access
to the PDC), we decided it was feasible not to use it.
 
=head1 APACHE CONFIGURATION
 
Please consult the Apache::AuthenNTLM documentation for more details on
the NTLM configuration.
 
'WhatEver' should be replaced with the AuthName you choose
for this location's authentication.
 
=head2 PerlSetVar WhatEverName
 
Sets the cookie name. This will default to
Apache::AuthCookieNTLM_WhatEver.
 
=head2 PerlSetVar WhatEverExpires
 
Sets the cookie expiry time. This defaults to being
a session only cookie.
 
=head2 PerlSetVar WhatEverPath
 
Sets the path that can retrieve the cookie. The default is /.

lib/Apache/AuthCookieNTLM.pm  view on Meta::CPAN

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
The method can be overwritten to set the values stored in the cookie
 
=head2 Example for overriding
 
This is an example of how to set your cookie values with whatever
data you want.
 
  package MYAuthenNTLM;
 
  use Apache::AuthCookieNTLM;  
  use base ( 'Apache::AuthCookieNTLM' );
  use MyUserLookup_Package;
   
  sub choose_cookie_values {
    my ($self,$r) = @_;
         
    # Save if it's not already set
    if ($self->check_cookie()) {
                # Look up against other sources
            my $person = MyUserLookup_Package->new($self->{'username'});

lib/Apache/AuthCookieNTLM.pm  view on Meta::CPAN

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
'Tools' -> 'Internet Options' -> 'Security' -> 'Local Intranet' ->
'Sites' -> 'Advanced' and add it in there, this must start
with http:// or https://
 
Once this is working you should be able to just replace
 
  PerlAuthenHandler Apache::AuthenNTLM
 
with           
                 
  PerlAuthenHandler Apache::AuthCookieNTLM
 
And have it all just work[tm].
 
Remember to quit IE and reload as it's crap at implementing
changes on the fly!
 
=head2 Not setting cookies
 
IE doesn't seem to alert you (if you've turned prompt on
for cookies). We guess it's because its from the trusted site.

lib/Apache/AuthCookieNTLM.pm  view on Meta::CPAN

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
=head2 access to /test failed in error log - but it works
 
Because Apache::AuthenNTLM has to go through several loops
the first of which will fail, this will be reported in
your error log, but you can just ignore it.
 
=head1 SEE ALSO
 
L<Apache::AuthenNTLM>,
L<Apache::Cookie>,
L<CGI::Cookie>
 
=head1 AUTHOR
 
Leo Lapworth <llap@cuckoo.org>, Francoise Dehinbo
 
=cut

test.pl  view on Meta::CPAN

1
2
3
4
5
6
7
use lib qw( ./blib/lib ../blib/lib );
 
use Test::More tests => 1;
 
BEGIN { use_ok('Apache::AuthCookieNTLM' ); }
 
# What more can you do!



( run in 0.284 second using v1.01-cache-2.11-cpan-00829025b61 )