Would this also ensure that when LDAP finds the matching email in RT's users, it'll update the other info to what LDAP has?(essentially overwriting the email address as username that was set when a non-user emails RT)<br>
<br>
<div class="gmail_quote">On Thu, Jul 29, 2010 at 9:46 AM, Kenneth Marshall <span dir="ltr"><<a href="mailto:ktm@rice.edu">ktm@rice.edu</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div></div>
<div class="h5">On Thu, Jul 29, 2010 at 09:36:33AM -0400, Mike Johnson wrote:<br>> Greetings all,<br>><br>> Has anyone that is using ExternalAuth developed a workaround for the "new<br>> user" creation issue with ExternalAuth?<br>
><br>> The issue was outlined in another rt-user message(I can't seem to find<br>> now). It relates to when non-privleged users are created through the<br>> creation of a ticket from an email, and then they login using LDAP. The<br>
> email generates a user with username and email address as their email<br>> address. ExternalAuth throws an error when it attempts to create the new<br>> user, as a user already exists with the same email address.<br>
><br>> I need ExternalAuth to find the user that has the same email address, and<br>> change that user's info to the info it grabs from LDAP.<br>><br>> If I was a perl programmer, I'd figure out how to customize it myself, but<br>
> unfortunately, I'm just stepping into that world... most perl stuff i use,<br>> I've "borrowed" from the web :P<br>> Has anyone developed a workaround?<br>><br>> The only thing I can think of, is taking all LDAP users, and loading them<br>
> into RT with their info, and everytime a new user is created in LDAP, they<br>> get created in RT... but that seems like a fair amount of work....<br>><br>> Thanks!<br>><br>> --<br>> Mike Johnson<br>
> Datatel Programmer/Analyst<br>> Northern Ontario School of Medicine<br>> 955 Oliver Road<br>> Thunder Bay, ON P7B 5E1<br>> Phone: (807) 766-7331<br>> Email: <a href="mailto:mike.johnson@nosm.ca">mike.johnson@nosm.ca</a><br>
<br><br></div></div>Hi Mike,<br><br>We use a customized version of the CanonicalizeEmailAddress() function<br>which looks up the E-mail address in the LDAP directory and maps it to<br>their primary E-mail address before creating the account. Then it does<br>
not conflict with the ExternalAuth process which will then pull the<br>same information. Here is our version which should give you some ideas:<br><br><br>sub CanonicalizeEmailAddress {<br> my $self = shift;<br> my $email = shift;<br>
<br> # Leave some addresses intact<br> if ( $email =~ /[\w-]+\@<a href="http://mysafe1.rice.edu/" target="_blank">mysafe1.rice.edu</a>$/ ) {<br> return ($email);<br> }<br> if ( $email =~ /[\w-]+\@<a href="http://mysafe2.rice.edu/" target="_blank">mysafe2.rice.edu</a>$/ ) {<br>
return ($email);<br> }<br><br> # Example: the following rule would treat all email<br> # coming from a subdomain as coming from second level domain<br> # <a href="http://foo.com/" target="_blank">foo.com</a><br>
if ( my $match = RT->Config->Get('CanonicalizeEmailAddressMatch') and<br> my $replace = RT->Config->Get('CanonicalizeEmailAddressReplace') )<br> {<br> $email =~ s/$match/$replace/gi;<br>
}<br> $email .= '@<a href="http://rice.edu/" target="_blank">rice.edu</a>' if ($email =~ /^[\w-]+$/);<br><br> #<br> # Now we should have an Email address that is of the form <a href="mailto:addr@rice.edu">addr@rice.edu</a><br>
# Use LDAP to map this to the primary vanity Email alias.<br><br> my $params = ( Name => undef,<br> EmailAddress => undef);<br><br> my $ldap = new Net::LDAP($RT::LdapServer)<br> or $RT::Logger->critical("CanonicalizeEmailAddress: Cannot connect to LDAP\n"),<br>
return ($email);<br><br> my $mesg = $ldap->bind();<br><br> if ($mesg->code != LDAP_SUCCESS) {<br> $RT::Logger->critical("CanonicalizeEmailAddress: Unable to bind to $RT::LdapServer: ",<br>
ldap_error_name($mesg->code), "\n");<br><br> return ($email);<br> }<br><br> # First check to see if the E-mail address uniquely characterizes the<br> # user. If so, update the information with the LDAP query results.<br>
my $filter = "(mailAlternateAddress=$email)";<br> $mesg = $ldap->search(base => $RT::LdapBase,<br> filter => $filter,<br> attrs => [ $RT::LdapMailAttr ]);<br>
<br> if ($mesg->code != LDAP_SUCCESS and $mesg->code != LDAP_PARTIAL_RESULTS) {<br> $RT::Logger->critical("Unable to search in LDAP: ", ldap_error_name($mesg->code), "\n");<br><br> return ($email);<br>
}<br><br> # The search succeeded with just one match<br> if ($mesg->count == 1) {<br> $email = ($mesg->first_entry->get_value($RT::LdapMailAttr))[0];<br> }<br><br> $mesg = $ldap->unbind();<br> if ($mesg->code != LDAP_SUCCESS) {<br>
$RT::Logger->critical("Could not unbind from LDAP: ", ldap_error_name($mesg->code), "\n");<br><br> }<br> undef $ldap;<br> undef $mesg;<br> return ($email);<br>}<br><br><br>You will also need these somewhere ahead of there use:<br>
<br>use Net::LDAP;<br>use Net::LDAP::Constant qw(LDAP_SUCCESS LDAP_PARTIAL_RESULTS);<br>use Net::LDAP::Util qw (ldap_error_name);<br>use Net::LDAP::Filter;<br><br>We have them at the top under "use strict".<br><br>
Cheers,<br>Ken<br></blockquote></div><br><br clear="all"><br>-- <br>Mike Johnson<br>Datatel Programmer/Analyst<br>Northern Ontario School of Medicine<br>955 Oliver Road<br>Thunder Bay, ON P7B 5E1<br>Phone: (807) 766-7331<br>
Email: <a href="mailto:mike.johnson@nosm.ca">mike.johnson@nosm.ca</a><br>