Subject: | LDAPImport - add convert rule (synchronizing users disabled in AD) |
Date: | Mon, 04 Jun 2012 15:37:05 +0200 |
To: | <bug-RT-Extension-LDAPImport [...] rt.cpan.org> |
From: | RafaĆ Matera <rafal [...] matera.pl> |
I was wondering how to import RT User's Disabled field from Windows
Active Directory using LDAP import.
One missing thing was, how to execute the code to convert value form AD
field userAccountControl.
In fact I needed to extract second bit from that field and put result
into User->Disabled
So I added new config option $LDAPConvert:
Set($LDAPMapping, {'Name' => 'sAMAccountName',
'EmailAddress' => 'mail',
...
'Disabled' => 'userAccountControl',
...
});
Set($LDAPConvert, {
'Disabled' => sub { ($_[0] & 2) / 2 }
});
And also 1 line of code executing this conversion:
--- LDAPImport.pm.orig 2012-03-15 15:53:14.000000000 +0100
+++ LDAPImport.pm 2012-03-16 10:13:51.406609924 +0100
@@ -283,6 +283,8 @@
push @values, scalar
$args{ldap_entry}->get_value($attribute);
}
$object->{$rtfield} = join(' ',grep {defined} @values);
+ $object->{$rtfield} =
($RT::LDAPConvert->{$rtfield})->($object->{$rtfield})
+ if (defined($RT::LDAPConvert->{$rtfield}) &&
ref($RT::LDAPConvert->{$rtfield}) eq 'CODE');
}
return $object;
This code refers to RT-Extension-LDAPImport-0.31
Maybe it is interesting enough for you to include in next release :-)
BR
Rafal