Note that there are some explanatory texts on larger screens.

plurals
  1. POYII LDAP connection for user authentication
    text
    copied!<p>I am new to yii frame work I am trying to create an ldap configuration for user authentication The following steps which I taken to create but it throws eerro as below</p> <p>include(Controller.php) [function.include]: failed to open stream: No such file or directory</p> <p>C:\xampp\htdocs\yiif\framework\YiiBase.php(418) </p> <p>steps: 1. I have included the following ldaprecord/ extension in C:\xampp\htdocs\seed2\protected\extensions\ldaprecord 2. I have included the following code in config/main.php</p> <pre><code>`'components'=&gt;array( 'user'=&gt;array( // enable cookie-based authentication 'allowAutoLogin'=&gt;true, ), 'ldap'=&gt;array( 'class' =&gt; 'ext.ldaprecord.LdapComponent', 'server' =&gt; 'ldap://192.168.x.xxxx', 'port' =&gt; 389, //'bind_rdn' =&gt; 'cn=suren diran,cn=Users,dc=xxxx,dc=demo,dc=com', //'bind_pwd' =&gt; 'pass@123', 'base_dn' =&gt; 'dc=rsales,dc=demo,dc=com'),); 'params'=&gt;array( // this is used in contact page 'adminEmail'=&gt;'sundarapandian@rsalesarm.com', ), 'ldap'=&gt;array( 'class' =&gt; 'ext.ldaprecord.LdapComponent', 'server' =&gt; 'ldap://192.168.x.xxx', 'port' =&gt; 389, //'bind_rdn' =&gt; 'cn=xxxx xxxx,cn=Users,dc=xxxx,dc=demo,dc=com', //'bind_pwd' =&gt; 'pass@123', 'base_dn' =&gt; 'dc=xxxxx,dc=demo,dc=com'), );` </code></pre> <ol> <li><p>included this line in the index.php</p> <p><code>$config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php';</code></p></li> <li><p>and I have changed the useridentity authentication function as</p></li> </ol> <p>` public function authenticate() { $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";</p> <pre><code>$options = Yii::app()-&gt;params['ldap']; print_r($options); $connection = ldap_connect($options['host'], $options['port']); //print_r($connection); ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($connection, LDAP_OPT_REFERRALS, 0); if($connection) { echo "success"; //exit; try { //echo $connection.$ldap_username.$this-&gt;password; //print_r(ldap_bind($connection,$dname."\\". $ldap_username, $password)); //exit; @$bind = ldap_bind($connection,$dname."\\". $ldap_username, $password); print_r(@$bind); if(@$bind) { echo "successfully logedin"; } } catch (Exception $e){ echo $e-&gt;getMessage(); } if(!$bind) $this-&gt;errorCode = self::ERROR_PASSWORD_INVALID; else $this-&gt;errorCode = self::ERROR_NONE; } return !$this-&gt;errorCode; };` </code></pre> <p>I am stucked here can any one help me hw to resolve this issue .please help me ,Thanks in advance.......... </p> <p>controller.php file was exists in the protected/components even I check that it was included in the main .php </p> <pre><code>'import'=&gt;array( 'application.models.*', 'application.components.*', 'ext.ldaprecord.*', ), </code></pre> <p>if I remove the following line the following error will shown code:</p> <pre><code>$config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php' </code></pre> <p>error: Property "CWebApplication.ldap" is not defined.</p> <p>yes I am using that extension only which u given link above([http://www.yiiframework.com/extension/ldaprecord/]),if u have any other extension please can u provide that link and what the steps need to be taken for that to implement .........thanks in advance.......... </p> <p>HIIIIII</p> <p>I done mistake in the params now I have changed that as below , and I removed the </p> <pre><code>$config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php'; </code></pre> <p>it was not throwing any error .</p> <p>I am including the my main.php full code below:</p> <pre><code>&lt;?php return array( 'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 'name'=&gt;'xxxxxx', // preloading 'log' component 'preload'=&gt;array('log'), // autoloading model and component classes 'import'=&gt;array( 'application.models.*', 'application.components.*', //ldap config added code 'ext.ldaprecord.*', ), 'defaultController' =&gt; 'site/login', 'modules'=&gt;array( // uncomment the following to enable the Gii tool 'gii'=&gt;array( 'class'=&gt;'system.gii.GiiModule', 'password'=&gt;'pass', // If removed, Gii defaults to localhost only. Edit carefully to taste. 'ipFilters'=&gt;array('127.0.0.1','::1'), ), ), // application components 'components'=&gt;array( 'user'=&gt;array( // enable cookie-based authentication 'allowAutoLogin'=&gt;true, ), // uncomment the following to enable URLs in path-format /*'urlManager'=&gt;array( 'urlFormat'=&gt;'path', 'rules'=&gt;array( '&lt;controller:\w+&gt;/&lt;id:\d+&gt;'=&gt;'&lt;controller&gt;/view', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;/&lt;id:\d+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;', ), ),*/ /*'db'=&gt;array( 'connectionString' =&gt; 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db', ),*/ // uncomment the following to use a MySQL database 'db'=&gt;array( 'connectionString' =&gt; 'mysql:host=localhost;dbname=xxxxx', 'emulatePrepare' =&gt; true, 'username' =&gt; 'root', 'password' =&gt; '', 'charset' =&gt; 'utf8', 'tablePrefix' =&gt; '', ), 'errorHandler'=&gt;array( // use 'site/error' action to display errors 'errorAction'=&gt;'site/error', ), 'log'=&gt;array( 'class'=&gt;'CLogRouter', 'routes'=&gt;array( array( 'class'=&gt;'CFileLogRoute', 'levels'=&gt;'error, warning', ), // uncomment the following to show log messages on web pages /* array( 'class'=&gt;'CWebLogRoute', ), */ ), ), 'ldap'=&gt;array( 'class' =&gt; 'ext.ldaprecord.LdapComponent', 'server' =&gt; 'ldap://192.168.x.xxx', 'port' =&gt; 389, //'bind_rdn' =&gt; 'cn=suren diran,cn=Users,dc=xxxxxx,dc=demo,dc=com', //'bind_pwd' =&gt; 'pass@123', 'base_dn' =&gt; 'dc=xxxxx,dc=demo,dc=com'), ), // application-level parameters that can be accessed // using Yii::app()-&gt;params['paramName'] 'params'=&gt;array( // this is used in contact page 'adminEmail'=&gt;'xxx@xxxx.com', 'ldap'=&gt;array( 'class' =&gt; 'ext.ldaprecord.LdapComponent', 'server' =&gt; 'ldap://192.168.x.xxx', 'port' =&gt; 389, //'bind_rdn' =&gt; 'cn=suren diran,cn=Users,dc=xxxxx,dc=demo,dc=com', //'bind_pwd' =&gt; 'pass@123', 'base_dn' =&gt; 'dc=xxxx,dc=demo,dc=com'), ), ); </code></pre> <p>I am including my useridentity function below:</p> <pre><code>&lt;?php public function authenticate() { $options = Yii::app()-&gt;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-&gt;username. $this-&gt;password; //exit; $ldap_username = "CN=".$this-&gt;username.",CN=xxxx,DC=xxxx,DC=demo,DC=com"; $ldap_password=$this-&gt;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-&gt;getMessage(); }*/ if(!$bind) $this-&gt;errorCode = self::ERROR_PASSWORD_INVALID; else $this-&gt;errorCode = self::ERROR_NONE; } return !$this-&gt;errorCode; } </code></pre> <p>But in the above one the ldap_bind is not working can u help on this ........ Please help me I how to overcome this .........thanks alot.....</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload