Remove already transformed files (#595)
parent
6e837af219
commit
6b2b7edd80
@ -1,179 +0,0 @@ |
||||
##@file |
||||
# Apache authentication backend file |
||||
|
||||
##@class |
||||
# Apache authentication backend class |
||||
package Lemonldap::NG::Portal::AuthApache; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @apmethod int authInit() |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authInit { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int extractFormInfo() |
||||
# Read username return by Apache authentication system. |
||||
# By default, authentication is valid if REMOTE_USER environment |
||||
# variable is set. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub extractFormInfo { |
||||
my $self = shift; |
||||
unless ( $self->{user} = $ENV{REMOTE_USER} ) { |
||||
$self->lmLog( 'Apache is not configured to authenticate users!', |
||||
'error' ); |
||||
return PE_ERROR; |
||||
} |
||||
|
||||
# This is needed for Kerberos authentication |
||||
$self->{user} =~ s/^(.*)@.*$/$1/g; |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setAuthSessionInfo() |
||||
# Set _user and authenticationLevel. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setAuthSessionInfo { |
||||
my $self = shift; |
||||
|
||||
# Store user submitted login for basic rules |
||||
$self->{sessionInfo}->{'_user'} = $self->{'user'}; |
||||
|
||||
$self->{sessionInfo}->{authenticationLevel} = $self->{apacheAuthnLevel}; |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authenticate() |
||||
# Does nothing. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authenticate { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authFinish() |
||||
# Does nothing. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authFinish { |
||||
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; |
||||
} |
||||
|
||||
## @method string getDisplayType |
||||
# @return display type |
||||
sub getDisplayType { |
||||
return "logo"; |
||||
} |
||||
|
||||
1; |
||||
__END__ |
||||
|
||||
=head1 NAME |
||||
|
||||
=encoding utf8 |
||||
|
||||
Lemonldap::NG::Portal::AuthApache - Perl extension for building Lemonldap::NG |
||||
compatible portals with Apache authentication. |
||||
|
||||
=head1 SYNOPSIS |
||||
|
||||
use Lemonldap::NG::Portal::SharedConf; |
||||
my $portal = new Lemonldap::NG::Portal::Simple( |
||||
configStorage => {...}, # See Lemonldap::NG::Portal |
||||
authentication => 'Apache', |
||||
); |
||||
|
||||
if($portal->process()) { |
||||
# Write here the menu with CGI methods. This page is displayed ONLY IF |
||||
# the user was not redirected here. |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "..."; |
||||
|
||||
# or redirect the user to the menu |
||||
print $portal->redirect( -uri => 'https://portal/menu'); |
||||
} |
||||
else { |
||||
# If the user enters here, IT MEANS THAT APACHE AUTHENTICATION DOES NOT WORK |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "<html><body><h1>Unable to work</h1>"; |
||||
print "This server isn't well configured. Contact your administrator."; |
||||
print "</body></html>"; |
||||
} |
||||
|
||||
and of course, configure Apache to protect the portal. |
||||
|
||||
=head1 DESCRIPTION |
||||
|
||||
This library just overload few methods of Lemonldap::NG::Portal::Simple to use |
||||
Apache authentication mechanism: we've just try to get REMOTE_USER environment |
||||
variable. |
||||
|
||||
See L<Lemonldap::NG::Portal::Simple> for usage and other methods. |
||||
|
||||
=head1 SEE ALSO |
||||
|
||||
L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Portal::Simple>, |
||||
L<http://lemonldap-ng.org/> |
||||
|
||||
=head1 AUTHOR |
||||
|
||||
=over |
||||
|
||||
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=item Xavier Guimard, E<lt>x.guimard@free.frE<gt> |
||||
|
||||
=back |
||||
|
||||
=head1 BUG REPORT |
||||
|
||||
Use OW2 system to report bug or ask for features: |
||||
L<http://jira.ow2.org> |
||||
|
||||
=head1 DOWNLOAD |
||||
|
||||
Lemonldap::NG is available at |
||||
L<http://forge.objectweb.org/project/showfiles.php?group_id=274> |
||||
|
||||
=head1 COPYRIGHT AND LICENSE |
||||
|
||||
=over |
||||
|
||||
=item Copyright (C) 2007-2010 by Xavier Guimard, E<lt>x.guimard@free.frE<gt> |
||||
|
||||
=item Copyright (C) 2009-2012 by Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=back |
||||
|
||||
This library is free software; you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation; either version 2, or (at your option) |
||||
any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program. If not, see L<http://www.gnu.org/licenses/>. |
||||
|
||||
=cut |
||||
|
@ -1,276 +0,0 @@ |
||||
##@file |
||||
# BrowserID authentication backend file |
||||
|
||||
##@class |
||||
# BrowserID authentication backend class |
||||
package Lemonldap::NG::Portal::AuthBrowserID; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
use Lemonldap::NG::Portal::_Browser; |
||||
use HTTP::Request; |
||||
use JSON; |
||||
|
||||
our @ISA = (qw(Lemonldap::NG::Portal::_Browser)); |
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @apmethod int authInit() |
||||
# Enables Browser ID (required for templates) |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authInit { |
||||
my $self = shift; |
||||
|
||||
$self->{browserIdVerificationURL} ||= |
||||
"https://verifier.login.persona.org/verify"; |
||||
$self->{browserIdAuthnLevel} = "2" |
||||
unless defined $self->{browserIdAuthnLevel}; |
||||
$self->{browserIdSiteName} ||= "LemonLDAP::NG"; |
||||
$self->{browserIdBackgroundColor} ||= "#000"; |
||||
$self->{browserIdAutoLogin} ||= "0"; |
||||
|
||||
# Enable BrowserID in template |
||||
$self->{tpl_browserIdEnabled} = 1; |
||||
|
||||
# Set BrowserID customization parameters |
||||
$self->{tpl_browserIdSiteName} = $self->{browserIdSiteName} |
||||
if $self->{browserIdSiteName}; |
||||
$self->{tpl_browserIdSiteLogo} = $self->{browserIdSiteLogo} |
||||
if $self->{browserIdSiteLogo}; |
||||
$self->{tpl_browserIdBackgroundColor} = $self->{browserIdBackgroundColor} |
||||
if $self->{browserIdBackgroundColor}; |
||||
$self->{tpl_browserIdAutoLogin} = $self->{browserIdAutoLogin} |
||||
if $self->{browserIdAutoLogin}; |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setAuthSessionInfo() |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setAuthSessionInfo { |
||||
my $self = shift; |
||||
|
||||
$self->{sessionInfo}->{_user} = $self->{user}; |
||||
$self->{sessionInfo}->{authenticationLevel} = $self->{browserIdAuthnLevel}; |
||||
$self->{sessionInfo}->{_browserIdAnswer} = $self->{browserIdAnswer}; |
||||
$self->{sessionInfo}->{_browserIdAnswerRaw} = $self->{browserIdAnswerRaw}; |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int extractFormInfo() |
||||
# Get BrowserID assertion |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub extractFormInfo { |
||||
my $self = shift; |
||||
|
||||
# Assertion should be browserIdAssertion parameter |
||||
if ( $self->{browserIdAssertion} = $self->param('browserIdAssertion') ) { |
||||
$self->lmLog( |
||||
"BrowserID Assertion found: " . $self->{browserIdAssertion}, |
||||
'debug' ); |
||||
|
||||
# Resolve assertion |
||||
my $postdata = |
||||
"assertion=" |
||||
. $self->{browserIdAssertion} |
||||
. "&audience=" |
||||
. $self->{portal}; |
||||
|
||||
$self->lmLog( "Send $postdata to " . $self->{browserIdVerificationURL}, |
||||
'debug' ); |
||||
|
||||
my $request = |
||||
HTTP::Request->new( 'POST' => $self->{browserIdVerificationURL} ); |
||||
$request->content_type('application/x-www-form-urlencoded'); |
||||
$request->content($postdata); |
||||
|
||||
my $answer = $self->ua()->request($request); |
||||
|
||||
$self->lmLog( "Verification response: " . $answer->as_string, 'debug' ); |
||||
|
||||
if ( $answer->code() == "200" ) { |
||||
|
||||
# Get JSON answser |
||||
$self->{browserIdAnswerRaw} = $answer->content; |
||||
$self->lmLog( |
||||
"Received BrowserID answer: " . $self->{browserIdAnswerRaw}, |
||||
'debug' ); |
||||
|
||||
my $json = JSON->new(); |
||||
$self->{browserIdAnswer} = |
||||
$json->decode( $self->{browserIdAnswerRaw} ); |
||||
|
||||
if ( $self->{browserIdAnswer}->{status} eq "okay" ) { |
||||
$self->{user} = $self->{browserIdAnswer}->{email}; |
||||
|
||||
$self->lmLog( |
||||
"Found user " |
||||
. $self->{user} |
||||
. " in BrowserID verification answer", |
||||
'debug' |
||||
); |
||||
|
||||
return PE_OK; |
||||
} |
||||
else { |
||||
if ( $self->{browserIdAnswer}->{reason} ) { |
||||
$self->lmLog( |
||||
"Assertion " |
||||
. $self->{browserIdAssertion} |
||||
. " verification error: " |
||||
. $self->{browserIdAnswer}->{reason}, |
||||
'error' |
||||
); |
||||
|
||||
} |
||||
else { |
||||
$self->lmLog( |
||||
"Assertion " |
||||
. $self->{browserIdAssertion} |
||||
. " not verified by BrowserID provider", |
||||
'error' |
||||
); |
||||
} |
||||
return PE_BADCREDENTIALS; |
||||
} |
||||
} |
||||
else { |
||||
$self->lmLog( |
||||
"Fail to validate BrowserId assertion " |
||||
. $self->{browserIdAssertion}, |
||||
'error' |
||||
); |
||||
return PE_ERROR; |
||||
} |
||||
|
||||
return PE_OK; |
||||
} |
||||
|
||||
# No assertion, return to login page with BrowserID login script |
||||
$self->{tpl_browserIdLoadLoginScript} = 1; |
||||
return PE_FIRSTACCESS; |
||||
} |
||||
|
||||
## @apmethod int authenticate() |
||||
# Verify assertion and audience |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authenticate { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authFinish() |
||||
# Does nothing. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authFinish { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authLogout() |
||||
# Call BrowserID logout method |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authLogout { |
||||
my $self = shift; |
||||
$self->{tpl_browserIdLoadLogoutScript} = 1; |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod boolean authForce() |
||||
# Does nothing |
||||
# @return result |
||||
sub authForce { |
||||
return 0; |
||||
} |
||||
|
||||
## @method string getDisplayType |
||||
# @return display type |
||||
sub getDisplayType { |
||||
return "logo"; |
||||
} |
||||
|
||||
1; |
||||
__END__ |
||||
|
||||
=head1 NAME |
||||
|
||||
=encoding utf8 |
||||
|
||||
Lemonldap::NG::Portal::AuthBrowserID - Perl extension for building Lemonldap::NG |
||||
compatible portals with Mozilla BrowserID protocol |
||||
|
||||
=head1 SYNOPSIS |
||||
|
||||
use Lemonldap::NG::Portal::SharedConf; |
||||
my $portal = new Lemonldap::NG::Portal::Simple( |
||||
configStorage => {...}, # See Lemonldap::NG::Portal |
||||
authentication => 'BrowserID', |
||||
); |
||||
|
||||
if($portal->process()) { |
||||
# Write here the menu with CGI methods. This page is displayed ONLY IF |
||||
# the user was not redirected here. |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "..."; |
||||
|
||||
# or redirect the user to the menu |
||||
print $portal->redirect( -uri => 'https://portal/menu'); |
||||
} |
||||
else { |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "<html><body><h1>Unable to work</h1>"; |
||||
print "This server isn't well configured. Contact your administrator."; |
||||
print "</body></html>"; |
||||
} |
||||
|
||||
=head1 DESCRIPTION |
||||
|
||||
This library just overload few methods of Lemonldap::NG::Portal::Simple to |
||||
create sessions for anonymous users. |
||||
|
||||
See L<Lemonldap::NG::Portal::Simple> for usage and other methods. |
||||
|
||||
=head1 SEE ALSO |
||||
|
||||
L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Portal::Simple>, |
||||
L<http://lemonldap-ng.org/> |
||||
|
||||
=head1 AUTHOR |
||||
|
||||
=over |
||||
|
||||
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=back |
||||
|
||||
=head1 BUG REPORT |
||||
|
||||
Use OW2 system to report bug or ask for features: |
||||
L<http://jira.ow2.org> |
||||
|
||||
=head1 DOWNLOAD |
||||
|
||||
Lemonldap::NG is available at |
||||
L<http://forge.objectweb.org/project/showfiles.php?group_id=274> |
||||
|
||||
=head1 COPYRIGHT AND LICENSE |
||||
|
||||
=over |
||||
|
||||
=item Copyright (C) 2013 by Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=back |
||||
|
||||
This library is free software; you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation; either version 2, or (at your option) |
||||
any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program. If not, see L<http://www.gnu.org/licenses/>. |
||||
|
||||
=cut |
||||
|
@ -1,173 +0,0 @@ |
||||
##@file |
||||
# Demo authentication backend file |
||||
|
||||
##@class |
||||
# Demo authentication backend class |
||||
package Lemonldap::NG::Portal::AuthDemo; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
use base qw(Lemonldap::NG::Portal::_WebForm); |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @apmethod int authInit() |
||||
# Initialize demo accounts |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authInit { |
||||
my $self = shift; |
||||
|
||||
# Sample accounts from Doctor Who characters |
||||
$self->{_demoAccounts} = { |
||||
'rtyler' => { |
||||
'uid' => 'rtyler', |
||||
'cn' => 'Rose Tyler', |
||||
'mail' => 'rtyler@badwolf.org', |
||||
}, |
||||
'msmith' => { |
||||
'uid' => 'msmith', |
||||
'cn' => 'Mickey Smith', |
||||
'mail' => 'msmith@badwolf.org', |
||||
}, |
||||
'dwho' => { |
||||
'uid' => 'dwho', |
||||
'cn' => 'Doctor Who', |
||||
'mail' => 'dwho@badwolf.org', |
||||
}, |
||||
}; |
||||
|
||||
$self->{_authnLevel} = 0; |
||||
|
||||
# Add warning in log |
||||
$self->lmLog( |
||||
"Using demonstration mode, go in Manager to edit the configuration", |
||||
'warn' ); |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authenticate() |
||||
# Does nothing. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authenticate { |
||||
my $self = shift; |
||||
|
||||
return PE_BADCREDENTIALS unless ( $self->{user} eq $self->{password} ); |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authFinish() |
||||
# Does nothing. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authFinish { |
||||
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; |
||||
} |
||||
|
||||
## @method string getDisplayType |
||||
# @return display type |
||||
sub getDisplayType { |
||||
return "standardform"; |
||||
} |
||||
|
||||
1; |
||||
__END__ |
||||
|
||||
=head1 NAME |
||||
|
||||
=encoding utf8 |
||||
|
||||
Lemonldap::NG::Portal::AuthDemo - Perl extension for building Lemonldap::NG |
||||
compatible portals with built-in authentication. |
||||
|
||||
=head1 SYNOPSIS |
||||
|
||||
use Lemonldap::NG::Portal::SharedConf; |
||||
my $portal = new Lemonldap::NG::Portal::Simple( |
||||
configStorage => {...}, # See Lemonldap::NG::Portal |
||||
authentication => 'Demo', |
||||
); |
||||
|
||||
if($portal->process()) { |
||||
# Write here the menu with CGI methods. This page is displayed ONLY IF |
||||
# the user was not redirected here. |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "..."; |
||||
|
||||
# or redirect the user to the menu |
||||
print $portal->redirect( -uri => 'https://portal/menu'); |
||||
} |
||||
else { |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "<html><body><h1>Unable to work</h1>"; |
||||
print "This server isn't well configured. Contact your administrator."; |
||||
print "</body></html>"; |
||||
} |
||||
|
||||
=head1 DESCRIPTION |
||||
|
||||
This library just overload few methods of Lemonldap::NG::Portal::Simple to |
||||
create sessions for sample users. |
||||
|
||||
See L<Lemonldap::NG::Portal::Simple> for usage and other methods. |
||||
|
||||
=head1 SEE ALSO |
||||
|
||||
L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Portal::Simple>, |
||||
L<http://lemonldap-ng.org/> |
||||
|
||||
=head1 AUTHOR |
||||
|
||||
=over |
||||
|
||||
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=back |
||||
|
||||
=head1 BUG REPORT |
||||
|
||||
Use OW2 system to report bug or ask for features: |
||||
L<http://jira.ow2.org> |
||||
|
||||
=head1 DOWNLOAD |
||||
|
||||
Lemonldap::NG is available at |
||||
L<http://forge.objectweb.org/project/showfiles.php?group_id=274> |
||||
|
||||
=head1 COPYRIGHT AND LICENSE |
||||
|
||||
=over |
||||
|
||||
=item Copyright (C) 2012 by Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=back |
||||
|
||||
This library is free software; you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation; either version 2, or (at your option) |
||||
any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program. If not, see L<http://www.gnu.org/licenses/>. |
||||
|
||||
=cut |
||||
|
@ -1,115 +0,0 @@ |
||||
##@file |
||||
# LDAP authentication backend file |
||||
|
||||
##@class |
||||
# LDAP authentication backend class |
||||
package Lemonldap::NG::Portal::AuthLDAP; |
||||
|
||||
use Lemonldap::NG::Portal::Simple; |
||||
use Lemonldap::NG::Portal::_LDAP 'ldap'; #link protected ldap |
||||
use Lemonldap::NG::Portal::_WebForm; |
||||
use Lemonldap::NG::Portal::UserDBLDAP; #inherits |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
use base qw(Lemonldap::NG::Portal::_WebForm); |
||||
|
||||
*_formateFilter = *Lemonldap::NG::Portal::UserDBLDAP::formateFilter; |
||||
*_search = *Lemonldap::NG::Portal::UserDBLDAP::search; |
||||
|
||||
## @apmethod int authInit() |
||||
# Set _authnLevel |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authInit { |
||||
my $self = shift; |
||||
|
||||
$self->{_authnLevel} = $self->{ldapAuthnLevel}; |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authenticate() |
||||
# Authenticate user by LDAP mechanism. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authenticate { |
||||
my $self = shift; |
||||
|
||||
unless ( $self->ldap ) { |
||||
return PE_LDAPCONNECTFAILED; |
||||
} |
||||
|
||||
# Set the dn unless done before |
||||
unless ( $self->{dn} ) { |
||||
my $tmp = $self->_subProcess(qw(_formateFilter _search)); |
||||
$self->{sessionInfo}->{dn} = $self->{dn}; |
||||
return $tmp if ($tmp); |
||||
} |
||||
|
||||
my $res = |
||||
$self->ldap->userBind( $self->{dn}, password => $self->{password} ); |
||||
|
||||
# Remember password if password reset needed |
||||
$self->{oldpassword} = $self->{password} |
||||
if ( |
||||
$res == PE_PP_CHANGE_AFTER_RESET |
||||
or ( $res == PE_PP_PASSWORD_EXPIRED |
||||
and $self->{ldapAllowResetExpiredPassword} ) |
||||
); |
||||
|
||||
# Unbind if there was an error |
||||
unless ( $res == PE_OK ) { |
||||
$self->ldap->unbind; |
||||
$self->{flags}->{ldapActive} = 0; |
||||
} |
||||
|
||||
return $res; |
||||
} |
||||
|
||||
## @apmethod int authFinish() |
||||
# Unbind. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authFinish { |
||||
my $self = shift; |
||||
|
||||
if ( ref( $self->{ldap} ) && $self->{flags}->{ldapActive} ) { |
||||
$self->ldap->unbind(); |
||||
$self->{flags}->{ldapActive} = 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; |
||||
} |
||||
|
||||
## @method string getDisplayType |
||||
# @return display type |
||||
sub getDisplayType { |
||||
return "standardform"; |
||||
} |
||||
|
||||
## @method boolean stop |
||||
# Define which error codes will stop Multi process |
||||
# @param res error code |
||||
# @return result 1 if stop is needed |
||||
sub stop { |
||||
my ( $self, $res ) = @_; |
||||
|
||||
return 1 |
||||
if ( $res == PE_PP_PASSWORD_EXPIRED |
||||
or $res == PE_PP_ACCOUNT_LOCKED |
||||
or $res == PE_PP_CHANGE_AFTER_RESET ); |
||||
return 0; |
||||
} |
||||
|
||||
1; |
@ -1,163 +0,0 @@ |
||||
##@file |
||||
# Null authentication backend file |
||||
|
||||
##@class |
||||
# Null authentication backend class |
||||
package Lemonldap::NG::Portal::AuthNull; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @apmethod int authInit() |
||||
# Does nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authInit { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setAuthSessionInfo() |
||||
# Set _user value to 'anonymous' and authenticationLevel to 0 |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setAuthSessionInfo { |
||||
my $self = shift; |
||||
|
||||
$self->{sessionInfo}->{'_user'} = 'anonymous'; |
||||
$self->{sessionInfo}->{authenticationLevel} = $self->{nullAuthnLevel}; |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int extractFormInfo() |
||||
# Does nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub extractFormInfo { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authenticate() |
||||
# Does nothing. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authenticate { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int authFinish() |
||||
# Does nothing. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub authFinish { |
||||
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; |
||||
} |
||||
|
||||
## @method string getDisplayType |
||||
# @return display type |
||||
sub getDisplayType { |
||||
return ""; |
||||
} |
||||
|
||||
1; |
||||
__END__ |
||||
|
||||
=head1 NAME |
||||
|
||||
=encoding utf8 |
||||
|
||||
Lemonldap::NG::Portal::AuthNull - Perl extension for building Lemonldap::NG |
||||
compatible portals with no authentication. |
||||
|
||||
=head1 SYNOPSIS |
||||
|
||||
use Lemonldap::NG::Portal::SharedConf; |
||||
my $portal = new Lemonldap::NG::Portal::Simple( |
||||
configStorage => {...}, # See Lemonldap::NG::Portal |
||||
authentication => 'Null', |
||||
); |
||||
|
||||
if($portal->process()) { |
||||
# Write here the menu with CGI methods. This page is displayed ONLY IF |
||||
# the user was not redirected here. |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "..."; |
||||
|
||||
# or redirect the user to the menu |
||||
print $portal->redirect( -uri => 'https://portal/menu'); |
||||
} |
||||
else { |
||||
print $portal->header('text/html; charset=utf-8'); # DON'T FORGET THIS (see CGI(3)) |
||||
print "<html><body><h1>Unable to work</h1>"; |
||||
print "This server isn't well configured. Contact your administrator."; |
||||
print "</body></html>"; |
||||
} |
||||
|
||||
=head1 DESCRIPTION |
||||
|
||||
This library just overload few methods of Lemonldap::NG::Portal::Simple to |
||||
create sessions for anonymous users. |
||||
|
||||
See L<Lemonldap::NG::Portal::Simple> for usage and other methods. |
||||
|
||||
=head1 SEE ALSO |
||||
|
||||
L<Lemonldap::NG::Portal>, L<Lemonldap::NG::Portal::Simple>, |
||||
L<http://lemonldap-ng.org/> |
||||
|
||||
=head1 AUTHOR |
||||
|
||||
=over |
||||
|
||||
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=item Xavier Guimard, E<lt>x.guimard@free.frE<gt> |
||||
|
||||
=back |
||||
|
||||
=head1 BUG REPORT |
||||
|
||||
Use OW2 system to report bug or ask for features: |
||||
L<http://jira.ow2.org> |
||||
|
||||
=head1 DOWNLOAD |
||||
|
||||
Lemonldap::NG is available at |
||||
L<http://forge.objectweb.org/project/showfiles.php?group_id=274> |
||||
|
||||
=head1 COPYRIGHT AND LICENSE |
||||
|
||||
=over |
||||
|
||||
=item Copyright (C) 2010 by Xavier Guimard, E<lt>x.guimard@free.frE<gt> |
||||
|
||||
=item Copyright (C) 2010-2012 by Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> |
||||
|
||||
=back |
||||
|
||||
This library is free software; you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation; either version 2, or (at your option) |
||||
any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program. If not, see L<http://www.gnu.org/licenses/>. |
||||
|
||||
=cut |
||||
|
@ -1,28 +0,0 @@ |
||||
##@file |
||||
# AD user database backend file |
||||
|
||||
##@class |
||||
# AD user database backend class |
||||
package Lemonldap::NG::Portal::UserDBAD; |
||||
|
||||
use strict; |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
use base qw(Lemonldap::NG::Portal::UserDBLDAP); |
||||
|
||||
## @apmethod protected int formateFilter() |
||||
# Set the default LDAP filter for AD. |
||||
# By default, the user is searched in the LDAP server with sAMAccountName. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub formateFilter { |
||||
my $self = shift; |
||||
|
||||
$self->{AuthLDAPFilter} ||= '(&(sAMAccountName=$user)(objectClass=person))'; |
||||
$self->{mailLDAPFilter} ||= '(&(mail=$mail)(objectClass=person))'; |
||||
|
||||
return $self->SUPER::formateFilter; |
||||
} |
||||
|
||||
1; |
||||
|
@ -1,122 +0,0 @@ |
||||
## @file |
||||
# DBI userDB mechanism |
||||
|
||||
## @class |
||||
# DBI userDB mechanism class |
||||
package Lemonldap::NG::Portal::UserDBDBI; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
use Lemonldap::NG::Portal::_DBI; #inherits |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @apmethod int userDBInit() |
||||
# Set default values |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub userDBInit { |
||||
my $self = shift; |
||||
|
||||
# DBI access to user is the same as authentication by default |
||||
$self->{dbiUserChain} ||= $self->{dbiAuthChain}; |
||||
$self->{dbiUserUser} ||= $self->{dbiAuthUser}; |
||||
$self->{dbiUserPassword} ||= $self->{dbiAuthPassword}; |
||||
$self->{dbiUserTable} ||= $self->{dbiAuthTable}; |
||||
$self->{userPivot} ||= $self->{dbiAuthLoginCol}; |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int getUser() |
||||
# Do nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub getUser { |
||||
my $self = shift; |
||||
|
||||
# Connect |
||||
my $dbh = |
||||
$self->dbh( $self->{dbiUserChain}, $self->{dbiUserUser}, |
||||
$self->{dbiUserPassword} ); |
||||
return PE_ERROR unless $dbh; |
||||
|
||||
my $table = $self->{dbiUserTable}; |
||||
my $pivot = $self->{userPivot}; |
||||
my $user = $self->{user}; |
||||
|
||||
# If in mailProcess, adapt search criteriums |
||||
if ( $self->{mail} ) { |
||||
$pivot = $self->{dbiPasswordMailCol}; |
||||
$user = $self->{mail}; |
||||
} |
||||
|
||||
$user =~ s/'/''/g; |
||||
my $sth; |
||||
|
||||
eval { |
||||
$sth = $dbh->prepare("SELECT * FROM $table WHERE $pivot=?"); |
||||
$sth->execute($user); |
||||
}; |
||||
if ($@) { |
||||
$self->lmLog( "DBI error: $@", 'error' ); |
||||
return PE_ERROR; |
||||
} |
||||
|
||||
unless ( $self->{entry} = $sth->fetchrow_hashref() ) { |
||||
$self->_sub( 'userNotice', "User $user not found" ); |
||||
return PE_BADCREDENTIALS; |
||||
} |
||||
|
||||
# In mail process, get user value |
||||
if ( $self->{mail} ) { |
||||
$table = $self->{dbiAuthTable}; |
||||
$pivot = $self->{dbiAuthLoginCol}; |
||||
$user = $self->{entry}->{ $self->{userPivot} }; |
||||
eval { |
||||
$sth = $dbh->prepare("SELECT * FROM $table WHERE $pivot=?"); |
||||
$sth->execute($user); |
||||
}; |
||||
if ($@) { |
||||
$self->lmLog( "DBI error: $@", 'error' ); |
||||
return PE_ERROR; |
||||
} |
||||
|
||||
my $results; |
||||
|
||||
unless ( $results = $sth->fetchrow_hashref() ) { |
||||
$self->_sub( 'userNotice', "User $user not found" ); |
||||
return PE_BADCREDENTIALS; |
||||
} |
||||
|
||||
$self->{user} = $results->{$pivot}; |
||||
} |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setSessionInfo() |
||||
# Get columns for each exportedVars |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setSessionInfo { |
||||
my $self = shift; |
||||
|
||||
# Set _user unless already defined |
||||
$self->{sessionInfo}->{_user} ||= $self->{user}; |
||||
|
||||
my %vars = ( %{ $self->{exportedVars} }, %{ $self->{dbiExportedVars} } ); |
||||
while ( my ( $var, $attr ) = each %vars ) { |
||||
$self->{sessionInfo}->{$var} = $self->{entry}->{$attr} |
||||
if ( defined $self->{entry}->{$attr} ); |
||||
} |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setGroups() |
||||
# Do nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setGroups { |
||||
PE_OK; |
||||
} |
||||
|
||||
1; |
||||
|
@ -1,83 +0,0 @@ |
||||
## @file |
||||
# Demo userDB mechanism |
||||
|
||||
## @class |
||||
# Demo userDB mechanism class |
||||
package Lemonldap::NG::Portal::UserDBDemo; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @apmethod int userDBInit() |
||||
# Check AuthDemo use |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub userDBInit { |
||||
my $self = shift; |
||||
|
||||
if ( $self->get_module('auth') =~ /^Demo/ ) { |
||||
|
||||
# Call authInit if demo accounts not found |
||||
$self->authInit() unless defined $self->{_demoAccounts}; |
||||
|
||||
return PE_OK; |
||||
} |
||||
else { |
||||
$self->lmLog( "Use UserDBDemo only with AuthDemo", 'error' ); |
||||
return PE_ERROR; |
||||
} |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int getUser() |
||||
# Check known accounts |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub getUser { |
||||
my $self = shift; |
||||
|
||||
# Search by login |
||||
if ( $self->{user} ) { |
||||
return PE_OK |
||||
if ( defined $self->{_demoAccounts}->{ $self->{user} } ); |
||||
} |
||||
|
||||
# Search by mail |
||||
if ( $self->{mail} ) { |
||||
foreach my $user ( keys %{ $self->{_demoAccounts} } ) { |
||||
if ( $self->{_demoAccounts}->{$user}->{mail} eq $self->{mail} ) { |
||||
$self->{user} = $user; |
||||
return PE_OK; |
||||
} |
||||
} |
||||
} |
||||
|
||||
PE_USERNOTFOUND; |
||||
} |
||||
|
||||
## @apmethod int setSessionInfo() |
||||
# Get sample data |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setSessionInfo { |
||||
my $self = shift; |
||||
|
||||
my %vars = ( %{ $self->{exportedVars} }, %{ $self->{demoExportedVars} } ); |
||||
while ( my ( $k, $v ) = each %vars ) { |
||||
$self->{sessionInfo}->{$k} = |
||||
$self->{_demoAccounts}->{ $self->{user} }->{$v} |
||||
|| ""; |
||||
} |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setGroups() |
||||
# Do nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setGroups { |
||||
PE_OK; |
||||
} |
||||
|
||||
1; |
||||
|
@ -1,203 +0,0 @@ |
||||
##@file |
||||
# LDAP user database backend file |
||||
|
||||
##@class |
||||
# LDAP user database backend class |
||||
package Lemonldap::NG::Portal::UserDBLDAP; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
use Lemonldap::NG::Portal::_LDAP 'ldap'; #link protected ldap |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @method int userDBInit() |
||||
# Transform ldapGroupAttributeNameSearch in ARRAY ref |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub userDBInit { |
||||
my $self = shift; |
||||
|
||||
unless ( ref $self->{ldapGroupAttributeNameSearch} eq 'ARRAY' ) { |
||||
my @values = split( /\s/, $self->{ldapGroupAttributeNameSearch} ); |
||||
$self->{ldapGroupAttributeNameSearch} = \@values; |
||||
} |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int getUser() |
||||
# 7) Launch formateFilter() and search() |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub getUser { |
||||
my $self = shift; |
||||
return $self->_subProcess(qw(formateFilter search)); |
||||
} |
||||
|
||||
## @apmethod protected int formateFilter() |
||||
# Set the LDAP filter. |
||||
# By default, the user is searched in the LDAP server with its UID. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub formateFilter { |
||||
my $self = shift; |
||||
$self->{LDAPFilter} = |
||||
$self->{mail} |
||||
? $self->{mailLDAPFilter} |
||||
: $self->{AuthLDAPFilter} |
||||
|| $self->{LDAPFilter}; |
||||
if ( $self->{LDAPFilter} ) { |
||||
$self->lmLog( "LDAP submitted filter: " . $self->{LDAPFilter}, |
||||
'debug' ); |
||||
} |
||||
else { |
||||
$self->{LDAPFilter} = |
||||
$self->{mail} |
||||
? '(&(mail=$mail)(objectClass=inetOrgPerson))' |
||||
: '(&(uid=$user)(objectClass=inetOrgPerson))'; |
||||
} |
||||
$self->{LDAPFilter} =~ s/\$(user|_?password|mail)/$self->{$1}/g; |
||||
$self->{LDAPFilter} =~ s/\$(\w+)/$self->{sessionInfo}->{$1}/g; |
||||
$self->lmLog( "LDAP transformed filter: " . $self->{LDAPFilter}, 'debug' ); |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod protected int search() |
||||
# Search the LDAP DN of the user. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub search { |
||||
my $self = shift; |
||||
unless ( $self->ldap ) { |
||||
return PE_LDAPCONNECTFAILED; |
||||
} |
||||
my @attrs = ( |
||||
values %{ $self->{exportedVars} }, |
||||
values %{ $self->{ldapExportedVars} } |
||||
); |
||||
my $mesg = $self->ldap->search( |
||||
base => $self->{ldapBase}, |
||||
scope => 'sub', |
||||
filter => $self->{LDAPFilter}, |
||||
deref => $self->{ldapSearchDeref} || 'find', |
||||
attrs => \@attrs, |
||||
); |
||||
$self->lmLog( |
||||
'LDAP Search with base: ' |
||||
. $self->{ldapBase} |
||||
. ' and filter: ' |
||||
. $self->{LDAPFilter}, |
||||
'debug' |
||||
); |
||||
if ( $mesg->code() != 0 ) { |
||||
$self->lmLog( 'LDAP Search error: ' . $mesg->error, 'error' ); |
||||
$self->ldap->unbind; |
||||
$self->{flags}->{ldapActive} = 0; |
||||
return PE_LDAPERROR; |
||||
} |
||||
if ( $mesg->count() > 1 ) { |
||||
$self->lmLog( 'More than one entry returned by LDAP directory', |
||||
'error' ); |
||||
$self->ldap->unbind; |
||||
$self->{flags}->{ldapActive} = 0; |
||||
return PE_BADCREDENTIALS; |
||||
} |
||||
unless ( $self->{entry} = $mesg->entry(0) ) { |
||||
my $user = $self->{mail} || $self->{user}; |
||||
$self->_sub( 'userError', "$user was not found in LDAP directory" ); |
||||
$self->ldap->unbind; |
||||
$self->{flags}->{ldapActive} = 0; |
||||
return PE_BADCREDENTIALS; |
||||
} |
||||
$self->{dn} = $self->{entry}->dn(); |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setSessionInfo() |
||||
# 7) Load all parameters included in exportedVars parameter. |
||||
# Multi-value parameters are loaded in a single string with |
||||
# a separator (param multiValuesSeparator) |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setSessionInfo { |
||||
my $self = shift; |
||||
$self->{sessionInfo}->{dn} = $self->{dn}; |
||||
|
||||
my %vars = ( %{ $self->{exportedVars} }, %{ $self->{ldapExportedVars} } ); |
||||
while ( my ( $k, $v ) = each %vars ) { |
||||
$self->{sessionInfo}->{$k} = |
||||
$self->{ldap}->getLdapValue( $self->{entry}, $v ) |
||||
|| ""; |
||||
} |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setGroups() |
||||
# Load all groups in $groups. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setGroups { |
||||
my $self = shift; |
||||
my $groups = $self->{sessionInfo}->{groups}; |
||||
my $hGroups = $self->{sessionInfo}->{hGroups}; |
||||
|
||||
if ( $self->{ldapGroupBase} ) { |
||||
|
||||
# Push group attribute value for recursive search |
||||
push( |
||||
@{ $self->{ldapGroupAttributeNameSearch} }, |
||||
$self->{ldapGroupAttributeNameGroup} |
||||
) |
||||
if ( $self->{ldapGroupRecursive} |
||||
and $self->{ldapGroupAttributeNameGroup} ne "dn" ); |
||||
|
||||
# Get value for group search |
||||
my $group_value = |
||||
$self->{ldap} |
||||
->getLdapValue( $self->{entry}, $self->{ldapGroupAttributeNameUser} ); |
||||
|
||||
$self->lmLog( |
||||
"Searching LDAP groups in " |
||||
. $self->{ldapGroupBase} |
||||
. " for $group_value", |
||||
'debug' |
||||
); |
||||
|
||||
# Call searchGroups |
||||
my $ldapGroups = $self->{ldap}->searchGroups( |
||||
$self->{ldapGroupBase}, $self->{ldapGroupAttributeName}, |
||||
$group_value, $self->{ldapGroupAttributeNameSearch} |
||||
); |
||||
|
||||
foreach ( keys %$ldapGroups ) { |
||||
my $groupName = $_; |
||||
$hGroups->{$groupName} = $ldapGroups->{$groupName}; |
||||
my $groupValues = []; |
||||
foreach ( @{ $self->{ldapGroupAttributeNameSearch} } ) { |
||||
next if $_ =~ /^name$/; |
||||
my $firstValue = $ldapGroups->{$groupName}->{$_}->[0]; |
||||
push @$groupValues, $firstValue; |
||||
} |
||||
$groups .= |
||||
$self->{multiValuesSeparator} . join( '|', @$groupValues ); |
||||
} |
||||
|
||||
} |
||||
|
||||
$self->{sessionInfo}->{groups} = $groups; |
||||
$self->{sessionInfo}->{hGroups} = $hGroups; |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int userDBFinish() |
||||
# Unbind. |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub userDBFinish { |
||||
my $self = shift; |
||||
|
||||
if ( ref( $self->{ldap} ) && $self->{flags}->{ldapActive} ) { |
||||
$self->ldap->unbind(); |
||||
$self->{flags}->{ldapActive} = 0; |
||||
} |
||||
|
||||
PE_OK; |
||||
} |
||||
|
||||
1; |
||||
|
@ -1,42 +0,0 @@ |
||||
## @file |
||||
# Null userDB mechanism |
||||
|
||||
## @class |
||||
# Null userDB mechanism class |
||||
package Lemonldap::NG::Portal::UserDBNull; |
||||
|
||||
use strict; |
||||
use Lemonldap::NG::Portal::Simple; |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @apmethod int userDBInit() |
||||
# Do nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub userDBInit { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int getUser() |
||||
# Do nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub getUser { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setSessionInfo() |
||||
# Do nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setSessionInfo { |
||||
PE_OK; |
||||
} |
||||
|
||||
## @apmethod int setGroups() |
||||
# Do nothing |
||||
# @return Lemonldap::NG::Portal constant |
||||
sub setGroups { |
||||
PE_OK; |
||||
} |
||||
|
||||
1; |
||||
|
@ -1,30 +0,0 @@ |
||||
##@file |
||||
# Add LWP::UserAgent object |
||||
|
||||
##@class |
||||
# Add LWP::UserAgent object |
||||
package Lemonldap::NG::Portal::_Browser; |
||||
|
||||
use strict; |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
our $_ua; |
||||
|
||||
## @method LWP::UserAgent ua() |
||||
# @return LWP::UserAgent object |
||||
sub ua { |
||||
my $self = shift; |
||||
|
||||
return $_ua if ($_ua); |
||||
eval { require LWP::UserAgent; }; |
||||
$self->abort( 'LWP::UserAgent isn\'t installed', $@ ) if ($@); |
||||
|
||||
# TODO : LWP options to use a proxy for example |
||||
$_ua = LWP::UserAgent->new() or $self->abort($@); |
||||
push @{ $_ua->requests_redirectable }, 'POST'; |
||||
$_ua->env_proxy(); |
||||
return $_ua; |
||||
} |
||||
|
||||
1; |
||||
|
@ -1,164 +0,0 @@ |
||||
##@file |
||||
# DBI common functions |
||||
|
||||
##@class |
||||
# DBI common functions |
||||
package Lemonldap::NG::Portal::_DBI; |
||||
|
||||
use DBI; |
||||
use base qw(Exporter); |
||||
use Lemonldap::NG::Portal::Simple; |
||||
use strict; |
||||
|
||||
our @EXPORT = qw(dbh); |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
## @method protected Lemonldap::NG::Portal::_DBI dbh(string dbiChain, string dbiUser, string dbiPassword) |
||||
# Create connection to database |
||||
# @param dbiChain DBI connection chain |
||||
# @param dbiUser DBI connection user |
||||
# @param dbiPassword DBI connection password |
||||
# @return dbh object |
||||
sub dbh { |
||||
my $self = shift; |
||||
my $dbiChain = shift; |
||||
my $dbiUser = shift; |
||||
my $dbiPassword = shift; |
||||
my $dbh; |
||||
|
||||
# Open connection to database |
||||
eval { |
||||
$dbh = |
||||
DBI->connect_cached( $dbiChain, $dbiUser, $dbiPassword, |
||||
{ RaiseError => 1, }, |
||||
); |
||||
}; |
||||
if ($@) { |
||||
$self->lmLog( "DBI connection error: $@", 'error' ); |
||||
return 0; |
||||
} |
||||
|
||||
$self->{_dbh} = $dbh; |
||||
return $dbh; |
||||
} |
||||
|
||||
## @method protected Lemonldap::NG::Portal::_DBI hash_password(string password, string hash) |
||||
# Return hashed password for use in SQL statement |
||||
# @param password clear password |
||||
# @param hash hash mechanism |
||||
# @return SQL statement string |
||||
sub hash_password { |
||||
my $self = shift; |
||||
my $password = shift; |
||||
my $hash = shift; |
||||
|
||||
if ( $hash =~ /^(md5|sha|sha1|encrypt)$/i ) { |
||||
$self->lmLog( "Using " . uc($hash) . " to hash password", 'debug' ); |
||||
return uc($hash) . "($password)"; |
||||
} |
||||
else { |
||||
$self->lmLog( "No valid password hash, using clear text for password", |
||||
'warn' ); |
||||
return $password; |
||||
} |
||||
|
||||
} |
||||
|
||||
## @method protected Lemonldap::NG::Portal::_DBI hash_password_for_select(string password, string hash) |
||||
# Return hashed password for use in SQL SELECT statement |
||||
# Call hash_password unless encrypt hash is choosen |
||||
# @param password clear password |
||||
# @param hash hash mechanism |
||||
# @return SQL statement string |
||||
sub hash_password_for_select { |
||||
my $self = shift; |
||||
my $password = shift; |
||||
my $hash = shift; |
||||
my $passwordCol = $self->{dbiAuthPasswordCol}; |
||||
|
||||
if ( $hash =~ /^encrypt$/i ) { |
||||
return uc($hash) . "($password,$passwordCol)"; |
||||
} |
||||
else { |
||||
return $self->hash_password( $password, $hash ); |
||||
} |
||||
} |
||||
|
||||
## @method protected Lemonldap::NG::Portal::_DBI check_password(ref dbh, string user, string password) |
||||
# Verify user and password with SQL SELECT |
||||
# @param dbh database handle |
||||
# @param user user |
||||
# @param password password |
||||
# @return boolean result |
||||
sub check_password { |
||||
my $self = shift; |
||||
my $dbh = shift; |
||||
my $user = shift || $self->{user}; |
||||
my $password = shift || $self->{password}; |
||||
my $table = $self->{dbiAuthTable}; |
||||
my $loginCol = $self->{dbiAuthLoginCol}; |
||||
my $passwordCol = $self->{dbiAuthPasswordCol}; |
||||
|
||||
# Password hash |
||||
my $passwordsql = |
||||
$self->hash_password_for_select( "?", $self->{dbiAuthPasswordHash} ); |
||||
|
||||
my @rows = (); |
||||
eval { |
||||
my $sth = $dbh->prepare( |
||||
"SELECT $loginCol FROM $table WHERE $loginCol=? AND $passwordCol=$passwordsql" |
||||
); |
||||
$sth->execute( $user, $password ); |
||||
@rows = $sth->fetchrow_array(); |
||||
}; |
||||
if ($@) { |
||||
$self->lmLog( "DBI error: $@", 'error' ); |
||||
return 0; |
||||
} |
||||
|
||||
if ( @rows == 1 ) { |
||||
$self->lmLog( "One row returned by SQL query", 'debug' ); |
||||
return 1; |
||||
} |
||||
else { |
||||
$self->_sub( 'userError', "Bad password for $user" ); |
||||
return 0; |
||||
} |
||||
|
||||
} |
||||
|
||||
## @method protected Lemonldap::NG::Portal::_DBI modify_password(string user, string password, string userCol, string passwordCol) |
||||
# Modify password with SQL UPDATE |
||||
# @param user user |
||||
# @param password password |
||||
# @param userCol optional user column |
||||
# @param passwordCol optional password column |
||||
# @return boolean result |
||||
sub modify_password { |
||||
my $self = shift; |
||||
my $user = shift; |
||||
my $password = shift; |
||||
my $userCol = shift || $self->{dbiAuthLoginCol}; |
||||
my $passwordCol = shift || $self->{dbiAuthPasswordCol}; |
||||
|
||||
my $table = $self->{dbiAuthTable}; |
||||
|
||||
# Password hash |
||||
my $passwordsql = $self->hash_password( "?", $self->{dbiAuthPasswordHash} ); |
||||
|
||||
eval { |
||||
my $sth = |
||||
$self->{_dbh}->prepare( |
||||
"UPDATE $table SET $passwordCol=$passwordsql WHERE $userCol=?"); |
||||
$sth->execute( $password, $user ); |
||||
}; |
||||
if ($@) { |
||||
$self->lmLog( "DBI password modification error: $@", 'error' ); |
||||
return 0; |
||||
} |
||||
|
||||
return 1; |
||||
} |
||||
|
||||
1; |
Loading…
Reference in new issue