2011-11-17 16:38:01 +01:00
|
|
|
|
##@file
|
|
|
|
|
# Radius authentication backend file
|
|
|
|
|
|
|
|
|
|
##@class
|
|
|
|
|
# Radius authentication backend class
|
|
|
|
|
package Lemonldap::NG::Portal::AuthRadius;
|
|
|
|
|
|
|
|
|
|
# Author: Sebastien Bahloul
|
|
|
|
|
|
|
|
|
|
use Lemonldap::NG::Portal::Simple;
|
|
|
|
|
use Lemonldap::NG::Portal::_WebForm;
|
|
|
|
|
|
|
|
|
|
our $VERSION = '1.2.0';
|
|
|
|
|
use base qw(Lemonldap::NG::Portal::_WebForm);
|
|
|
|
|
|
|
|
|
|
## @apmethod int authInit()
|
|
|
|
|
# Set _authnLevel
|
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
|
sub authInit {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
# require Perl module
|
|
|
|
|
eval { require Authen::Radius; };
|
|
|
|
|
if ($@) {
|
|
|
|
|
$self->lmLog( "Module Authen::Radius not found in @INC", 'error' );
|
|
|
|
|
return PE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$self->lmLog( "Opening connexion to " . $self->{radiusServer} . " ...",
|
|
|
|
|
'debug' );
|
|
|
|
|
$self->{radius} = new Authen::Radius(
|
|
|
|
|
Host => $self->{radiusServer},
|
|
|
|
|
Secret => $self->{radiusSecret}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
unless ( $self->{radius} ) {
|
|
|
|
|
return PE_RADIUSCONNECTFAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$self->{_authnLevel} = $self->{radiusAuthnLevel};
|
|
|
|
|
|
|
|
|
|
PE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## @apmethod int authenticate()
|
|
|
|
|
# Authenticate user by LDAP mechanism.
|
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
|
sub authenticate {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
unless ( $self->{radius} ) {
|
|
|
|
|
return PE_RADIUSCONNECTFAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $res = $self->{radius}->check_pwd( $self->{user}, $self->{password} );
|
|
|
|
|
|
|
|
|
|
unless ( $res == 1 ) {
|
2013-10-13 14:15:01 +02:00
|
|
|
|
$self->_sub( 'userNotice',
|
|
|
|
|
"Unable to authenticate " . $self->{user} . " !" );
|
2011-11-17 16:38:01 +01:00
|
|
|
|
return PE_BADCREDENTIALS;
|
|
|
|
|
}
|
|
|
|
|
return PE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## @apmethod int authFinish()
|
|
|
|
|
# Unbind.
|
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
|
sub authFinish {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
$self->{radius} = 0;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 15:47:47 +01:00
|
|
|
|
## @method string getDisplayType
|
|
|
|
|
# @return display type
|
|
|
|
|
sub getDisplayType {
|
|
|
|
|
return "standardform";
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-17 16:38:01 +01:00
|
|
|
|
1;
|