From d7d7d7af5b11ffe493c27666efc79d92ddc56f6d Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sat, 6 Dec 2014 04:26:42 +0100 Subject: Kernel::System::Auth::Sync::LDAP: add fix for complex mappings We need a complex mapping for LDAP Sync, because the required fields does not appear as single fileds in LDAP. No you could set a sub ref as SyncMap in the configuration, that gets the LDAP Entry and sould return the poppulated user object. --- Kernel/System/Auth/Sync/LDAP.pm | 79 ++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/Kernel/System/Auth/Sync/LDAP.pm b/Kernel/System/Auth/Sync/LDAP.pm index 3c2632d..5f83068 100644 --- a/Kernel/System/Auth/Sync/LDAP.pm +++ b/Kernel/System/Auth/Sync/LDAP.pm @@ -223,48 +223,53 @@ sub Sync { # get whole user dn my %SyncUser; for my $Entry ( $Result->all_entries() ) { - for my $Key ( sort keys %{$UserSyncMap} ) { - - # detect old config setting - if ( $Key =~ m{ \A (?: Firstname | Lastname | Email ) }xms ) { - $Key = 'User' . $Key; - $Kernel::OM->Get('Kernel::System::Log')->Log( - Priority => 'error', - Message => 'Old config setting detected, please use the new one ' - . 'from Kernel/Config/Defaults.pm (User* has been added!).', - ); - } + if (ref $UserSyncMap eq 'CODE') { + %SyncUser = $UserSyncMap->($Entry); + } + else { + for my $Key ( sort keys %{$UserSyncMap} ) { + + # detect old config setting + if ( $Key =~ m{ \A (?: Firstname | Lastname | Email ) }xms ) { + $Key = 'User' . $Key; + $Kernel::OM->Get('Kernel::System::Log')->Log( + Priority => 'error', + Message => 'Old config setting detected, please use the new one ' + . 'from Kernel/Config/Defaults.pm (User* has been added!).', + ); + } - my $AttributeNames = $UserSyncMap->{$Key}; - if ( ref $AttributeNames ne 'ARRAY' ) { - $AttributeNames = [$AttributeNames]; - } - ATTRIBUTE_NAME: - for my $AttributeName ( @{$AttributeNames} ) { - if ( $AttributeName =~ /^_/ ) { - $SyncUser{$Key} = substr( $AttributeName, 1 ); - last ATTRIBUTE_NAME; + my $AttributeNames = $UserSyncMap->{$Key}; + if ( ref $AttributeNames ne 'ARRAY' ) { + $AttributeNames = [$AttributeNames]; } - elsif ( $Entry->get_value($AttributeName) ) { - $SyncUser{$Key} = $Entry->get_value($AttributeName); - last ATTRIBUTE_NAME; + ATTRIBUTE_NAME: + for my $AttributeName ( @{$AttributeNames} ) { + if ( $AttributeName =~ /^_/ ) { + $SyncUser{$Key} = substr( $AttributeName, 1 ); + last ATTRIBUTE_NAME; + } + elsif ( $Entry->get_value($AttributeName) ) { + $SyncUser{$Key} = $Entry->get_value($AttributeName); + last ATTRIBUTE_NAME; + } } - } - # e. g. set utf-8 flag - $SyncUser{$Key} = $Self->_ConvertFrom( - $SyncUser{$Key}, - 'utf-8', - ); - } - if ( $Entry->get_value('userPassword') ) { - $SyncUser{UserPw} = $Entry->get_value('userPassword'); + # e. g. set utf-8 flag + $SyncUser{$Key} = $Self->_ConvertFrom( + $SyncUser{$Key}, + 'utf-8', + ); + } + if ( $Entry->get_value('userPassword') ) { + $SyncUser{UserPw} = $Entry->get_value('userPassword'); - # e. g. set utf-8 flag - $SyncUser{UserPw} = $Self->_ConvertFrom( - $SyncUser{UserPw}, - 'utf-8', - ); + # e. g. set utf-8 flag + $SyncUser{UserPw} = $Self->_ConvertFrom( + $SyncUser{UserPw}, + 'utf-8', + ); + } } } -- cgit v1.2.3-1-g7c22