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


PHP Zend_Ldap::connect方法代码示例

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


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

示例1: getLdap

 /**
  * returns the class that actually does the LDAP querying
  * 
  * @return Zend_Ldap
  */
 public function getLdap()
 {
     // get the connection if not set
     if (!$this->connection && $this->Host) {
         $options = array('host' => $this->Host, 'username' => $this->BindUser, 'password' => $this->BindPass, 'bindRequiresDn' => true, 'baseDn' => $this->BaseDN);
         $this->connection = new Zend_Ldap($options);
         $this->connection->connect();
     }
     return $this->connection;
 }
开发者ID:nyeholt,项目名称:silverstripe-ldap-connector,代码行数:15,代码来源:LdapContentSource.php

示例2: testConnectWithUri

 /**
  * @group ZF-8274
  */
 public function testConnectWithUri()
 {
     $host = TESTS_ZEND_LDAP_HOST;
     $port = 0;
     if (defined('TESTS_ZEND_LDAP_PORT') && TESTS_ZEND_LDAP_PORT != 389) {
         $port = TESTS_ZEND_LDAP_PORT;
     }
     $useSsl = false;
     if (defined('TESTS_ZEND_LDAP_USE_SSL')) {
         $useSsl = TESTS_ZEND_LDAP_USE_SSL;
     }
     if ($useSsl) {
         $host = 'ldaps://' . $host;
     } else {
         $host = 'ldap://' . $host;
     }
     if ($port) {
         $host = $host . ':' . $port;
     }
     $ldap = new Zend_Ldap();
     try {
         $ldap->connect($host)->bind('CN=ignored,DC=example,DC=com', 'ignored');
         $this->fail('Expected exception for invalid username');
     } catch (Zend_Ldap_Exception $zle) {
         $this->assertContains('Invalid credentials', $zle->getMessage());
     }
 }
开发者ID:crodriguezn,项目名称:crossfit-milagro,代码行数:30,代码来源:ConnectTest.php

示例3: testConnectBind

 public function testConnectBind()
 {
     $ldap = new Zend_Ldap($this->_options);
     $ldap->connect()->bind();
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:5,代码来源:OriginalBindTest.php

示例4: testDisconnect

 public function testDisconnect()
 {
     $ldap = new Zend_Ldap($this->_options);
     for ($i = 0; $i < 3; $i++) {
         $ldap->disconnect();
         try {
             $ldap->connect()->bind('CN=ignored,DC=example,DC=com', 'ignored');
             $this->fail('Expected exception for unknown username');
         } catch (Zend_Ldap_Exception $zle) {
             $this->assertContains('Invalid credentials', $zle->getMessage());
         }
     }
 }
开发者ID:omusico,项目名称:logica,代码行数:13,代码来源:OriginalConnectTest.php

示例5: testConnectBind

 public function testConnectBind()
 {
     $ldap = new Zend_Ldap($this->_options);
     $ldap->connect()->bind();
     $this->assertNotNull($ldap->getResource());
 }
开发者ID:travisj,项目名称:zf,代码行数:6,代码来源:BindTest.php

示例6: _ldapIntegration

 private static function _ldapIntegration($userId, $username, $password, $loginServer = null)
 {
     $userId = intval($userId);
     $conf = Phprojekt::getInstance()->getConfig();
     $ldapOptions = $conf->authentication->ldap->toArray();
     // Zend library does not allow determining from which server the user was found from
     // That's why we need to request the server from the user during login.
     $account = null;
     if ($loginServer !== null && array_key_exists($loginServer, $ldapOptions)) {
         $searchOpts = $ldapOptions[$loginServer];
         try {
             $ldap = new Zend_Ldap($searchOpts);
             $ldap->connect();
             $ldap->bind($username, $password);
             $filter = sprintf("(\n                        &(\n                           |(objectclass=posixAccount)\n                            (objectclass=Person)\n                        )\n                        (\n                            |(uid=%s)\n                             (samAccountName=%s)\n                         )\n                    )", $username, $username);
             $result = $ldap->search($filter, $searchOpts['baseDn']);
             $account = $result->getFirst();
             $ldap->disconnect();
         } catch (Exception $e) {
             throw new Phprojekt_Auth_Exception('Failed to establish a search connection to the LDAP server:' . ' ' . $server . ' ' . 'Please check your configuration for that server.', 8);
         }
     } else {
         throw new Phprojekt_Auth_Exception('Server not specified during login! "
             . "Please check that your login screen contains the login domain selection.', 9);
     }
     if ($account !== null) {
         // User found
         $integration = isset($conf->authentication->integration) ? $conf->authentication->integration->toArray() : array();
         $firstname = "";
         $lastname = "";
         $email = "";
         if (isset($account['givenname'])) {
             $firstname = $account['givenname'][0];
         }
         if (isset($account['sn'])) {
             $lastname = $account['sn'][0];
         }
         if (isset($account['mail'])) {
             $email = $account['mail'][0];
         }
         // Set user params
         $params = array();
         $params['id'] = intval($userId);
         // New user has id = 0
         $params['username'] = $username;
         $params['password'] = $password;
         $admins = array();
         if (isset($integration['systemAdmins'])) {
             $admins = split(",", $integration['systemAdmins']);
             foreach ($admins as $key => $admin) {
                 $admins[$key] = trim($admin);
             }
         }
         $params['admin'] = in_array($username, $admins) ? 1 : 0;
         // Default to non-admin (0)
         if ($userId > 0) {
             $user = self::_getUser($userId);
             $params['admin'] = intval($user->admin);
         }
         // Integrate with parameters found from LDAP server
         $params['firstname'] = $firstname;
         $params['lastname'] = $lastname;
         $params['email'] = $email;
         if ($userId > 0) {
             // Update user parameters with those found from LDAP server
             $user->find($userId);
             $params['id'] = $userId;
             if (!self::_saveUser($params)) {
                 throw new Phprojekt_Auth_Exception('User update failed for LDAP parameters', 10);
             }
         } else {
             // Add new user to PHProjekt
             // TODO: Default conf could be defined in configuration
             // Lists needed for checks ?
             // Set default parameters for users
             $params['status'] = "A";
             // Active user
             $params['language'] = isset($conf->language) ? $conf->language : "en";
             // Conf language / English
             $params['timeZone'] = "0000";
             // (GMT) Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London
             // Default integration vals from config
             if (isset($integration['admin']) && $params['admin'] == 0) {
                 $val = intval($integration['admin']);
                 if ($val == 1 || $val == 0) {
                     $params['admin'] = $val;
                 }
             }
             if (isset($integration['status'])) {
                 $val = trim(strtoupper($integration['status']));
                 if (in_array($val, array("A", "I"))) {
                     $params['status'] = $val;
                 }
             }
             if (isset($integration['language'])) {
                 $val = trim(strtolower($integration['language']));
                 $languages = Phprojekt_LanguageAdapter::getLanguageList();
                 if (array_key_exists($val, $languages)) {
                     $params['language'] = $val;
                 } else {
//.........这里部分代码省略.........
开发者ID:RainyBlueSky,项目名称:PHProjekt,代码行数:101,代码来源:Auth.php


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