Apache2-AuthCookieLDAP

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

use strict;
use warnings;

use Module::Build;

my $build = Module::Build->new(
    module_name => 'Apache2::AuthCookieLDAP',
    license     => 'perl',
    requires    => {
        'mod_perl2'           => 1.999022,
        'Apache2::AuthCookie' => 3.19,
        'Apache2::Connection' => 0,
        'Apache2::Const'      => 0,
        'Apache2::RequestRec' => 0,
        'Apache2::ServerUtil' => 0,
        'Crypt::CBC'          => 2.13,
        'Digest::MD5'         => 0,
        'Net::LDAP'           => 0.54,
    },
    create_makefile_pl => 'traditional'
)->create_build_script();

Changes  view on Meta::CPAN

Revision history for Apache2::AuthCookieLDAP

1.15  2013-08-21
     - Updated pod

1.14  2013-06-23
     - Updated pod

1.13  2013-06-22
     - Fixed 'logout()' example in the pod

MANIFEST  view on Meta::CPAN

Build.PL
Changes
lib/Apache2/AuthCookieLDAP.pm
LICENSE
Makefile.PL
MANIFEST			This list of files
META.json
META.yml
README

META.json  view on Meta::CPAN

{
   "abstract" : "An Apache2::AuthCookie backend for LDAP based authentication",
   "author" : [
      "unknown"
   ],
   "dynamic_config" : 1,
   "generated_by" : "Module::Build version 0.4005, CPAN::Meta::Converter version 2.112621",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
      "version" : "2"
   },
   "name" : "Apache2-AuthCookieLDAP",
   "prereqs" : {
      "configure" : {
         "requires" : {
            "Module::Build" : "0.40"
         }
      },
      "runtime" : {
         "requires" : {
            "Apache2::AuthCookie" : "3.19",
            "Apache2::Connection" : 0,
            "Apache2::Const" : 0,
            "Apache2::RequestRec" : 0,
            "Apache2::ServerUtil" : 0,
            "Crypt::CBC" : "2.13",
            "Digest::MD5" : 0,
            "Net::LDAP" : "0.54",
            "mod_perl2" : "1.999022"
         }
      }
   },
   "provides" : {
      "Apache2::AuthCookieLDAP" : {
         "file" : "lib/Apache2/AuthCookieLDAP.pm",
         "version" : "1.15"
      }
   },
   "release_status" : "stable",
   "resources" : {
      "license" : [
         "http://dev.perl.org/licenses/"
      ]
   },
   "version" : "1.15"

META.yml  view on Meta::CPAN

---
abstract: 'An Apache2::AuthCookie backend for LDAP based authentication'
author:
  - unknown
build_requires: {}
configure_requires:
  Module::Build: 0.40
dynamic_config: 1
generated_by: 'Module::Build version 0.4005, CPAN::Meta::Converter version 2.112621'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: 1.4
name: Apache2-AuthCookieLDAP
provides:
  Apache2::AuthCookieLDAP:
    file: lib/Apache2/AuthCookieLDAP.pm
    version: 1.15
requires:
  Apache2::AuthCookie: 3.19
  Apache2::Connection: 0
  Apache2::Const: 0
  Apache2::RequestRec: 0
  Apache2::ServerUtil: 0
  Crypt::CBC: 2.13
  Digest::MD5: 0
  Net::LDAP: 0.54
  mod_perl2: 1.999022
resources:
  license: http://dev.perl.org/licenses/

Makefile.PL  view on Meta::CPAN

# Note: this file was auto-generated by Module::Build::Compat version 0.4005
use ExtUtils::MakeMaker;
WriteMakefile
(
  'PL_FILES' => {},
  'INSTALLDIRS' => 'site',
  'NAME' => 'Apache2::AuthCookieLDAP',
  'EXE_FILES' => [],
  'VERSION_FROM' => 'lib/Apache2/AuthCookieLDAP.pm',
  'PREREQ_PM' => {
                   'Apache2::Const' => 0,
                   'Apache2::AuthCookie' => '3.19',
                   'Apache2::RequestRec' => 0,
                   'mod_perl2' => '1.999022',
                   'Crypt::CBC' => '2.13',
                   'Digest::MD5' => 0,
                   'Apache2::ServerUtil' => 0,
                   'Net::LDAP' => '0.54',
                   'Apache2::Connection' => 0
                 }
)
;

README  view on Meta::CPAN

Apache2::AuthCookieLDAP is a module that subclasses Apache2::AuthCookie
and acts as an authentication backend to check a user credentials against an
LDAP server. In case of successfull authentication an encrypted session key is
stored as a browser authentication cookie on the client's side.

Latest distribution at: http://search.cpan.org/dist/Apache2-AuthCookieLDAP
 
Maintainer: ksolomko@cpan.org

lib/Apache2/AuthCookieLDAP.pm  view on Meta::CPAN

package Apache2::AuthCookieLDAP;

# Apache2::AuthCookieLDAP
#
# An Apache2::AuthCookie backend for LDAP based authentication
#
# Author: Kirill Solomko <ksolomko@cpan.org>

use strict;
use warnings;
use 5.010_000;
our $VERSION = '1.15';

use Apache2::AuthCookie;
use base qw(Apache2::AuthCookie);

use Apache2::Connection;
use Apache2::RequestRec;
use Apache2::Log;
use Apache2::Const -compile => qw(:log);
use APR::Const -compile     => qw(:error ENOTIME SUCCESS);

use English qw(-no_match_vars);

use Digest::MD5 qw(md5_hex);

lib/Apache2/AuthCookieLDAP.pm  view on Meta::CPAN


    return $user;
}

1;

=pod

=head1 NAME

Apache2::AuthCookieLDAP - An Apache2::AuthCookie backend for LDAP based authentication

=head1 VERSION

Version 1.15

=head1 COMPATIBILITY

The version is compatible with Apache2 and mod_perl2

=head1 SYNOPSIS

1. Make sure that your LDAP server is configured and you have access to it 

2.  In httpd.conf or .htaccess

Apache2::AuthCookie config (check L<Apache2::AuthCookie> documentation for the additional info)

    PerlSetVar MyAuthPath /
    PerlSetVar MyAuthLoginScript /
    PerlSetVar MyAuthLogoutURL http://127.0.0.1
    PerlSetVar MyAuthSecure 1

To make "LogoutURL" working you can subsclass Apache2::ApacheCookieLDAP and provide it with:

    sub logout {
        my ( $self, $r ) = @_;
        $self->SUPER::logout($r);
        my $logout_url = $r->dir_config( $r->auth_name . 'LogoutURL' );
        if ($logout_url) {
            $r->headers_out->set( Location => $logout_url );
            $r->status(Apache2::Const::REDIRECT);
        }

        return Apache2::Const::REDIRECT;
    }
  
Apache2::AuthCookieLDAP config

    PerlSetVar MyAuth_SecretKey OGheSWkT1ixd4V0DydSarLVevF77sSibMIoUaIYuQUqp2zvZIwbS4lyWhRTFUcHE
    PerlSetVar MyAuth_SessionLifetime 00-24-00-00
    PerlSetVar MyAuth_LDAPURI ldap://127.0.0.1
    PerlSetVar MyAuth_Base uid=%USER%,ou=staff,dc=company,dc=com
    PerlSetVar MyAuth_BindDN cn=ldap,dc=company,dc=com
    PerlSetVar MyAuth_BindPW somepassword
    PerlSetVar MyAuth_Filter (uid=%USER%)

    <Directory /var/www/mysite/protected>
        AuthType Apache2::AuthCookieLDAP
        AuthName MyAuth
        PerlAuthenHandler Apache2::AuthCookieLDAP->authenticate
        PerlAuthzHandler Apache2::AuthCookieLDAP->authorize
        require valid-user
    </Directory>

    <Location /login>
        SetHandler perl-script
        AuthType Apache2::AuthCookieLDAP
        AuthName MyAuth
        PerlResponseHandler MyAuthCookieLDAP->login
    </Location>

    <Location /logout>
        SetHandler perl-script
        AuthType Apache2::AuthCookieLDAP
        AuthName MyAuth
        PerlResponseHandler Apache2::AuthCookieLDAP->logout
    </Location>

=head1 DESCRIPTION

This module acts as an authentication handler under Apache2 environment. 
It uses Apache2::AuthCookie as the base class and serves as a backend to 
provide user authentication against an LDAP server.

Make sure that you have got a reachable LDAP server and credentials to access it 
(ldapuri, base, binddn/bindpw or anonymous bind).

When there is an attempt to access a "protected" directory or location
that has 'require valid-user' option included Apache2::AuthCookieLDAP is used 
as the authentication and the authorization handler. It takes a pair of
provided username/password and tries to search the username in the LDAP directory 
(it also uses the filter MyAuth_Filter, for puropses where you want to restrict access
to the resource to only a specific group). If the user is found then it tries 
to bind with the provided username/password.  Once authorized a session key 
is generated by taking into account the provided username, authorization time 
and a hash generated by including a specific logic plus the user's IP address. 
Upon completion the session data is encrypted with the secret key (MyAuth_SecretKey) 
and the according cookie is generated by Apache2::AuthCookie.  
All the following requests to the protected resource take the cookie (if exists)
and the encrypted session key is validated (decrypted, the user is checked, 
the session time is checked for expiration and the hash is regenerated 
and compared with the provided one).
Upon success the user is authorized to access the protected resource.

Should you require any additional information how the cookies logic works 
please check L<Apache2::AuthCookie> documentation.

=head1 APACHE CONFIGURATION DIRECTIVES

All the configuration directives as used in the following format:

    PerlSetVar "AuthName""DirectiveName"

So if your have:
    
    <Directory /var/www/mysite/protected>
        AuthType Apache2::AuthCookieLDAP
        AuthName WhateverAuthName
    ...

Then the directive name for you will be (for instance):

    PerlSetVar WhatEverAuthName_SecretKey

=over 4

=item C<MyAuth_SecretKey> 

lib/Apache2/AuthCookieLDAP.pm  view on Meta::CPAN


Decrypts $str and returns the provided encrypted session string.

=head2 check_expire_time($r, $session_time)

Checks the provided session time (unixtime) with the current time
and returns '0' if the session time is still valid or '1' if passed.

=head2 authen_cred($r, $user, $password, @extra_data) 

This is the overridden method of Apache::AuthCookie and is used to
authenticate $user with the provided $password

Returns the encrypted session key in case of successfull authentication.

Please follow to Apache2::AuthCookie if you need more information about the method.

=head2 authen_ses_key($r, $session_key)

This is the overridden method of Apache::AuthCookie and is used to
validate the provided $session_key. 

Returns the authenticated username in case of success or redirects to the login page otherwise.

Please follow to Apache2::AuthCookie if you need more information about the method.

=head1 SUBCLASSING

You can subclass the module and override any of the available methods.

=head1 CREDITS

"SecretKey", "Lifetime" Apache config directive names and their definition style 
are similar to Apache2::AuthCookieDBI to keep it common for those 
who use both of the modules.

Authors of Apache2::AuthCookieDBI 

Authors of Apache2::AuthCookie

=head1 COPYRIGHT

Copyright (C) 2013 Kirill Solomko

=head1 LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=head1 BUGS

Please report any bugs or feature requests through the web interface at:
 http://rt.cpan.org/Public/Dist/Display.html?Name=Apache2-AuthCookieLDAP

=head1 TODO

=over 4

=item Add package tests.

=back

=head1 SEE ALSO

L<perl(1)>, L<Apache2::AuthCookie>, L<Apache2::AuthCookieDBI>

=cut

__END__

# vim: sw=4 ts=4 et



( run in 0.708 second using v1.01-cache-2.11-cpan-e9199f4ba4c )