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; } }
/** * returns function parameter as object, decode Json if needed * * Prepare function input to be an array. Input maybe already an array or (empty) text. * Starting PHP 7 Zend_Json::decode can't handle empty strings. * * @param mixed $_dataAsArrayOrJson * @return array */ protected function _prepareParameter($_dataAsArrayOrJson) { return Tinebase_Helper::jsonDecode($_dataAsArrayOrJson); }
/** * decrypts username and password * * @param Tinebase_Model_CredentialCache $_cache * @throws Tinebase_Exception_NotFound * @throws Tinebase_Exception_SystemGeneric */ protected function _decrypt($_cache) { if (!extension_loaded('mcrypt')) { throw new Tinebase_Exception_SystemGeneric('mcrypt extension required'); } $encryptedData = base64_decode($_cache->cache); $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', 'cbc', ''); mcrypt_generic_init($td, $_cache->key, substr($_cache->getId(), 0, 16)); $jsonEncodedData = trim(mdecrypt_generic($td, $encryptedData)); $cacheData = Tinebase_Helper::jsonDecode($jsonEncodedData); mcrypt_generic_deinit($td); mcrypt_module_close($td); if (!isset($cacheData['username']) && !isset($cacheData['password'])) { throw new Tinebase_Exception_NotFound('could not find valid credential cache'); } $_cache->username = $cacheData['username']; $_cache->password = $cacheData['password']; }