简体   繁体   English

具有LDAP身份验证的Codeigniter应用程序

[英]Codeigniter Application with LDAP Authentication

Without codeigniter i am able to use ldap_connect() but in the codeigniter project i want to use ldap connection for authenticating user with their windows username and password. 没有codeigniter,我可以使用ldap_connect(),但是在codeigniter项目中,我想使用ldap连接来通过Windows用户名和密码对用户进行身份验证。 Below is the code which is working perfect without codeigniter. 下面是没有codeigniter的完美代码。

/******LDAP CONNECTIVITY STARTS HERE*********/
$ldaprdn = $_POST['uname']; // ldap rdn or dn
    $ldappass = $_POST['upass']; // associated password
    $ldaprdn = $_POST['uname'].'@domain.com';
    $ldapconn = ldap_connect("ip") or die("Could not connect to LDAP server."); //our ip
if ($ldapconn) {
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
        // verify binding
        if ($ldapbind) {
            //echo "<pre>";
            //print_r($row_login);
            //exit;

            $_SESSION['appusername']=$_POST['uname'];
            $_SESSION['emp_code']=$row_login['emp_code'];
            $_SESSION['emp_id']=$row_login['emp_id'];
            $_SESSION['emp_name']=$row_login['emp_name'];
            $_SESSION['emp_email']=$row_login['emp_email'];
            $_SESSION['emp_dept_id']=$row_login['emp_dept_id'];
            $_SESSION['emp_dept_name']=$row_login['dept_name'];
            $_SESSION['emp_group']=$row_login['emp_group'];
            $_SESSION['emp_category']=$row_login['emp_category'];

            $_SESSION['finance_app_authority']=$row_login['finance_approval_status'];
            $_SESSION['line_eng_status']=$row_login['line_eng_status'];

            $_SESSION['line_name']=$row_login['line_name'];
            $_SESSION['dept_name']=$row_login['dept_name'];

            if($row_login['emp_mod_status']=='Y'){ //if moderator means
                $_SESSION['userType']='MOD';
            }
            else if($row_login['emp_id']==$row_login['dept_hod_id']){ //if HOD means
                $_SESSION['userType']='HOD';
            }else{ //if normal user means
                $_SESSION['userType']='EMP';
            }
            echo '<script language="javascript">document.location.href="?p=main&m=it-home"</script>';
            exit;

        }
        else{
        echo '<div  class="man_style" style="width:50%;padding:10px 10px 10px 250px !important;text-align:center;color:red;">Invalid password.</div>';
        }
    }

All i want is to authenticate user by windows username and password in codeigniter. 我想要的只是通过Windows Windows用户名和密码在Codeigniter中对用户进行身份验证。 Suggest me a very simple way please. 请给我一个非常简单的方法。

I tried Auth_Ldap library but still i am getting an error 我尝试了Auth_Ldap库,但仍然出现错误

LDAP functionality not present. LDAP功能不存在。 Either load the module ldap php module or use a php with ldap support compiled in. 加载模块ldap php模块或使用已编译了ldap支持的php。

I have used Auth_Ldap library file. 我使用了Auth_Ldap库文件。 the following config file Don't know where to give my host ip address 以下配置文件不知道在哪里提供我的主机IP地址

$config['account_suffix']       = '@abcd.com';
$config['base_dn']              = 'DC=domain,DC=local';
$config['domain_controllers']   = array ("server1.domain.local");
$config['ad_username']          = 'administrator';
$config['ad_password']          = 'password';
$config['real_primarygroup']    = true;
$config['use_ssl']              = false;
$config['use_tls']              = false;
$config['recursive_groups']     = true;


/* End of file adldap.php */
/* Location: ./system/application/config/adldap.php */

Your help is appreciated 感谢您的帮助

I did not find the library you want to use (Auth_Ldap), but I found Auth_Ldap . 我没有找到要使用的库(Auth_Ldap),但是我找到了Auth_Ldap Your config files differ, however. 但是,您的配置文件有所不同。 I downloaded the file and in this config you clearly got the ldap_uri, so that would be where your host ip goes I guess. 我下载了文件,在此配置中,您显然获得了ldap_uri,所以我想那就是您的主机IP所在的位置。

$config['ldap_uri'] = array('ldap://ldap.mycompany.com:389/');
// $config ['ldap_uri'] = array('ldaps://ldap.mycompany.com:636/');  <-- connect via SSL
$config['use_tls'] = true; // Encrypted without using SSL
$config['search_base'] = 'dc=mycompany,dc=com';
$config['user_search_base'] = array('ou=people,dc=mycompany,dc=com');  // Leave empty to use $config['search_base']
$config['group_search_base'] = array('ou=group,dc=mycompany,dc=com');  // Leave empty to use $config['search_base']
$config['user_object_class'] = 'posixAccount';
$config['group_object_class'] = 'posixGroup';
$config['user_search_filter'] = '';  // Additional search filters to use for user lookups
$config['group_search_filter'] = ''; // Additional search filters to use for group lookups
$config['login_attribute'] = 'uid';
$config['schema_type'] = 'rfc2307'; // Use rfc2307, rfc2307bis, or ad
$config['proxy_user'] = '';
$config['proxy_pass'] = '';
$config['roles'] = array(1 => 'User', 
                         3 => 'Power User',
                         5 => 'Administrator');
$config['auditlog'] = 'application/logs/audit.log';  // Some place to log attempted logins (separate from message log)

If all else fails and you are comfortable writing your very own library, that might also be an idea. 如果所有其他方法都失败了,并且您很愿意编写自己的库,那可能也是一个主意。

Update: I just noticed that the library fails in the _init() function: 更新:我只是注意到该库在_init()函数中失败:

private function _init() {
    // Verify that the LDAP extension has been loaded/built-in
    // No sense continuing if we can't
    if (! function_exists('ldap_connect')) {
        show_error('LDAP functionality not present.  Either load the module ldap php module or use a php with ldap support compiled in.');
        log_message('error', 'LDAP functionality not present in php.');
    }

I don't actually know why that would fail if the function cleary exists (and works) as you stated previously. 我实际上不知道如果如前所述,如果函数cleary存在(并且可以正常工作),为什么会失败。

Hello, 你好,

Even if the question is more than an year old (and you probably found the answer by now), I will try to give some hints as it might help someone else. 即使问题已经存在了一年多(并且您可能已经找到答案了),我也会尝试给出一些提示,因为它可能会对其他人有所帮助。

The error you are seeing is because the php_ldap library is not enabled in your php.ini file. 您看到的错误是因为php.ini文件中未启用php_ldap库。 So, try to find in the php.ini the line ";extension=php_ldap.dll" and uncomment it by removing the ";" 因此,尝试在php.ini中找到“; extension = php_ldap.dll”行,并通过删除“;”取消注释。 form the beginning. 形成一个开始。

Note: If you are using XAMPP (for windows), then after restarting it, PHP will probabbly complain about some dlls missing. 注意:如果使用的是XAMPP(用于Windows),则在重新启动XAMPP之后,PHP可能会抱怨缺少一些dll。 To solve this problem you have to copy the following dll files from your php folder to apache/bin: 要解决此问题,您必须将以下dll文件从您的php文件夹复制到apache / bin:

  • libsasl.dll libsasl.dll
  • libeay32.dll 的libeay32.dll
  • ssleay32.dll (optional; for SSL) ssleay32.dll(可选;用于SSL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM