/**
  * the singleton pattern
  *
  * @return Tinebase_Auth_CredentialCache
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Tinebase_Auth_CredentialCache();
     }
     return self::$_instance;
 }
 public function testCachePassword()
 {
     //Tinebase_User::getInstance()->cachePassword('secret');
     //$this->assertEquals('secret', Tinebase_User::getInstance()->getCachedPassword());
     $InCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials('username', 'secret');
     $outCache = new Tinebase_Model_CredentialCache(array('id' => $InCache->getId(), 'key' => $InCache->key));
     Tinebase_Auth_CredentialCache::getInstance()->getCachedCredentials($outCache);
     $this->assertEquals('username', $outCache->username);
     $this->assertEquals('secret', $outCache->password);
 }
 /**
  * set new password & credentials
  * 
  * @param string $_username
  * @param string $_password
  */
 protected function _setCredentials($_username, $_password)
 {
     Tinebase_User::getInstance()->setPassword(Tinebase_Core::getUser(), $_password, true, false);
     $oldCredentialCache = Tinebase_Core::get(Tinebase_Core::USERCREDENTIALCACHE);
     // update credential cache
     $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($_username, $_password);
     Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache);
     $event = new Tinebase_Event_User_ChangeCredentialCache($oldCredentialCache);
     Tinebase_Event::fireEvent($event);
 }
 /**
  * import the data
  */
 public function import($_resource = NULL, $_clientRecordData = array())
 {
     $_resource['options'] = Zend_Json::decode($_resource['options']);
     $credentials = new Tinebase_Model_CredentialCache(array('id' => $_resource['options']['cid'], 'key' => $_resource['options']['ckey']));
     Tinebase_Auth_CredentialCache::getInstance()->getCachedCredentials($credentials);
     $uri = $this->_splitUri($_resource['remoteUrl']);
     $caldavClientOptions = array('baseUri' => $uri['host'], 'calenderUri' => $uri['path'], 'userName' => $credentials->username, 'password' => $credentials->password, 'allowDuplicateEvents' => isset($_resource['options']['allowDuplicateEvents']) ? $_resource['options']['allowDuplicateEvents'] : false);
     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Trying to get calendar container Name:' . $_resource['options']['container_id']);
     $container = Tinebase_Container::getInstance()->getContainerById($this->_getImportCalendarByName($_resource['options']['container_id']));
     if ($container === false) {
         throw new Tinebase_Exception('Could not import, aborting ..');
         return false;
     }
     $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($credentials->username, $credentials->password);
     Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . ' ' . __LINE__ . ' Trigger CalDAV client with URI ' . $_resource['remoteUrl']);
     }
     $this->_calDAVClient = new Calendar_Import_CalDav_Client($caldavClientOptions, 'Generic', $container->name);
     $this->_calDAVClient->setVerifyPeer(false);
     $this->_calDAVClient->getDecorator()->initCalendarImport();
     $this->_calDAVClient->updateAllCalendarData();
 }
 /**
  * login from HTTP post 
  * 
  * redirects the tine main screen if authentication is successful
  * otherwise redirects back to login url 
  */
 public function loginFromPost($username, $password)
 {
     Tinebase_Core::startCoreSession();
     if (!empty($username)) {
         // try to login user
         $success = Tinebase_Controller::getInstance()->login($username, $password, Tinebase_Core::get(Tinebase_Core::REQUEST), self::REQUEST_TYPE) === TRUE;
     } else {
         $success = FALSE;
     }
     if ($success === TRUE) {
         $this->_setJsonKeyCookie();
         $ccAdapter = Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter();
         if (Tinebase_Core::isRegistered(Tinebase_Core::USERCREDENTIALCACHE)) {
             $ccAdapter->setCache(Tinebase_Core::getUserCredentialCache());
         } else {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialCache / no CC registered.');
             $success = FALSE;
             $ccAdapter->resetCache();
         }
     }
     $request = new Sabre\HTTP\Request();
     $redirectUrl = str_replace('index.php', '', $request->getAbsoluteUri());
     // authentication failed
     if ($success !== TRUE) {
         $_SESSION = array();
         Tinebase_Session::destroyAndRemoveCookie();
         // redirect back to loginurl if needed
         $redirectUrl = Tinebase_Config::getInstance()->get(Tinebase_Config::REDIRECTURL, $redirectUrl);
     }
     // load the client with GET
     header('Location: ' . $redirectUrl);
 }
 /**
  * get credentials cache from the registry or initialize it
  *
  * @return  Tinebase_Model_CredentialCache
  */
 public static function getUserCredentialCache()
 {
     if (!self::get(self::USERCREDENTIALCACHE) instanceof Tinebase_Model_CredentialCache && self::getUser()) {
         try {
             $cache = Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter()->getCache();
         } catch (Zend_Db_Statement_Exception $zdse) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Could not get credential cache adapter, perhaps Tine 2.0 is not installed yet");
             $cache = NULL;
         }
         if ($cache !== NULL) {
             self::set(self::USERCREDENTIALCACHE, $cache);
         }
     }
     return self::get(self::USERCREDENTIALCACHE);
 }
 /**
  * get an adapter instance according to the path
  *
  * pathParts:
  * [0] =>
  * [1] => external
  * [2] => accountLogin
  * [3] => adapterName
  * [4..] => path in backend
  *
  * @param string $_path
  * @return Expressodriver_Backend_Adapter_Interface
  * @throws Expressodriver_Exception
  */
 public function getAdapterBackend($_path)
 {
     $pathParts = explode('/', $_path);
     $adapterName = $pathParts[1];
     if (!isset(self::$_backends[$adapterName])) {
         $adapter = null;
         $config = Expressodriver_Controller::getInstance()->getConfigSettings();
         foreach ($config['adapters'] as $adapterConfig) {
             if ($adapterName === $adapterConfig['name']) {
                 $adapter = $adapterConfig;
             }
         }
         if (!is_null($adapter)) {
             $credentialsBackend = Tinebase_Auth_CredentialCache::getInstance();
             $userCredentialCache = Tinebase_Core::getUserCredentialCache();
             $credentialsBackend->getCachedCredentials($userCredentialCache);
             $username = $adapter['useEmailAsLoginName'] ? Tinebase_Core::getUser()->accountEmailAddress : Tinebase_Core::getUser()->accountLoginName;
             $options = array('host' => $adapter['url'], 'user' => $username, 'password' => $userCredentialCache->password, 'root' => '/', 'name' => $adapter['name'], 'useCache' => $config['default']['useCache'], 'cacheLifetime' => $config['default']['cacheLifetime']);
             self::$_backends[$adapterName] = Expressodriver_Backend_Storage_Abstract::factory($adapter['adapter'], $options);
         } else {
             throw new Expressodriver_Exception('Adapter config does not exists');
         }
     }
     return self::$_backends[$adapterName];
 }
 /**
  * update credential cache
  * 
  * @param string $loginName
  * @param string $password
  */
 protected function _updateCredentialCache($loginName, $password)
 {
     $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($loginName, $password);
     Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache);
 }
 /**
  * test credential cache cleanup
  */
 public function testClearCredentialCacheTable()
 {
     // add dummy record to credential cache
     $id = Tinebase_Record_Abstract::generateUID();
     $db = Tinebase_Core::getDb();
     $oneMinuteAgo = Tinebase_DateTime::now()->subMinute(1)->format(Tinebase_Record_Abstract::ISO8601LONG);
     $data = array('id' => $id, 'cache' => Tinebase_Record_Abstract::generateUID(), 'creation_time' => $oneMinuteAgo, 'valid_until' => $oneMinuteAgo);
     $table = SQL_TABLE_PREFIX . 'credential_cache';
     Tinebase_Core::getDb()->insert($table, $data);
     Tinebase_Auth_CredentialCache::getInstance()->clearCacheTable();
     $result = $db->fetchCol('SELECT id FROM ' . $db->quoteIdentifier($table) . ' WHERE ' . $db->quoteInto($db->quoteIdentifier('valid_until') . ' < ?', Tinebase_DateTime::now()->format(Tinebase_Record_Abstract::ISO8601LONG)));
     $this->assertNotContains($id, $result);
 }
 /**
  * creates a scheduled import
  * 
  * @param string $remoteUrl
  * @param string $interval
  * @param string $importOptions
  * @return array
  */
 public function importRemoteEvents($remoteUrl, $interval, $importOptions)
 {
     // Determine which plugin should be used to import
     switch ($importOptions['sourceType']) {
         case 'remote_caldav':
             $plugin = 'Calendar_Import_CalDAV';
             break;
         default:
             $plugin = 'Calendar_Import_Ical';
     }
     $credentialCache = Tinebase_Auth_CredentialCache::getInstance();
     $credentials = $credentialCache->cacheCredentials($importOptions['username'], $importOptions['password'], null, true, Tinebase_DateTime::now()->addYear(100));
     $record = Tinebase_Controller_ScheduledImport::getInstance()->createRemoteImportEvent(array('source' => $remoteUrl, 'interval' => $interval, 'options' => array_replace($importOptions, array('plugin' => $plugin, 'importFileByScheduler' => $importOptions['sourceType'] != 'remote_caldav', 'cid' => $credentials->getId(), 'ckey' => $credentials->key)), 'model' => 'Calendar_Model_Event', 'user_id' => Tinebase_Core::getUser()->getId(), 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId()));
     $result = $this->_recordToJson($record);
     Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'container_id:' . print_r($result['container_id'], true));
     return $result;
 }
 /**
  * create account credentials and return new credentials id
  *
  * @param string $_username
  * @param string $_password
  * @return boolean
  */
 protected function _createCredentials($_username = NULL, $_password = NULL)
 {
     Tinebase_Auth_CredentialCache::getInstance()->setCacheAdapter('Config');
     $cc = new Tinebase_Model_CredentialCache(array('username' => $_username, 'password' => $_password));
     $ac = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($cc->username, $cc->password, $this->_credential_key, TRUE);
     return $ac->getId();
 }
示例#12
0
 /**
  * places user credential cache id from cache adapter (if present) into registry
  */
 public static function setupUserCredentialCache()
 {
     try {
         $cache = Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter()->getCache();
     } catch (Zend_Db_Statement_Exception $zdse) {
         // could not get credential cache adapter, perhaps Tine 2.0 is not installed yet
         $cache = NULL;
     }
     if ($cache !== NULL) {
         self::set(self::USERCREDENTIALCACHE, $cache);
     }
 }
示例#13
0
 /**
  * init user session
  * 
  * @param Tinebase_Model_FullUser $_user
  * @param Tinebase_Model_AccessLog $_accessLog
  * @param string $_password
  */
 protected function _initUser(Tinebase_Model_FullUser $_user, Tinebase_Model_AccessLog $_accessLog, $_password)
 {
     if ($_accessLog->result === Tinebase_Auth::SUCCESS && $_user->accountStatus === Tinebase_User::STATUS_ENABLED) {
         $this->_initUserSession($_user);
         Tinebase_Core::set(Tinebase_Core::USER, $_user);
         $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($_user->accountLoginName, $_password);
         Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache);
         // need to set locale again and because locale might not be set correctly during loginFromPost
         // use 'auto' setting because it is fetched from cookie or preference then
         Tinebase_Core::setupUserLocale('auto');
         // need to set userTimeZone again
         $userTimezone = Tinebase_Core::getPreference()->getValue(Tinebase_Preference::TIMEZONE);
         Tinebase_Core::setupUserTimezone($userTimezone);
         $_user->setLoginTime($_accessLog->ip);
         $_accessLog->sessionid = session_id();
         $_accessLog->login_name = $_user->accountLoginName;
         $_accessLog->account_id = $_user->getId();
     }
 }
 protected function _setUser()
 {
     try {
         $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountLoginName', $this->userName, 'Tinebase_Model_FullUser');
         Tinebase_Core::set(Tinebase_Core::USER, $user);
         $credentialCache = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($this->userName, $this->password);
         Tinebase_Core::set(Tinebase_Core::USERCREDENTIALCACHE, $credentialCache);
     } catch (Tinebase_Exception_NotFound $e) {
         Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' Can\'t find tine20 user: ' . $this->userName);
         return null;
     }
     $this->principals[$this->currentUserPrincipal] = $user;
     return $user;
 }
示例#15
0
 /**
  * clear table as defined in arguments
  * can clear the following tables:
  * - credential_cache
  * - access_log
  * - async_job
  * - temp_files
  * 
  * if param date is given (date=2010-09-17), all records before this date are deleted (if the table has a date field)
  * 
  * @param $_opts
  * @return boolean success
  */
 public function clearTable(Zend_Console_Getopt $_opts)
 {
     if (!$this->_checkAdminRight()) {
         return FALSE;
     }
     $args = $this->_parseArgs($_opts, array('tables'), 'tables');
     $dateString = array_key_exists('date', $args) ? $args['date'] : NULL;
     $db = Tinebase_Core::getDb();
     foreach ($args['tables'] as $table) {
         switch ($table) {
             case 'access_log':
                 if ($dateString) {
                     echo "\nRemoving all access log entries before {$dateString} ...";
                     $where = array($db->quoteInto($db->quoteIdentifier('li') . ' < ?', $dateString));
                     $db->delete(SQL_TABLE_PREFIX . $table, $where);
                 } else {
                     $db->query('TRUNCATE ' . SQL_TABLE_PREFIX . $table);
                 }
                 break;
             case 'async_job':
                 $db->query('delete FROM ' . SQL_TABLE_PREFIX . 'async_job' . " WHERE status='success'");
                 break;
             case 'credential_cache':
                 Tinebase_Auth_CredentialCache::getInstance()->clearCacheTable($dateString);
                 break;
             case 'temp_files':
                 Tinebase_TempFile::getInstance()->clearTable($dateString);
                 break;
             default:
                 echo 'Table ' . $table . " not supported or argument missing.\n";
         }
         echo "\nCleared table {$table}.";
     }
     echo "\n\n";
     return TRUE;
 }
 /**
  * resolve imap or smtp credentials
  *
  * @param boolean $_onlyUsername
  * @param boolean $_throwException
  * @param boolean $_smtp
  * @return boolean
  */
 public function resolveCredentials($_onlyUsername = TRUE, $_throwException = FALSE, $_smtp = FALSE)
 {
     if ($_smtp) {
         $passwordField = 'smtp_password';
         $userField = 'smtp_user';
         $credentialsField = 'smtp_credentials_id';
     } else {
         $passwordField = 'password';
         $userField = 'user';
         $credentialsField = 'credentials_id';
     }
     if (!$this->{$userField} || !($this->{$passwordField} && !$_onlyUsername)) {
         $credentialsBackend = Tinebase_Auth_CredentialCache::getInstance();
         $userCredentialCache = Tinebase_Core::getUserCredentialCache();
         if ($userCredentialCache !== NULL) {
             try {
                 $credentialsBackend->getCachedCredentials($userCredentialCache);
             } catch (Exception $e) {
                 return FALSE;
             }
         } else {
             Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialsCache / use given imap username/password instead.');
             $userCredentialCache = new Tinebase_Model_CredentialCache(array('username' => $this->user, 'password' => $this->password));
         }
         if ($this->type == self::TYPE_USER) {
             if (!$this->{$credentialsField}) {
                 if ($_throwException) {
                     throw new Expressomail_Exception('Could not get credentials, no ' . $credentialsField . ' given.');
                 } else {
                     return FALSE;
                 }
             }
             try {
                 // NOTE: cache cleanup process might have removed the cache
                 $credentials = $credentialsBackend->get($this->{$credentialsField});
                 $credentials->key = substr($userCredentialCache->password, 0, 24);
                 $credentialsBackend->getCachedCredentials($credentials);
             } catch (Exception $e) {
                 if ($_throwException) {
                     throw $e;
                 } else {
                     return FALSE;
                 }
             }
         } else {
             // just use tine user credentials to connect to mailserver / or use credentials from config if set
             $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray();
             $credentials = $userCredentialCache;
             if (array_key_exists('user', $imapConfig) && array_key_exists('password', $imapConfig) && !empty($imapConfig['user'])) {
                 $credentials->username = $imapConfig['user'];
                 $credentials->password = $imapConfig['password'];
             }
         }
         $this->{$userField} = $credentials->username;
         $this->{$passwordField} = $credentials->password;
     }
     return TRUE;
 }
 /**
  * resolve imap or smtp credentials
  *
  * @param boolean $_onlyUsername
  * @param boolean $_throwException
  * @param boolean $_smtp
  * @return boolean
  */
 public function resolveCredentials($_onlyUsername = TRUE, $_throwException = FALSE, $_smtp = FALSE)
 {
     if ($_smtp) {
         $passwordField = 'smtp_password';
         $userField = 'smtp_user';
         $credentialsField = 'smtp_credentials_id';
     } else {
         $passwordField = 'password';
         $userField = 'user';
         $credentialsField = 'credentials_id';
     }
     if (!$this->{$userField} || !($this->{$passwordField} && !$_onlyUsername)) {
         $credentialsBackend = Tinebase_Auth_CredentialCache::getInstance();
         $userCredentialCache = Tinebase_Core::getUserCredentialCache();
         if ($userCredentialCache !== NULL) {
             try {
                 $credentialsBackend->getCachedCredentials($userCredentialCache);
             } catch (Exception $e) {
                 return FALSE;
             }
         } else {
             Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialsCache');
             return FALSE;
         }
         if ($this->type == self::TYPE_USER) {
             if (!$this->{$credentialsField}) {
                 if ($_throwException) {
                     throw new Felamimail_Exception('Could not get credentials, no ' . $credentialsField . ' given.');
                 } else {
                     return FALSE;
                 }
             }
             try {
                 // NOTE: cache cleanup process might have removed the cache
                 $credentials = $credentialsBackend->get($this->{$credentialsField});
                 $credentials->key = substr($userCredentialCache->password, 0, 24);
                 $credentialsBackend->getCachedCredentials($credentials);
             } catch (Exception $e) {
                 if ($_throwException) {
                     throw $e;
                 } else {
                     return FALSE;
                 }
             }
         } else {
             // just use tine user credentials to connect to mailserver / or use credentials from config if set
             $imapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP, new Tinebase_Config_Struct())->toArray();
             $credentials = $userCredentialCache;
             // allow to set credentials in config
             if ((isset($imapConfig['user']) || array_key_exists('user', $imapConfig)) && (isset($imapConfig['password']) || array_key_exists('password', $imapConfig)) && !empty($imapConfig['user'])) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Using credentials from config for system account.');
                 }
                 $credentials->username = $imapConfig['user'];
                 $credentials->password = $imapConfig['password'];
             }
             // allow to set pw suffix in config
             if ((isset($imapConfig['pwsuffix']) || array_key_exists('pwsuffix', $imapConfig)) && !preg_match('/' . preg_quote($imapConfig['pwsuffix']) . '$/', $credentials->password)) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Appending configured pwsuffix to system account password.');
                 }
                 $credentials->password .= $imapConfig['pwsuffix'];
             }
             if (!empty($imapConfig['domain']) && strpos($credentials->username, $imapConfig['domain']) === false) {
                 $credentials->username .= '@' . $imapConfig['domain'];
             }
         }
         if (!$this->{$userField}) {
             $this->{$userField} = $credentials->username;
         }
         $this->{$passwordField} = $credentials->password;
     }
     return TRUE;
 }
示例#18
0
 /**
  * login from HTTP post 
  * 
  * renders the tine main screen if authentication is successfull
  * otherwise redirects back to login url 
  */
 public function loginFromPost($username, $password)
 {
     if (!empty($username)) {
         # removed this line on 09-06-2010 Lars
         #Tinebase_Config::getInstance()->getConfig(Tinebase_Config::USERBACKEND, null, $_SERVER["HTTP_REFERER"])->value;
         // try to login user
         $success = Tinebase_Controller::getInstance()->login($username, $password, $_SERVER['REMOTE_ADDR'], 'TineHttpPost') === TRUE;
     } else {
         $success = FALSE;
     }
     if ($success === TRUE) {
         $ccAdapter = Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter();
         if (Tinebase_Core::isRegistered(Tinebase_Core::USERCREDENTIALCACHE)) {
             $ccAdapter->setCache(Tinebase_Core::get(Tinebase_Core::USERCREDENTIALCACHE));
         } else {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialCache / no CC registered.');
             $success = FALSE;
             $ccAdapter->resetCache();
         }
     }
     // authentication failed
     // redirect back to loginurl
     if ($success !== TRUE) {
         $defaultUrl = array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : '';
         $redirectUrl = Tinebase_Config::getInstance()->getConfig(Tinebase_Config::REDIRECTURL, NULL, $defaultUrl)->value;
         if (!empty($redirectUrl)) {
             header('Location: ' . $redirectUrl);
         }
         return;
     }
     $this->_renderMainScreen();
 }
 /**
  * clear table as defined in arguments
  * can clear the following tables:
  * - credential_cache
  * - access_log
  * - async_job
  * - temp_files
  * 
  * if param date is given (date=2010-09-17), all records before this date are deleted (if the table has a date field)
  * 
  * @param $_opts
  * @return boolean success
  */
 public function clearTable(Zend_Console_Getopt $_opts)
 {
     if (!$this->_checkAdminRight()) {
         return FALSE;
     }
     $args = $this->_parseArgs($_opts, array('tables'), 'tables');
     $dateString = isset($args['date']) || array_key_exists('date', $args) ? $args['date'] : NULL;
     $db = Tinebase_Core::getDb();
     foreach ($args['tables'] as $table) {
         switch ($table) {
             case 'access_log':
                 $date = $dateString ? new Tinebase_DateTime($dateString) : NULL;
                 Tinebase_AccessLog::getInstance()->clearTable($date);
                 break;
             case 'async_job':
                 $where = $dateString ? array($db->quoteInto($db->quoteIdentifier('end_time') . ' < ?', $dateString)) : array();
                 $where[] = $db->quoteInto($db->quoteIdentifier('status') . ' < ?', 'success');
                 echo "\nRemoving all successful async_job entries " . ($dateString ? "before {$dateString} " : "") . "...";
                 $deleteCount = $db->delete(SQL_TABLE_PREFIX . $table, $where);
                 echo "\nRemoved {$deleteCount} records.";
                 break;
             case 'credential_cache':
                 Tinebase_Auth_CredentialCache::getInstance()->clearCacheTable($dateString);
                 break;
             case 'temp_files':
                 Tinebase_TempFile::getInstance()->clearTableAndTempdir($dateString);
                 break;
             default:
                 echo 'Table ' . $table . " not supported or argument missing.\n";
         }
         echo "\nCleared table {$table}.";
     }
     echo "\n\n";
     return TRUE;
 }
 /**
  * connects to request tracker
  *
  * @return void
  */
 protected function _connect()
 {
     if (!$this->_config->rest || $this->_config->rest->url) {
         throw new Tinebase_Exception_NotFound('Could not connect to RequestTracker: No REST url given!');
     }
     $config = array('url' => $this->_config->rest->url, 'useragent' => 'Tine 2.0 remote client (rv: 0.2)', 'keepalive' => true);
     $this->_httpClient = new Zend_Http_Client($this->_config->rest->url, $config);
     $this->_httpClient->setCookieJar();
     // login
     $this->_httpClient->setMethod(Zend_Http_Client::POST);
     $this->_httpClient->setUri($this->_config->rest->url . "/REST/1.0/ticket/");
     $loginName = Tinebase_Core::getUser()->accountLoginName;
     if ($this->_config->useCustomCredendials) {
         $this->_httpClient->setAuth($this->_config->customCredentials->{$loginName}->username, $this->_config->customCredentials->{$loginName}->password);
     } else {
         $credentialCache = Tinebase_Core::getUserCredentialCache();
         Tinebase_Auth_CredentialCache::getInstance()->getCachedCredentials($credentialCache);
         $this->_httpClient->setAuth(Tinebase_Core::getUser()->accountLoginName, $credentialCache->password);
     }
     $response = $this->_httpClient->request();
     if ($response->getStatus() != 200) {
         throw new Tinebase_Exception_Record_NotAllowed($response->getMessage(), $response->getStatus());
     }
 }
 /**
  * destroy session
  *
  * @return array
  */
 public function logout()
 {
     Tinebase_Controller::getInstance()->logout($_SERVER['REMOTE_ADDR']);
     Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter()->resetCache();
     if (Tinebase_Session::isStarted()) {
         Tinebase_Session::destroyAndRemoveCookie();
     }
     $result = array('success' => true);
     return $result;
 }
示例#22
0
 /**
  * create account credentials and return new credentials id
  *
  * @param string $_username
  * @param string $_password
  * @return string
  */
 protected function _createCredentials($_username = NULL, $_password = NULL, $_userCredentialCache = NULL)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         $message = 'Create new account credentials';
         if ($_username !== NULL) {
             $message .= ' for username ' . $_username;
         }
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $message);
     }
     if (Tinebase_Core::isRegistered(Tinebase_Core::USERCREDENTIALCACHE)) {
         $userCredentialCache = Tinebase_Core::get(Tinebase_Core::USERCREDENTIALCACHE);
         Tinebase_Auth_CredentialCache::getInstance()->getCachedCredentials($userCredentialCache);
     } else {
         Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' Something went wrong with the CredentialsCache / use given username/password instead.');
         $userCredentialCache = new Tinebase_Model_CredentialCache(array('username' => $_username, 'password' => $_password));
     }
     $accountCredentials = Tinebase_Auth_CredentialCache::getInstance()->cacheCredentials($_username !== NULL ? $_username : $userCredentialCache->username, $_password !== NULL ? $_password : $userCredentialCache->password, $userCredentialCache->password);
     return $accountCredentials->getId();
 }
示例#23
0
 /**
  * destroy session
  *
  * @return array
  */
 public function logout()
 {
     Tinebase_Controller::getInstance()->logout($_SERVER['REMOTE_ADDR']);
     Tinebase_Auth_CredentialCache::getInstance()->getCacheAdapter()->resetCache();
     $result = array('success' => true);
     return $result;
 }
示例#24
0
 /**
  * test credential cache cleanup
  */
 public function testClearCredentialCacheTable()
 {
     // add dummy record to credential cache
     $id = Tinebase_Record_Abstract::generateUID();
     $oneMinuteAgo = Tinebase_DateTime::now()->subMinute(1)->format(Tinebase_Record_Abstract::ISO8601LONG);
     $data = array('id' => $id, 'cache' => Tinebase_Record_Abstract::generateUID(), 'creation_time' => $oneMinuteAgo, 'valid_until' => $oneMinuteAgo);
     $table = SQL_TABLE_PREFIX . 'credential_cache';
     Tinebase_Core::getDb()->insert($table, $data);
     Tinebase_Auth_CredentialCache::getInstance()->clearCacheTable();
     $result = Tinebase_Core::getDb()->fetchAll('SELECT * FROM ' . $table . ' WHERE valid_until < ?', Tinebase_DateTime::now()->format(Tinebase_Record_Abstract::ISO8601LONG));
     $this->assertTrue(count($result) == 0);
 }