Closed (fixed)
Project:
LDAP integration
Version:
5.x-1.1
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Feb 2007 at 17:36 UTC
Updated:
9 Apr 2008 at 17:44 UTC
For my blog, I want users to log in with their active directory username, but I want their names to always show up as the displayName. A simple hack I've used for quite some time is to swap the username for the displayName immediately after authentication. This seemed simpler than hacking all the other modules to use a different name attribute. Patch is attached.
| Comment | File | Size | Author |
|---|---|---|---|
| ldapauth-displayName.patch | 570 bytes | 2root4u |
Comments
Comment #1
kreaper commentedCurrently I am not planning on taking on this change. We'll have to go thru the code and ensure that it works across all directory servers and situations.
Comment #2
scafmac commentedTheme_username() is probably the best place to put any changes like that. Since it is part of the theming layer, it should be pretty stable with other modules.
For this example below, I started with a copy of the theme_username() function from the CVS. Then I added one line of code, and 1 find & replace. If you are not familiar with the theme hooks, your adultered copy belong in the template file of your theme. Change the name replaceing <theme_name> with your theme's name. You might want to change the name truncation. And if your admin account (uid=1) doesn't have a profile_displayName, then any posts will appear to come from Anonymous.
Comment #3
scafmac commentedI forgot to mention that I setup a field in admin/user/profile titled profile_displayName. Then under admin/settings/ldapdata/edit/<ldap_server> I associated profile_displayName with the LDAP attribute displayName. Also you need to set the radio box to readonly or read/write access.
Since the profile module is required, IMO it is better to use profile fields rather than the other option in ldapdata. And being able to use profile_load_profile() is a perfect example of why it is better.
Comment #4
norelpref commentedI've got this module working and I'm stoked about that. However, people are accustomed to logging in around these parts with their user ID (uid) which is an eight character, arbitrary alphanumeric string. So, when someone logs into the CMS I'm building, they see, e.g., "AH129736" as their username. This sucks. I want them to see their "cn" or common name instead. I've scoured the forums around here and no one has supplied (at least for me, who am php challenged) an easy solution. It seems like it would be a no-brainer, but I have no idea where in the Drupal code I'd implement the fix. Interestingly, when a user clicks to see their profile, they see all the pertinent LDAP attributes displayed, like Full Name, short name, etc. It should be easy to display the common name througout their login sessions. In asp I'd just write something like "You are logged in as<%username%>"
So I want to have the user's cn displayed instead of the ui, which they have to login with. Why is this such a pain?
Comment #5
scafmac commentedYou're using a complicated CMS framework that provides for that sort of customization, just not with one line of code. Take it or leave it.
So no one has supplied an answer? Funny I thought that's what the second post was, PHP newbie friendly & all. If you are not interested in learning more about hooks & php - the little you would need to learn considering I spelled out the solution above, engage a consultant. I am available.
Or if you prefer to complain, switch to something in ASP or pay the $10k for a commercial CMS. No one's holding your feet to the fire.
Good luck.
Comment #6
aclight commentedYou should also check out this similar issue: http://drupal.org/node/46237
AC
Comment #7
norelpref commentedI don't know where in my post I was "complaining". But I'll go ahead and try again to implement solution #2 and see what happens.
I have nothing but praise for Drupal and the site I'm developing is awesome because of it. I just think that something as intuitively simple as displaying a specific LDAP attribute as the username display might be an option in the LDAP module. From other posts I've seen in the forums, I'm not alone in this idea.
I didn't mean to diss or dissmiss solution #2. I appeciate the author for providing it. And I will take another crack at implementing it this morning.
Comment #8
scafmac commentedPlease accept my apologies norelpref. I saw no indication that you had tried the solution and I got a little soured at
But it's easy to misunderstand intent, so let's figure out a solution instead...
You said you tried it? What happened / how far did you get?
More tips/clarifications:
I think that covers practically everything. Let me know how it goes.
Comment #9
scafmac commentedWhoops...
Previously mentioned code at bottom of post #8 should actually be:
}
>> else if($object->uid == 1) {
>> $name = $object->name // or ( 'admin', 'god', etc...);
>> }
else if ($object->name) {
Comment #10
norelpref commentedI was able to successfully implement the solution detailed in this thread. Thanks!
Comment #11
g011um commentedI'd like to point out that this does not change the display in all cases (because some modules don't use the theme functions). See the discussion pointed out by aclight above, especially the comments starting around #17. It's an excellent starting place though, and this (of course) works for non-LDAP implementations as well, as long as there's some sort of display name field setup.
Comment #12
scafmac commentedComment #13
eevul commentedI am running Drupal 5.7 with LDAP authentication and the Marinelli theme and this worked nicely. Thanks for the work on this.