本文整理汇总了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;
}
示例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());
}
}
示例3: testConnectBind
public function testConnectBind()
{
$ldap = new Zend_Ldap($this->_options);
$ldap->connect()->bind();
}
示例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());
}
}
}
示例5: testConnectBind
public function testConnectBind()
{
$ldap = new Zend_Ldap($this->_options);
$ldap->connect()->bind();
$this->assertNotNull($ldap->getResource());
}
示例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 {
//.........这里部分代码省略.........