« Posts tagged LDAP

在Yii中使用活动目录验证用户身份

借助第三方类库adLDAP,将adLDAP.php复制到项目的vendors目录中。修改UserIdentity.php

PHP
<?php
 
/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
	public function authenticate()
	{   
        $ldapConfig = Yii::app()->params['ldap'];
        Yii::import('application.vendors.*');
        require_once('adLDAP.php');
        try
        {
            $adldap = new adLDAP($ldapConfig);
        }
        catch (adLDAPException $e)
        {
            echo $e; exit();   
        }
        if(!$adldap->authenticate($this->username, $this->password))
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
        else
        {
            $adInfo = $adldap->user_info($this->username);
            $this->setState('ad_info',$adInfo);
            $this->setState('login_time',time());
            $this->errorCode=self::ERROR_NONE;
        }
        return !$this->errorCode;
	}
}

PHP connect AD with LDAP over SSL (LDAPs)

《Server is unwilling to perform》之后的三个多月,终于有了测试环境。节后的第一个工作日,用了一个下午的时间进行测试,终于成功了。

主要参考文档为adldapLDAP over SSL

环境:win2003 server 用于安装ad和ca,ubuntu做为webserver,安装apache2和php

准备工作:运行phpinfo(),确认php环境已经支持openssl和openldap,关于php环境的配置不多说了。

step 1:安装CA,用来颁发证书,微软或者第三方的都可以,我装的微软的CA,这里很简单

参考文档:安装windows server 2003 证书服务(CA) 企业数字证书认证服务

setp 2:创建证书,并使ad下的ldap开启对ssl的支持,配置完成之后可以使用ldp.exe来测试ldaps连接是否成功,这里也很简单,照着文档做就OK。 »Read More

Server is unwilling to perform

在使用php连接ldap向ad中添加用户的时候遇到问题:“Server is unwilling to perform”,搜索之后发现相关资料不多,并且——解释五花八门。最后得到了同事的启发,发现这个报错与用户密码有关,把密码参数去掉后创建用户的操作返回了true,再看AD中的这个用户的状态却是禁用的。有点不理解,但总算有了些进展。

(续)上周又有了新的进展,但一直没时间更新日志。前几天找到一篇Loudly前辈的文章,链接地址:http://blog.loudly.cn/2007/11/4bfe75d9de3096a90055876934b77f21/ 。文章中提到的工作环境跟我的现在很相似,基本上可以确认不能操作用户密码的问题与SSL有关,但由于一些限制我现在没有办法进行测试,测试的工作会在最近的1-2周内完成,到时候再把我的测试结果发上来吧。

再续

PHP connect AD with LDAP over SSL (LDAPs)

ldap_search(): Partial search results returned: Sizelimit exceeded

        最近在研究用php ldap连接active directory(主要是使用adLDAP类),在使用folder_list()方法递归OU的时候发现报错,即ldap_search(): Partial search results returned: Sizelimit exceeded——只能查询1000个对象,google了一下,发现ad ldap默认的策略是有限制的(估计是考虑到性能的因素),将默认的MaxPageSize参数修改为一个较大的值即可(例如3000,我的测试环境里2000就够用了),修改方法如下。

Viewing current policy settings

  1. At the Ntdsutil.exe command prompt, type LDAP policies, and then press ENTER.
  2. At the LDAP policy command prompt, type connections, and then press ENTER.
  3. At the server connection command prompt, type connect to server <DNS name of server>, and then press ENTER. You want to connect to the server that your are currently working with.
  4. At the server connection command prompt, type q, and then press ENTER to return to the previous menu.
  5. At the LDAP policy command prompt, type Show Values, and then press ENTER.
    A display of the policies as they exist appears.

»Read More