Possibility to autoconfigure LDAP notification backend from LDAP configuration backend (#457)

This commit is contained in:
Clément Oudot 2013-10-22 16:26:20 +00:00
parent 625ae5ece0
commit 3106100c5d
4 changed files with 17 additions and 53 deletions

View File

@ -35,7 +35,7 @@ sub new {
unless ( $self->{type} =~ /::/ );
eval "require $self->{type}";
if ($@) {
$msg = "Error: unknown storage type $type";
$msg = "Error: unknown storage type $type ($@)";
return 0;
}
unless ( $self->_prereq ) {

View File

@ -4,40 +4,6 @@
## @class
# LDAP storage methods for notifications
# Use case: copy and adapt the following lines into lemonldap-ng.ini
#
# [Portal]
#
# notification = 1
# notificationStorage = LDAP
# notificationStorageOptions = { \
# 'ldapServer' => 'ldap://directory.com:389',\
# 'ldapBindDN' => 'cn=lemonldap,ou=people,dc=directory,dc=com',\
# 'ldapBindPassword' => 'secret',\
# 'notifBase' => 'ou=notifications,ou=websso,dc=directory,dc=com',\
# 'notificationWildcard' => 'allusers',\
# 'fileNameSeparator' => '_',\
# }
#
# [...]
#
# [Manager]
#
# notificationStorage = LDAP
# notificationStorageOptions = { \
# 'ldapServer' => 'ldap://directory.com:389',\
# 'ldapBindDN' => 'cn=lemonldap,ou=people,dc=directory,dc=com',\
# 'ldapBindPassword' => 'secret',\
# 'notifBase' => 'ou=notifications,ou=websso,dc=directory,dc=com',\
# 'notificationWildcard' => 'allusers',\
# 'fileNameSeparator' => '_',\
# }
#
#
# possible other notificationStorageOptions are:
# caFile, caPath, ldapPort
# notifBase can be replaced by ldapConfBase
package Lemonldap::NG::Common::Notification::LDAP;
use strict;
@ -46,19 +12,13 @@ use MIME::Base64;
use Net::LDAP;
use utf8;
our $VERSION = '1.0.0';
our $VERSION = '1.3.0';
## @method boolean prereq()
# Check if LDAP parameters are set.
# @return true if all is OK
sub prereq {
my $self = shift;
if ( $self->{notifBase} ) {
$self->{ldapConfBase} = $self->{notifBase};
}
else {
$self->{ldapConfBase} =~ s/[^,]+,/ou=notifications,/;
}
unless ( $self->{ldapServer} ) {
$self->lmLog( '"ldapServer" is required in LDAP notification type',
'error' );
@ -66,6 +26,10 @@ sub prereq {
'"ldapServer" is required in LDAP notification type';
return 0;
}
if ( $self->{table} ) {
$self->{ldapConfBase} =~ s/^\w+=\w+(,.*)$/ou=$self->{table}$1/;
}
$self->lmLog( 'Warning: "ldapBindDN" parameter is not set', 'warn' )
unless ( $self->{ldapBindDN} );
1;
@ -153,7 +117,7 @@ sub delete {
$ts[4]++;
return _modify(
$self,
'(&(objectClass=applicationProcess)(description={uid}'
'(&(objectClass=applicationProcess)(description={uid}'
. $u
. ')(description={ref}'
. $r
@ -181,7 +145,7 @@ sub purge {
my $clause;
$clause = '(description={done}*)' unless ($force);
return _delete( $self,
'(&(objectClass=applicationProcess)(description={uid}'
'(&(objectClass=applicationProcess)(description={uid}'
. $u
. ')(description={ref}'
. $r

View File

@ -81,7 +81,7 @@ sub new {
# Else use the configuration backend
else {
(%$tmp) = ( %{ $self->{lmConf} } );
(%$tmp) = ( %{ $conf } );
$class->abort( "notificationStorage not defined",
"This parameter is required to use notification system" )
unless ( ref($tmp) );
@ -91,8 +91,8 @@ sub new {
$tmp->{type} =~ s/(CBDI|RDBI)/DBI/; # CDBI/RDBI are DBI
# If type not File or DBI, abort
$class->abort("Only File or DBI supported for Notifications")
unless $tmp->{type} =~ /^(File|DBI)$/;
$class->abort("Only File, DBI or LDAP supported for Notifications")
unless $tmp->{type} =~ /^(File|DBI|LDAP)$/;
# Force table name
$tmp->{table} = 'notifications';

View File

@ -433,9 +433,9 @@ sub new {
$tmp->{type} =~ s/.*:://;
$tmp->{type} =~ s/(CDBI|RDBI)/DBI/; # CDBI/RDBI are DBI
# If type not File or DBI, abort
$self->abort("Only File or DBI supported for Notifications")
unless $tmp->{type} =~ /^(File|DBI)$/;
# If type not File, DBI or LDAP, abort
$self->abort("Only File, DBI or LDAP supported for Notifications")
unless $tmp->{type} =~ /^(File|DBI|LDAP)$/;
# Force table name
$tmp->{table} = 'notifications';
@ -762,9 +762,9 @@ sub buildHiddenForm {
# Build hidden input HTML code
$val .=
'<input type="hidden" name="'
. $_
. '" id="'
'<input type="hidden" name="'
. $_
. '" id="'
. $_
. '" value="'
. $self->{portalHiddenFormValues}->{$_} . '" />';