2008-12-26 20:18:23 +01:00
|
|
|
##@file
|
|
|
|
# LDAP user database backend file
|
|
|
|
#
|
|
|
|
#@copy 2008, Xavier Guimard <x.guimard@free.fr>
|
|
|
|
|
|
|
|
##@class
|
|
|
|
# LDAP user database backend class
|
2008-10-05 20:42:50 +02:00
|
|
|
package Lemonldap::NG::Portal::UserDBLDAP;
|
|
|
|
|
|
|
|
use Lemonldap::NG::Portal::Simple;
|
|
|
|
use Lemonldap::NG::Portal::_LDAP;
|
|
|
|
|
|
|
|
our $VERSION = '0.1';
|
|
|
|
|
2008-12-28 09:36:52 +01:00
|
|
|
## @method private Lemonldap::NG::Portal::_LDAP ldap()
|
|
|
|
# @return Lemonldap::NG::Portal::_LDAP object
|
2008-10-05 20:42:50 +02:00
|
|
|
sub ldap {
|
|
|
|
my $self = shift;
|
2008-10-07 22:15:48 +02:00
|
|
|
unless ( ref( $self->{ldap} ) ) {
|
2008-10-08 11:40:24 +02:00
|
|
|
my $mesg = $self->{ldap}->bind
|
2008-10-07 22:15:48 +02:00
|
|
|
if ( $self->{ldap} = Lemonldap::NG::Portal::_LDAP->new($self) );
|
2008-10-08 11:40:24 +02:00
|
|
|
if ( $mesg->code != 0 ) {
|
2008-10-07 22:15:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $self->{ldap};
|
2008-10-05 20:42:50 +02:00
|
|
|
}
|
|
|
|
|
2008-12-28 09:36:52 +01:00
|
|
|
## @method int userDBInit()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Does nothing.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-10-05 20:42:50 +02:00
|
|
|
sub userDBInit {
|
2008-10-07 22:15:48 +02:00
|
|
|
PE_OK;
|
2008-10-05 20:42:50 +02:00
|
|
|
}
|
|
|
|
|
2008-12-28 09:36:52 +01:00
|
|
|
## @method int getUser()
|
2008-12-26 20:18:23 +01:00
|
|
|
# 7) Launch formateFilter() and search()
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-10-05 20:42:50 +02:00
|
|
|
sub getUser {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->_subProcess(qw(formateFilter search));
|
|
|
|
}
|
|
|
|
|
2008-12-28 09:36:52 +01:00
|
|
|
## @method int formateFilter()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Set the LDAP filter.
|
|
|
|
# By default, the user is searched in the LDAP server with its UID.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-10-05 20:42:50 +02:00
|
|
|
sub formateFilter {
|
|
|
|
my $self = shift;
|
2008-12-26 20:18:23 +01:00
|
|
|
$self->{filter} = $self->{authFilter} || $self->{filter} || "(&(uid=" . $self->{user} . ")(objectClass=inetOrgPerson))";
|
2008-10-05 20:42:50 +02:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-28 09:36:52 +01:00
|
|
|
## @method int search()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Search the LDAP DN of the user.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-10-05 20:42:50 +02:00
|
|
|
sub search {
|
|
|
|
my $self = shift;
|
2008-10-07 22:15:48 +02:00
|
|
|
unless ( $self->ldap ) {
|
|
|
|
return PE_LDAPCONNECTFAILED;
|
|
|
|
}
|
2008-10-05 20:42:50 +02:00
|
|
|
my $mesg = $self->ldap->search(
|
|
|
|
base => $self->{ldapBase},
|
|
|
|
scope => 'sub',
|
|
|
|
filter => $self->{filter},
|
|
|
|
);
|
|
|
|
if ( $mesg->code() != 0 ) {
|
|
|
|
print STDERR $mesg->error . "\n";
|
|
|
|
return PE_LDAPERROR;
|
|
|
|
}
|
2008-12-03 14:30:37 +01:00
|
|
|
return PE_BADCREDENTIALS unless ( $self->{entry} = $mesg->entry(0) );
|
2008-10-05 20:42:50 +02:00
|
|
|
$self->{dn} = $self->{entry}->dn();
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method int setSessionInfo()
|
2008-12-26 20:18:23 +01:00
|
|
|
# 7) Load all parameters included in exportedVars parameter.
|
|
|
|
# Multi-value parameters are loaded in a single string with
|
|
|
|
# '; ' separator
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-10-05 20:42:50 +02:00
|
|
|
sub setSessionInfo {
|
|
|
|
my ($self) = @_;
|
|
|
|
$self->{sessionInfo}->{dn} = $self->{dn};
|
|
|
|
$self->{sessionInfo}->{startTime} =
|
|
|
|
&POSIX::strftime( "%Y%m%d%H%M%S", localtime() );
|
|
|
|
unless ( $self->{exportedVars} ) {
|
|
|
|
foreach (qw(uid cn mail)) {
|
|
|
|
$self->{sessionInfo}->{$_} =
|
|
|
|
join( '; ', $self->{entry}->get_value($_) ) || "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ( ref( $self->{exportedVars} ) eq 'HASH' ) {
|
|
|
|
foreach ( keys %{ $self->{exportedVars} } ) {
|
|
|
|
if ( my $tmp = $ENV{$_} ) {
|
|
|
|
$tmp =~ s/[\r\n]/ /gs;
|
|
|
|
$self->{sessionInfo}->{$_} = $tmp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->{sessionInfo}->{$_} = join( '; ',
|
|
|
|
$self->{entry}->get_value( $self->{exportedVars}->{$_} ) )
|
|
|
|
|| "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-11-21 08:27:08 +01:00
|
|
|
$self->abort('Only hash reference are supported now in exportedVars');
|
2008-10-05 20:42:50 +02:00
|
|
|
}
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|