2009-12-10 12:30:43 +01:00
|
|
|
|
##@file
|
|
|
|
|
# DBI authentication backend file
|
|
|
|
|
|
|
|
|
|
##@class
|
|
|
|
|
# LDAP authentication backend class
|
|
|
|
|
package Lemonldap::NG::Portal::AuthDBI;
|
|
|
|
|
|
|
|
|
|
use Lemonldap::NG::Portal::Simple;
|
|
|
|
|
use base qw(Lemonldap::NG::Portal::_WebForm Lemonldap::NG::Portal::_DBI);
|
2009-12-21 23:28:38 +01:00
|
|
|
|
use strict;
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
|
|
|
|
our $VERSION = '0.1';
|
2010-09-23 17:09:27 +02:00
|
|
|
|
our $initDone;
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
|
|
|
|
## @apmethod int authInit()
|
|
|
|
|
# Check DBI paramaters
|
|
|
|
|
#@return Lemonldap::NG::Portal constant
|
|
|
|
|
sub authInit {
|
|
|
|
|
my $self = shift;
|
2010-09-23 17:09:27 +02:00
|
|
|
|
return PE_OK if ($initDone);
|
|
|
|
|
|
2009-12-11 22:17:06 +01:00
|
|
|
|
unless ($self->{dbiAuthChain}
|
2009-12-10 12:30:43 +01:00
|
|
|
|
and $self->{dbiAuthTable}
|
|
|
|
|
and $self->{dbiAuthUser}
|
|
|
|
|
and $self->{dbiAuthPassword}
|
|
|
|
|
and $self->{dbiAuthLoginCol}
|
2009-12-11 22:17:06 +01:00
|
|
|
|
and $self->{dbiAuthPasswordCol} )
|
|
|
|
|
{
|
|
|
|
|
$self->lmLog( "Missing configuration parameters for DBI authentication",
|
|
|
|
|
'error' );
|
|
|
|
|
return PE_ERROR;
|
2009-12-10 12:30:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 17:09:27 +02:00
|
|
|
|
$initDone = 1;
|
2009-12-10 12:30:43 +01:00
|
|
|
|
PE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## @apmethod int authenticate()
|
|
|
|
|
# Find row in DBI backend with user and password criterions
|
|
|
|
|
#@return Lemonldap::NG::Portal constant
|
|
|
|
|
sub authenticate {
|
|
|
|
|
my $self = shift;
|
2010-09-23 17:09:27 +02:00
|
|
|
|
$self->{_authnLevel} = $self->{dbiAuthnLevel};
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
|
|
|
|
# Connect
|
2009-12-11 22:17:06 +01:00
|
|
|
|
my $dbh =
|
|
|
|
|
$self->dbh( $self->{dbiAuthChain}, $self->{dbiAuthUser},
|
|
|
|
|
$self->{dbiAuthPassword} );
|
2009-12-10 12:30:43 +01:00
|
|
|
|
return PE_ERROR unless $dbh;
|
|
|
|
|
|
|
|
|
|
# Check credentials
|
2009-12-22 09:46:54 +01:00
|
|
|
|
my $result = $self->check_password($dbh);
|
|
|
|
|
if ($result) {
|
2009-12-10 12:30:43 +01:00
|
|
|
|
return PE_OK;
|
2009-12-11 22:17:06 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-12-10 12:30:43 +01:00
|
|
|
|
return PE_BADCREDENTIALS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 10:59:39 +02:00
|
|
|
|
## @apmethod int authFinish()
|
|
|
|
|
# Disconnect.
|
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
|
sub authFinish {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
eval { $self->{_dbh}->disconnect(); };
|
|
|
|
|
|
|
|
|
|
PE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## @apmethod int authLogout()
|
|
|
|
|
# Does nothing
|
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
|
sub authLogout {
|
|
|
|
|
PE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## @apmethod boolean authForce()
|
|
|
|
|
# Does nothing
|
|
|
|
|
# @return result
|
|
|
|
|
sub authForce {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-10 12:30:43 +01:00
|
|
|
|
1;
|