WordPress.org

Ready to get started?Download WordPress

Forums

Simple LDAP Login
[resolved] Open LDAP authentication with non-RDN attribute (1 post)

  1. jschmock
    Member
    Posted 2 years ago #

    Hi Clif,

    if you need to authenicate against OpenLDAP and some other LDAPs the RDN is often not costructed from the attribute you are asking for in the ADdmin dialogue. In our case the RDN is made from the cn while we still want to search in the LDAP for a UID which matches, e.g.

    ldapsearch ( host = 'yourhost',
    searchbase = 'cn=Users,dc=My, dc=org',
    filter = '(uid = $UID_TO_SEARCH)',
    scope = 'base');

    I have extended your code in the following way so that it would generally work with your strategy:

    function sll_is_in_group($username)
    {
            global $ldap, $adldap;
            $result = false;
    
            switch(get_option('simpleldap_directory_type'))
            {
                    case "directory_ad":
                            $result = $adldap->user_ingroup($username,get_option('simpleldap_group'));
                    break;
    
                    case "directory_ol":
                            if($ldap == null) {return false;}
                            $result = ldap_search($ldap, get_option('simpleldap_group_suffix'), '(' . get_option('simpleldap_group_member_attribute') . '=' . $username . ')', array('cn'));
                            $ldapgroups = ldap_get_entries($ldap, $result);
    
                            //Ok, we should have the user, all the info, including which groups he is a member of.
                            //Now let's make sure he's in the right group before proceeding.
                            $groups = array();
                            for ($i=0; $i<$ldapgroups['count']; $i++) {
                                    $groups[] .= $ldapgroups[$i]['cn'][0];
                            }
                            $result = in_array(get_option('simpleldap_group'),$groups);
                    break;
            }
            return $result;
    }

    I have tested this code with various setups. Perhaps you might want to add it into your code base.

    Cheers,

    John

    http://wordpress.org/extend/plugins/simple-ldap-login/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic