From 3106100c5d2c569e30d2c69610e197eb495473f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudot?= Date: Tue, 22 Oct 2013 16:26:20 +0000 Subject: [PATCH] Possibility to autoconfigure LDAP notification backend from LDAP configuration backend (#457) --- .../lib/Lemonldap/NG/Common/Notification.pm | 2 +- .../Lemonldap/NG/Common/Notification/LDAP.pm | 50 +++---------------- .../lib/Lemonldap/NG/Manager/Notifications.pm | 6 +-- .../lib/Lemonldap/NG/Portal/Simple.pm | 12 ++--- 4 files changed, 17 insertions(+), 53 deletions(-) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification.pm index 492e2f661..c9730fc42 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification.pm @@ -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 ) { diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification/LDAP.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification/LDAP.pm index d9e91f676..20eb0eaf6 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification/LDAP.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notification/LDAP.pm @@ -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 diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm index c0f34c154..a45e99386 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm @@ -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'; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm index e8ffe6982..8112ff5b5 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm @@ -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 .= - '';