2008-12-31 16:10:02 +01:00
|
|
|
## @file
|
|
|
|
# Alias for Lemonldap::NG::Handler::SharedConf
|
|
|
|
|
|
|
|
## @class
|
|
|
|
# Alias for Lemonldap::NG::Handler::SharedConf
|
2006-12-18 12:32:33 +01:00
|
|
|
package Lemonldap::NG::Handler;
|
|
|
|
|
2009-06-03 14:41:37 +02:00
|
|
|
our $VERSION = "0.91";
|
2008-12-31 16:10:02 +01:00
|
|
|
use Lemonldap::NG::Handler::SharedConf;
|
|
|
|
use base qw(Lemonldap::NG::Handler::SharedConf);
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
Lemonldap::NG::Handler - The Apache protection module part of
|
|
|
|
Lemonldap::NG Web-SSO system.
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
=head2 Create your Apache module
|
|
|
|
|
|
|
|
Create your own package (example using a central configuration database):
|
|
|
|
|
|
|
|
package My::Package;
|
2006-12-24 09:37:49 +01:00
|
|
|
use Lemonldap::NG::Handler::SharedConf;
|
|
|
|
@ISA = qw(Lemonldap::NG::Handler::SharedConf);
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
__PACKAGE__->init ( {
|
|
|
|
# Local storage used for sessions and configuration
|
|
|
|
localStorage => "Cache::DBFile",
|
|
|
|
localStorageOptions => {...},
|
|
|
|
# How to get my configuration
|
2006-12-24 09:37:49 +01:00
|
|
|
configStorage => {
|
|
|
|
type => "DBI",
|
|
|
|
dbiChain => "DBI:mysql:database=lemondb;host=$hostname",
|
|
|
|
dbiUser => "lemonldap",
|
2008-05-09 22:50:27 +02:00
|
|
|
dbiPassword => "password",
|
2006-12-24 09:37:49 +01:00
|
|
|
}
|
2008-05-09 22:50:27 +02:00
|
|
|
# Uncomment this to activate status module
|
|
|
|
# status => 1,
|
2006-12-18 12:32:33 +01:00
|
|
|
} );
|
|
|
|
|
|
|
|
=head2 Configure Apache
|
|
|
|
|
|
|
|
Call your package in /apache-dir/conf/httpd.conf:
|
|
|
|
|
|
|
|
# Load your package
|
|
|
|
PerlRequire /My/File
|
|
|
|
# TOTAL PROTECTION
|
2007-01-04 17:17:40 +01:00
|
|
|
PerlHeaderParserHandler My::Package
|
2006-12-18 12:32:33 +01:00
|
|
|
# OR SELECTED AREA
|
|
|
|
<Location /protected-area>
|
2007-01-04 17:17:40 +01:00
|
|
|
PerlHeaderParserHandler My::Package
|
2006-12-18 12:32:33 +01:00
|
|
|
</Location>
|
|
|
|
|
|
|
|
The configuration is loaded only at Apache start. Create an URI to force
|
|
|
|
configuration reload, so you don't need to restart Apache at each change:
|
|
|
|
|
|
|
|
# /apache-dir/conf/httpd.conf
|
|
|
|
<Location /location/that/I/ve/choosed>
|
|
|
|
Order deny,allow
|
|
|
|
Deny from all
|
|
|
|
Allow from my.manager.com
|
2007-01-04 17:17:40 +01:00
|
|
|
PerlHeaderParserHandler My::Package->refresh
|
2006-12-18 12:32:33 +01:00
|
|
|
</Location>
|
2007-02-04 15:34:41 +01:00
|
|
|
|
|
|
|
You can also unprotect an URI
|
|
|
|
|
|
|
|
<Files "*.gif">
|
|
|
|
PerlHeaderParserHandler My::Package->unprotect
|
|
|
|
</Files>
|
|
|
|
|
2008-05-09 22:50:27 +02:00
|
|
|
To display the status page, add something like this :
|
|
|
|
|
|
|
|
<Location /status>
|
|
|
|
Order deny,allow
|
|
|
|
Allow from 10.1.1.0/24
|
|
|
|
Deny from all
|
|
|
|
PerlHeaderParserHandler My::Package->status
|
|
|
|
</Location>
|
|
|
|
|
2007-07-22 22:30:27 +02:00
|
|
|
If your application has a "logout" URL, you can configure it directly in Apache
|
2008-05-09 22:50:27 +02:00
|
|
|
configuration file (or in the manager interface). THIS IS DEPRECATED, use the
|
|
|
|
manager :
|
2007-03-24 16:18:52 +01:00
|
|
|
|
|
|
|
<Location /logout>
|
|
|
|
PerlHeaderParserHandler My::Package->logout
|
|
|
|
</Location>
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Lemonldap::NG is a modular Web-SSO based on Apache::Session modules. It
|
|
|
|
simplifies the build of a protected area with a few changes in the application.
|
|
|
|
|
|
|
|
It manages both authentication and authorization and provides headers for
|
|
|
|
accounting. So you can have a full AAA protection for your web space as
|
|
|
|
described below.
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
The Apache module part works both with Apache 1.3.x and 2.x ie mod_perl 1 and 2
|
2006-12-24 09:37:49 +01:00
|
|
|
but B<not with mod_perl 1.99>.
|
2006-12-18 12:32:33 +01:00
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
=head2 Authentication, Authorization, Accounting
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=head3 B<Authentication>
|
|
|
|
|
|
|
|
If a user isn't authenticated and attemps to connect to an area protected by a
|
|
|
|
Lemonldap::NG compatible handler, he is redirected to a portal. The portal
|
|
|
|
authenticates user with a ldap bind by default, but you can also use another
|
|
|
|
authentication sheme like using x509 user certificates (see
|
|
|
|
L<Lemonldap::NG::Portal::AuthSSL> for more).
|
|
|
|
|
2007-05-05 16:13:44 +02:00
|
|
|
Lemonldap::NG use session cookies generated by L<Apache::Session> so as secure
|
|
|
|
as a 128-bit random cookie. You may use the C<securedCookie> options of
|
2006-12-18 12:32:33 +01:00
|
|
|
L<Lemonldap::NG::Portal> to avoid session hijacking.
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
You have to manage life of sessions by yourself since Lemonldap::NG knows
|
|
|
|
nothing about the L<Apache::Session> module you've choosed, but it's very easy
|
|
|
|
using a simple cron script because L<Lemonldap::NG::Portal> stores the start
|
|
|
|
time in the C<_utime> field.
|
2006-12-18 12:32:33 +01:00
|
|
|
By default, a session stay 10 minutes in the local storage, so in the worth
|
|
|
|
case, a user is authorized 10 minutes after he lost his rights.
|
|
|
|
|
|
|
|
=head3 B<Authorization>
|
|
|
|
|
|
|
|
Authorization is controled only by handlers because the portal knows nothing
|
|
|
|
about the way the user will choose. When configuring your Web-SSO, you have to:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * choose the ldap attributes you want to use to manage accounting and
|
|
|
|
authorization (see C<exportedHeaders> parameter in L<Lemonldap::NG::Portal>
|
|
|
|
documentation).
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
=item * create Perl expressions to define user groups (using ldap attributes)
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=item * create an array foreach virtual host associating URI regular
|
|
|
|
expressions and Perl expressions to use to grant access.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
2006-12-24 09:37:49 +01:00
|
|
|
=head4 Example (See L<Lemonldap::NG::Manager> to see how configuration is
|
|
|
|
stored)
|
2006-12-18 12:32:33 +01:00
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
Exported variables (values will be stored in session database by
|
|
|
|
L<Lemonldap::NG::Portal>):
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
exportedVars => {
|
|
|
|
cn => "cn",
|
|
|
|
departmentUID => "departmentUID",
|
|
|
|
login => "uid",
|
|
|
|
},
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
User groups (values will be stored in session database by
|
|
|
|
L<Lemonldap::NG::Portal>):
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
groups => {
|
|
|
|
group1 => '{ $departmentUID eq "unit1" or $login = "xavier.guimard" }',
|
|
|
|
...
|
|
|
|
},
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
Area protection:
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
locationRules => {
|
|
|
|
www1.domain.com => {
|
|
|
|
'^/protected/.*$' => '$groups =~ /\bgroup1\b/',
|
|
|
|
default => 'accept',
|
|
|
|
},
|
|
|
|
www2.domain.com => {
|
|
|
|
'^/site/.*$' => '$uid eq "xavier.guimard" or $groups =~ /\bgroup2\b/',
|
|
|
|
'^/(js|css)' => 'accept',
|
|
|
|
default => 'deny',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
=head4 Performance
|
|
|
|
|
|
|
|
You can use Perl expressions as complicated as you want and you can use all
|
2007-01-22 16:47:11 +01:00
|
|
|
the exported LDAP attributes (and create your own attributes: with 'macros'
|
|
|
|
mechanism. See L<Lemonldap::NG::Manager>) in groups evaluations, area
|
|
|
|
protections or custom HTTP headers (you just have to call them with a "$").
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
You have to be careful when choosing your expressions:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
=item * C<groups> and C<macros> are evaluated each time a user is redirected to
|
|
|
|
the portal,
|
2006-12-18 12:32:33 +01:00
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
=item * C<locationRules> and C<exportedheaders> are evaluated for each request
|
|
|
|
on a protected area.
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
It is also recommanded to use the C<groups> mechanism to avoid having to
|
|
|
|
evaluate a long expression at each HTTP request:
|
|
|
|
|
|
|
|
locationRules => {
|
|
|
|
www1.domain.com => {
|
|
|
|
'^/protected/.*$' => '$groups =~ /\bgroup1\b/',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
You can also use LDAP filters, or Perl expression or mixed expressions in
|
|
|
|
C<groups> parameter. Perl expressions has to be enclosed with C<{}>:
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * C<group1 =E<gt> '(|(uid=xavier.guimard)(ou=unit1))'>
|
|
|
|
|
|
|
|
=item * C<group1 =E<gt> '{$uid eq "xavier.guimard" or $ou eq "unit1"}'>
|
|
|
|
|
|
|
|
=item * C<group1 =E<gt> '(|(uid=xavier.guimard){$ou eq "unit1"})'>
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
It is also recommanded to use Perl expressions to avoid requiering the LDAP
|
|
|
|
server more than 2 times per authentication.
|
|
|
|
|
|
|
|
=head3 B<Accounting>
|
|
|
|
|
|
|
|
=head4 I<Logging portal access>
|
|
|
|
|
|
|
|
L<Lemonldap::NG::Portal> doesn't log anything by default, but it's easy to overload
|
|
|
|
C<log> method for normal portal access or using C<error> method to know what
|
|
|
|
was wrong if C<process> method has failed.
|
|
|
|
|
|
|
|
=head4 I<Logging application access>
|
|
|
|
|
|
|
|
Because an handler knows nothing about the protected application, it can't do
|
2007-01-22 16:47:11 +01:00
|
|
|
more than logging URL. As Apache does this fine, L<Lemonldap::NG::Handler>
|
|
|
|
gives it the name to used in logs. The C<whatToTrace> parameters indicates
|
|
|
|
which variable Apache has to use (C<$uid> by default).
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
The real accounting has to be done by the application itself which knows the
|
|
|
|
result of SQL transaction for example.
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
Lemonldap::NG can export HTTP headers either using a proxy or protecting
|
|
|
|
directly the application. By default, the C<Auth-User> field is used but you
|
|
|
|
can change it using the C<exportedHeaders> parameters (stored in the
|
|
|
|
configuration database). This parameters contains an associative array per
|
|
|
|
virtual host:
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * B<keys> are the names of the choosen headers
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
=item * B<values> are Perl expressions where you can use user datas stored in
|
2006-12-18 12:32:33 +01:00
|
|
|
the global store by calling them C<$E<lt>varnameE<gt>>.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
exportedHeaders => {
|
|
|
|
www1.domain.com => {
|
|
|
|
'Auth-User' => '$uid',
|
|
|
|
'Unit' => '$ou',
|
|
|
|
},
|
|
|
|
www2.domain.com => {
|
|
|
|
'Authorization' => '"Basic ".encode_base64($employeeNumber.":dummy")',
|
2007-01-22 16:47:11 +01:00
|
|
|
'Remote-IP' => '$ip',
|
2006-12-18 12:32:33 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
=head2 Session storage systems
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
Lemonldap::NG use 3 levels of cache for authenticated users:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * an Apache::Session::* module choosed with the C<globalStorage>
|
|
|
|
parameter (completed with C<globalStorageOptions>) and used by
|
|
|
|
L<lemonldap::NG::Portal> to store authenticated user parameters,
|
|
|
|
|
|
|
|
=item * a L<Cache::Cache> module choosed with the C<localStorage> parameter
|
2007-01-22 16:47:11 +01:00
|
|
|
(completed with C<localStorageOptions>) and used to share authenticated users
|
2006-12-18 12:32:33 +01:00
|
|
|
between Apache's threads or processus and of course between virtual hosts,
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
=item * Lemonldap::NG::Handler variables: if the same user use the same thread
|
|
|
|
or processus a second time, no request are needed to grant or refuse access.
|
|
|
|
This is very efficient with HTTP/1.1 Keep-Alive system.
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
2007-01-22 16:47:11 +01:00
|
|
|
So the number of request to the central storage is limited to 1 per active
|
|
|
|
user each 10 minutes.
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
Lemonldap::NG is very fast, but you can increase performance using a
|
|
|
|
L<Cache::Cache> module that does not use disk access.
|
|
|
|
|
2007-03-24 16:18:52 +01:00
|
|
|
=head2 Logout system
|
|
|
|
|
|
|
|
Lemonldap::NG provides a single logout system: you can use it by adding a link
|
|
|
|
to the portal with "logout=1" parameter in the portal (See
|
|
|
|
L<Lemonldap::NG::Portal>) and/or by configuring handler to intercept some URL
|
|
|
|
(See Sinopsys). The logout system:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * delete session in the global session storage,
|
|
|
|
|
|
|
|
=item * replace Lemonldap::NG cookie by '',
|
|
|
|
|
|
|
|
=item * delete handler caches only if logout action was started from a
|
|
|
|
protected application and only in the current Apache server. So in other
|
|
|
|
servers, session is still in cache for 10 minutes maximum if the user was
|
|
|
|
connected on it in the last 10 minutes.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
2007-07-22 22:30:27 +02:00
|
|
|
You can also configure rules in the Manager interface to intercept logout URL.
|
|
|
|
See L<Lemonldap::NG::Manager> and L<Lemonldap::NG::Handler> for more.
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
=head1 USING LEMONLDAP::NG::HANDLER FOR DEVELOPMENT
|
|
|
|
|
|
|
|
Lemonldap::NG::Handler provides different modules:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * L<Lemonldap::NG::Handler::Simple>: base module. It can be used
|
|
|
|
directly to protect a single host.
|
|
|
|
|
|
|
|
=item * L<Lemonldap::NG::Handler::Vhost>: module used to managed virtual hosts.
|
|
|
|
|
|
|
|
=item * L<Lemonldap::NG::Handler::SharedConf>: with this module, the
|
|
|
|
configuration can be centralized. Inherits from
|
|
|
|
L<Lemonldap::NG::Handler::Vhost> and L<Lemonldap::NG::Handler::Simple>.
|
|
|
|
|
2007-04-14 15:12:11 +02:00
|
|
|
=item * L<Lemonldap::NG::Handler::CGI>: if you have only a few Perl CGI to
|
|
|
|
protect, you can use this module in your CGI instead of protecting it under
|
|
|
|
L<Lemonldap::NG::Handler::SharedConf>.
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
=item * L<Lemonldap::NG::Handler::Proxy>: this module isn't used to manage
|
|
|
|
security but is written to create a reverse-proxy without using mod_proxy. In
|
|
|
|
some case, mod_proxy does not manage correctly some redirections, that is why
|
|
|
|
this module still exists.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
All those modules are compatible both with Apache and mod_perl version 1 and 2,
|
|
|
|
but NOT with mod_perl 1.99. If you use Linux distributions like Debian Sarge
|
|
|
|
who provide mod_perl 1.99 for Apache2, you have to use Apache-1.3 or to
|
|
|
|
download a mod_perl2 backport.
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2006-12-24 09:37:49 +01:00
|
|
|
L<Lemonldap::NG::Handler::SharedConf>,
|
2007-04-02 21:13:05 +02:00
|
|
|
L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Manager>,
|
2007-04-14 15:12:11 +02:00
|
|
|
L<http://wiki.lemonldap.objectweb.org/xwiki/bin/view/NG/Presentation>
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
|
|
|
|
2007-04-14 15:12:11 +02:00
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
|
|
|
L<http://forge.objectweb.org/tracker/?group_id=274>
|
|
|
|
|
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
2007-03-18 19:33:38 +01:00
|
|
|
Copyright (C) 2005-2007 by Xavier Guimard E<lt>x.guimard@free.frE<gt>
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.4 or,
|
|
|
|
at your option, any later version of Perl 5 you may have available.
|
|
|
|
|
|
|
|
Lemonldap was originaly written by Eric German who decided to publish him in
|
|
|
|
2003 under the terms of the GNU General Public License version 2.
|
|
|
|
Lemonldap::NG is a complete rewrite of Lemonldap and is able to have different
|
|
|
|
policies in a same Apache virtual host.
|
|
|
|
|
|
|
|
=cut
|