public setStreamContext ( mixed $context ) : Zend_Http_Client_Adapter_Socket | ||
$context | mixed | Stream context or array of context options |
return | Zend_Http_Client_Adapter_Socket |
public function setStreamContext($context)
{
if (is_resource($context) && get_resource_type($context) == 'stream-context') {
$this->_context = $context;
} elseif (is_array($context)) {
$this->_context = stream_context_create($context);
} else {
// Invalid parameter
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Expecting either a stream context resource or array, got " . gettype($context));
}
return $this;
}
public function validate($username, $password) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Options: ' . print_r($this->_options, true)); } $url = isset($this->_options['url']) ? $this->_options['url'] : 'https://localhost/validate/check'; $adapter = new Zend_Http_Client_Adapter_Socket(); $adapter->setStreamContext($this->_options = array('ssl' => array('verify_peer' => isset($this->_options['ignorePeerName']) ? false : true, 'allow_self_signed' => isset($this->_options['allowSelfSigned']) ? true : false))); $client = new Zend_Http_Client($url, array('maxredirects' => 0, 'timeout' => 30)); $client->setAdapter($adapter); $params = array('user' => $username, 'pass' => $password); $client->setParameterPost($params); try { $response = $client->request(Zend_Http_Client::POST); } catch (Zend_Http_Client_Adapter_Exception $zhcae) { Tinebase_Exception::log($zhcae); return Tinebase_Auth::FAILURE; } $body = $response->getBody(); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Request: ' . $client->getLastRequest()); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Response: ' . $body); } if ($response->getStatus() !== 200) { return Tinebase_Auth::FAILURE; } $result = Tinebase_Helper::jsonDecode($body); if (isset($result['result']) && $result['result']['status'] === true && $result['result']['value'] === true) { return Tinebase_Auth::SUCCESS; } else { return Tinebase_Auth::FAILURE; } }