当前位置: 首页>>代码示例>>PHP>>正文


PHP Dn::checkDn方法代码示例

本文整理汇总了PHP中Zend\Ldap\Dn::checkDn方法的典型用法代码示例。如果您正苦于以下问题:PHP Dn::checkDn方法的具体用法?PHP Dn::checkDn怎么用?PHP Dn::checkDn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Ldap\Dn的用法示例。


在下文中一共展示了Dn::checkDn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bind

 /**
  * @param  string $username The username for authenticating the bind
  * @param  string $password The password for authenticating the bind
  * @return Ldap Provides a fluent interface
  * @throws Exception\LdapException
  */
 public function bind($username = null, $password = null)
 {
     $moreCreds = true;
     if ($username === null) {
         $username = $this->getUsername();
         $password = $this->getPassword();
         $moreCreds = false;
     }
     if (empty($username)) {
         /* Perform anonymous bind
          */
         $username = null;
         $password = null;
     } else {
         /* Check to make sure the username is in DN form.
          */
         if (!Dn::checkDn($username)) {
             if ($this->getBindRequiresDn()) {
                 /* moreCreds stops an infinite loop if getUsername does not
                  * return a DN and the bind requires it
                  */
                 if ($moreCreds) {
                     try {
                         $username = $this->getAccountDn($username);
                     } catch (Exception\LdapException $zle) {
                         switch ($zle->getCode()) {
                             case Exception\LdapException::LDAP_NO_SUCH_OBJECT:
                             case Exception\LdapException::LDAP_X_DOMAIN_MISMATCH:
                             case Exception\LdapException::LDAP_X_EXTENSION_NOT_LOADED:
                                 throw $zle;
                         }
                         throw new Exception\LdapException(null, 'Failed to retrieve DN for account: ' . $username . ' [' . $zle->getMessage() . ']', Exception\LdapException::LDAP_OPERATIONS_ERROR);
                     }
                 } else {
                     throw new Exception\LdapException(null, 'Binding requires username in DN form');
                 }
             } else {
                 $username = $this->getCanonicalAccountName($username, $this->getAccountCanonicalForm());
             }
         }
     }
     if (!is_resource($this->resource)) {
         $this->connect();
     }
     if ($username !== null && $password === '' && $this->getAllowEmptyPassword() !== true) {
         $zle = new Exception\LdapException(null, 'Empty password not allowed - see allowEmptyPassword option.');
     } else {
         ErrorHandler::start(E_WARNING);
         $bind = ldap_bind($this->resource, $username, $password);
         ErrorHandler::stop();
         if ($bind) {
             $this->boundUser = $username;
             return $this;
         }
         $message = $username === null ? $this->connectString : $username;
         switch ($this->getLastErrorCode()) {
             case Exception\LdapException::LDAP_SERVER_DOWN:
                 /* If the error is related to establishing a connection rather than binding,
                  * the connect string is more informative than the username.
                  */
                 $message = $this->connectString;
         }
         $zle = new Exception\LdapException($this, $message);
     }
     $this->disconnect();
     throw $zle;
 }
开发者ID:Rovak,项目名称:zf2,代码行数:73,代码来源:Ldap.php

示例2: testCoreExplodeDnWithMultiValuedRdn

 public function testCoreExplodeDnWithMultiValuedRdn()
 {
     $dn = 'cn=name1+uid=user,cn=name2,dc=example,dc=org';
     $k = array();
     $v = array();
     $this->assertTrue(Ldap\Dn::checkDn($dn, $k, $v));
     $ke = array(array('cn', 'uid'), 'cn', 'dc', 'dc');
     $ve = array(array('name1', 'user'), 'name2', 'example', 'org');
     $this->assertEquals($ke, $k);
     $this->assertEquals($ve, $v);
     $dn = 'cn=name11+cn=name12,cn=name2,dc=example,dc=org';
     $this->assertFalse(Ldap\Dn::checkDn($dn));
     $dn = 'CN=name11+Cn=name12,cn=name2,dc=example,dc=org';
     $this->assertFalse(Ldap\Dn::checkDn($dn));
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:15,代码来源:ExplodingTest.php


注:本文中的Zend\Ldap\Dn::checkDn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。