Yii 用于用户身份验证的yildap连接

Yii 用于用户身份验证的yildap连接,yii,ldap,yii-extensions,Yii,Ldap,Yii Extensions,我是yii框架的新手,我正在尝试为用户身份验证创建ldap配置 下面是我创建的步骤,但它抛出了eerro,如下所示 include(Controller.php)[function.include]:打开流失败:没有这样的文件或目录 C:\xampp\htdocs\yiif\framework\YiiBase.php(418) 步骤: 1.我已包括以下ldaprecord/ C中的扩展:\xampp\htdocs\seed2\protected\extensions\ldaprecord 2.我

我是yii框架的新手,我正在尝试为用户身份验证创建ldap配置 下面是我创建的步骤,但它抛出了eerro,如下所示

include(Controller.php)[function.include]:打开流失败:没有这样的文件或目录

C:\xampp\htdocs\yiif\framework\YiiBase.php(418)

步骤: 1.我已包括以下ldaprecord/ C中的扩展:\xampp\htdocs\seed2\protected\extensions\ldaprecord 2.我在config/main.php中包含了以下代码

`'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'ldap'=>array(
'class' => 'ext.ldaprecord.LdapComponent',
'server' => 'ldap://192.168.x.xxxx',
'port' => 389,
//'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxx,dc=demo,dc=com',
//'bind_pwd' => 'pass@123',
'base_dn' => 'dc=rsales,dc=demo,dc=com'),);
'params'=>array(
// this is used in contact page
'adminEmail'=>'sundarapandian@rsalesarm.com',
),
'ldap'=>array(
'class' => 'ext.ldaprecord.LdapComponent',
'server' => 'ldap://192.168.x.xxx',
'port' => 389,
//'bind_rdn' => 'cn=xxxx xxxx,cn=Users,dc=xxxx,dc=demo,dc=com',
//'bind_pwd' => 'pass@123',
'base_dn' => 'dc=xxxxx,dc=demo,dc=com'),
);`
  • 在index.php中包含这一行

    $config=dirname(_文件)'/protected/extensions/ldaprecord/CLdapRecord.php'

  • 我将useridentity身份验证功能更改为

  • ` 公共函数身份验证() { $username=$this->username; $password=$this->password; $dname='xxxxxxx'; $options['host']='ldap://192.168.x.xxx'; $options['port']=389; $ldap_username=“CN=”.$username.”,CN=Users,DC=xxxx,DC=demo,DC=com”

    我在这里被绊住了。有人能帮我解决这个问题吗。请帮助我,提前谢谢

    controller.php文件存在于受保护的/组件中 甚至我也检查它是否包含在main.php中

    'import'=>array(
            'application.models.*',
            'application.components.*',
            'ext.ldaprecord.*',
        ),
    
    如果删除以下行,将显示以下错误 代码:

    错误: 未定义属性“CWebApplication.ldap”

    是的,我使用的扩展只有你给出的链接上面([http://www.yiiframework.com/extension/ldaprecord/]),如果您有任何其他扩展,请您提供该链接,以及需要采取哪些步骤来实现………提前感谢

    HIIIIII

    我在参数中犯了错误,现在我已更改如下,并删除了

    $config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php';
    
    它没有抛出任何错误

    下面是我的main.php完整代码:

    <?php
       return array(
        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
        'name'=>'xxxxxx',
    
        // preloading 'log' component
        'preload'=>array('log'),
    
        // autoloading model and component classes
        'import'=>array(
            'application.models.*',
            'application.components.*',
            //ldap config added code
             'ext.ldaprecord.*',
    
        ),
    
        'defaultController' => 'site/login',
    
        'modules'=>array(
            // uncomment the following to enable the Gii tool
    
            'gii'=>array(
                'class'=>'system.gii.GiiModule',
                'password'=>'pass',
                // If removed, Gii defaults to localhost only. Edit carefully to taste.
                'ipFilters'=>array('127.0.0.1','::1'),
            ),
    
        ),
    
        // application components
        'components'=>array(
            'user'=>array(
                // enable cookie-based authentication
                'allowAutoLogin'=>true,
            ),
    
            // uncomment the following to enable URLs in path-format
    
            /*'urlManager'=>array(
                'urlFormat'=>'path',
                'rules'=>array(
                    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                ),
            ),*/
    
                /*'db'=>array(
                'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
            ),*/
            // uncomment the following to use a MySQL database
    
            'db'=>array(
                'connectionString' => 'mysql:host=localhost;dbname=xxxxx',
                'emulatePrepare' => true,
                'username' => 'root',
                'password' => '',
                'charset' => 'utf8',
                'tablePrefix' => '',
            ),
    
            'errorHandler'=>array(
                // use 'site/error' action to display errors
                'errorAction'=>'site/error',
            ),
            'log'=>array(
                'class'=>'CLogRouter',
                'routes'=>array(
                    array(
                        'class'=>'CFileLogRoute',
                        'levels'=>'error, warning',
                    ),
                    // uncomment the following to show log messages on web pages
                    /*
                    array(
                        'class'=>'CWebLogRoute',
                    ),
                    */
                ),
            ),
    
    
    
            'ldap'=>array(
                'class' => 'ext.ldaprecord.LdapComponent',
                'server' => 'ldap://192.168.x.xxx',
                'port' => 389,
                //'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxxxx,dc=demo,dc=com',
                //'bind_pwd' => 'pass@123',
                'base_dn' => 'dc=xxxxx,dc=demo,dc=com'),
    
    
    
    
        ),
    
        // application-level parameters that can be accessed
        // using Yii::app()->params['paramName']
        'params'=>array(
            // this is used in contact page
            'adminEmail'=>'xxx@xxxx.com',
            'ldap'=>array(
                'class' => 'ext.ldaprecord.LdapComponent',
                'server' => 'ldap://192.168.x.xxx',
                'port' => 389,
                //'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxxx,dc=demo,dc=com',
                //'bind_pwd' => 'pass@123',
                'base_dn' => 'dc=xxxx,dc=demo,dc=com'),
        ),
    
    );
    

    我刚刚读到:

    $config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php'
    

    为什么要这样做?我假设您正在使用扩展:它不建议文档中的任何地方这样做。这几乎清空了应用程序的配置,包括
    导入
    -节,这最终导致
    控制器.php
    的包含失败。

    既然您要求另一个扩展,我会这样做请指出。它不是一个扩展,但非常详细地介绍了如何设置它,看起来它将为您实现相同的最终目标。

    是的,我只使用您在上面给出的链接中提供的扩展,如果您有任何其他扩展,请您提供该链接以及需要采取哪些步骤来实现………提前感谢……不搅动配置是一个开始。检查配置中括号的嵌套级别。有东西正在将
    ldap
    -部分推出
    组件
    -节。'components'=>数组('errorHandler'=>数组('errorAction'=>'site/error',),'log'=>数组('class'=>'CLogRouter','routes'=>数组(数组('class'=>'CFileLogRoute','levels'=>'error,warning',),,),),,,,,),'ldap'=>数组('class'=>'ext.ldaprecord.LdapComponent','server'=>'ldap://192.168.x.xxxx“,“端口”=>389,//“绑定”=>“cn=xxxx xxxx,cn=Users,dc=xxxx,dc=demo,dc=com”,//“绑定”=>”pass@123“,”基本dn'=>“dc=xxxxx,dc=demo,dc=com'),),@$bind=ldap\U bind($connection,$options['domain']。“\\”$this->username,$this->password);不起作用你能说我的终端上会出现什么错误吗这是一个可怕的工作。你能确认你的组件节看起来大致相同吗?如果是这样,我不明白为什么Yii会错误地指出没有
    CWebApplication.ldap
    属性。此外,“不起作用”的信息太少,无法处理。遗憾的是此扩展的原始作者还选择通过
    die()
    停止应用程序,而不是抛出异常,这使得调试变得异常困难。。。
    <?php
       return array(
        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
        'name'=>'xxxxxx',
    
        // preloading 'log' component
        'preload'=>array('log'),
    
        // autoloading model and component classes
        'import'=>array(
            'application.models.*',
            'application.components.*',
            //ldap config added code
             'ext.ldaprecord.*',
    
        ),
    
        'defaultController' => 'site/login',
    
        'modules'=>array(
            // uncomment the following to enable the Gii tool
    
            'gii'=>array(
                'class'=>'system.gii.GiiModule',
                'password'=>'pass',
                // If removed, Gii defaults to localhost only. Edit carefully to taste.
                'ipFilters'=>array('127.0.0.1','::1'),
            ),
    
        ),
    
        // application components
        'components'=>array(
            'user'=>array(
                // enable cookie-based authentication
                'allowAutoLogin'=>true,
            ),
    
            // uncomment the following to enable URLs in path-format
    
            /*'urlManager'=>array(
                'urlFormat'=>'path',
                'rules'=>array(
                    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                ),
            ),*/
    
                /*'db'=>array(
                'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
            ),*/
            // uncomment the following to use a MySQL database
    
            'db'=>array(
                'connectionString' => 'mysql:host=localhost;dbname=xxxxx',
                'emulatePrepare' => true,
                'username' => 'root',
                'password' => '',
                'charset' => 'utf8',
                'tablePrefix' => '',
            ),
    
            'errorHandler'=>array(
                // use 'site/error' action to display errors
                'errorAction'=>'site/error',
            ),
            'log'=>array(
                'class'=>'CLogRouter',
                'routes'=>array(
                    array(
                        'class'=>'CFileLogRoute',
                        'levels'=>'error, warning',
                    ),
                    // uncomment the following to show log messages on web pages
                    /*
                    array(
                        'class'=>'CWebLogRoute',
                    ),
                    */
                ),
            ),
    
    
    
            'ldap'=>array(
                'class' => 'ext.ldaprecord.LdapComponent',
                'server' => 'ldap://192.168.x.xxx',
                'port' => 389,
                //'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxxxx,dc=demo,dc=com',
                //'bind_pwd' => 'pass@123',
                'base_dn' => 'dc=xxxxx,dc=demo,dc=com'),
    
    
    
    
        ),
    
        // application-level parameters that can be accessed
        // using Yii::app()->params['paramName']
        'params'=>array(
            // this is used in contact page
            'adminEmail'=>'xxx@xxxx.com',
            'ldap'=>array(
                'class' => 'ext.ldaprecord.LdapComponent',
                'server' => 'ldap://192.168.x.xxx',
                'port' => 389,
                //'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxxx,dc=demo,dc=com',
                //'bind_pwd' => 'pass@123',
                'base_dn' => 'dc=xxxx,dc=demo,dc=com'),
        ),
    
    );
    
    <?php
     public function authenticate()
    
    {
            $options = Yii::app()->params['ldap'];
            //print_r($options);
            $connection = ldap_connect($options['host'], $options['port']);
            ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
            ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
    
            if($connection)
            {
               // try
              //  {
                    //echo $options['domain']."\\".$this->username. $this->password;
                    //exit;
                    $ldap_username = "CN=".$this->username.",CN=xxxx,DC=xxxx,DC=demo,DC=com";
    
            $ldap_password=$this->password;
            echo $connection.$ldap_username.$ldap_password;
            //$bind=ldap_bind($connection, $ldap_username, $ldap_password)
                    //exit;
                    //print_r(ldap_bind($connection,$ldap_username,$ldap_password));
                    $bind = @ldap_bind($connection,$ldap_username, $ldap_password);
                    print_r($bind);
                    //exit;
               //@$bind = ldap_bind($connection,$ldap_username, $ldap_password);
                //   $abc=@$bind;
                   //print_r($abc);
    
                   //exit;
                /*}
                catch (Exception $e){
                    echo $e->getMessage();
                }*/
                if(!$bind) $this->errorCode = self::ERROR_PASSWORD_INVALID;
                else $this->errorCode = self::ERROR_NONE;
            }
            return !$this->errorCode;
    }
    
    $config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php'