1
rlankford
LDAP Authentication Field Mapping
  • 2007/2/7 14:22

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


I have to say, I love the fact that XOOPS now has LDAP built in with no more hacking! Thanks for this great feature! This morning, I've finally gotten around to mapping various LDAP fields to various columns in the xoops_users table. This is a great feature! I was able to make up some new fields fairly easily by altering the translations for the various instant messenger fields (you know, user_yim becomes "Phone Number", that kind of thing). We have a 'standard' instant messenger here at work, so these weren't needed anyway.

Enough of the long story though (sorry). I've made all these changes, and they work fine. BUT (there has to be one, doesn't there?), the fields won't be populated with all this good information until each and every user logs into the website again. It would be nice if XOOPS would ask you to repopulate all the fields again whenever a change is made to:

Site Preferences -> Authentication Options -> Server Fields Mapping

This way, you'd get the benefits immediately for people who rely on this information. As it stands, I'll probably spend a few minutes this morning writing a stand-alone script to loop through all the users and do this -- but a core addition would be perfect for new users in the future!

Thanks for listening/reading and keep up the awesome Xoopsing (yeah that's not a word, but I'm in a good mood this morning ).

2
rlankford
Re: LDAP Authentication Field Mapping
  • 2007/2/7 21:20

  • rlankford

  • Not too shy to talk

  • Posts: 158

  • Since: 2004/8/27


I wrote a little script up to migrate all the data over. It's really rough (some things filled in by hand) and it relies on a temporary change to the core in order to run. It's possible that someone else might find it useful, so I'm including it here.

Create a file called LDAP_MapFields.php and place it in your root XOOPS directory. It should contain the following code:

        include "mainfile.php";
    include 
'header.php';
        include_once 
XOOPS_ROOT_PATH.'/class/auth/authfactory.php';
        include_once 
XOOPS_ROOT_PATH.'/class/auth/auth_provisionning.php';
        include_once 
XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/auth.php';

    
$member_handler =& xoops_gethandler('member');
    
$criteria = new Criteria('uid');
    
$members $member_handler->getUsers($criteria);
    
$count count($members);
    
$ldapConnection ldap_connect("**directory.whatever.com**"'**389**') or die("Cound not connect");
    
$ldapBind ldap_bind($ldapConnection);
    
        echo 
"User Count: " $count "";    
        
    
$tab_mapping explode('|'"**enter the value that you use in Site Preferences -> Authentication Options -> Field Mappings**");
    
$xoopsAuth =& XoopsAuthFactory::getAuthConnection('**I manually entered a user name (mine) here**');
    
$authProv = new XoopsAuthProvisionning($xoopsAuth);

        foreach (
$members as $member) {
              
$dn "uid=" $member->getVar('uname') . "** the rest of your base dn goes here**";
            
$sr ldap_read($ldapConnection$dn'(objectclass=*)');
              
$entries ldap_get_entries($ldapConnection$sr);        

        foreach (
$tab_mapping as $mapping) {
                    
$fields explode('='trim($mapping));
                    if (
$fields[0] && $fields[1]) {
                        echo 
"setVar(" trim($fields[0]) . " for user " $member->getVar("uname") . ": " $entries["0"][trim($fields[1])]["0"] . ")";
                        
$member->setVar(trim($fields[0]), $entries["0"][trim($fields[1])]["0"]);
                    }
                }

                if (
$member_handler->insertUser($member,true)) {
               echo 
$member->getVar("uid") . "=good";
        } else {
            echo 
$member->getVar("uid") . "=BAD";
        }
        }
        include 
'footer.php';
?>


Look for code that contains ** and replace it with values appropriate to your web site.

Now the final trick. Edit kernel\user.php and comment out the lines that return from the function prematurely between lines 510 and 520:
function insert(&$user$force false)
    {
        if (
strtolower(get_class($user)) != 'xoopsuser') {
            
//return false;
        
}
        if (!
$user->isDirty()) {
            
//return true;
        
}
        if (!
$user->cleanVars()) {
            
//return false;
        
}
        foreach (
$user->cleanVars as $k => $v) {
            ${
$k} = $v;
        }


Now run the LDAP_MapFields.php file from your browser. Once that's complete, remove the comments in user.php from above.

Your user fields for all users should now be filled with data from your LDAP directory without having to wait for everyone to log in again.

Login

Who's Online

322 user(s) are online (235 user(s) are browsing Support Forums)


Members: 0


Guests: 322


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits