/**
  * set credentials for given adapter
  *
  * @param string $adapterName
  * @param string $password
  * @return array
  */
 public function setCredentials($adapterName, $password)
 {
     $adapter = null;
     $config = $this->getConfigSettings();
     foreach ($config['adapters'] as $adapterConfig) {
         if ($adapterName === $adapterConfig['name']) {
             $adapter = $adapterConfig;
         }
     }
     $url = $adapter['url'];
     if ($adapter['adapter'] == 'owncloud') {
         $url = rtrim($url, '/');
         $url .= '/remote.php/webdav/';
     }
     $username = $adapter['useEmailAsLoginName'] ? Tinebase_Core::getUser()->accountEmailAddress : Tinebase_Core::getUser()->accountLoginName;
     $options = array('host' => $adapter['url'], 'user' => $username, 'password' => $password, 'root' => '/', 'name' => $adapter['name'], 'useCache' => $config['default']['useCache'], 'cacheLifetime' => $config['default']['cacheLifetime']);
     $adapterInstance = Expressodriver_Backend_Storage_Abstract::factory($adapter['adapter'], $options);
     // check authentication for owncloud/webdav
     if ($adapterInstance->checkCredentials($url, $username, $password)) {
         Expressodriver_Session::getSessionNamespace()->password[$adapterName] = $password;
         return array('success' => true);
     } else {
         return array('success' => false, 'errorMessage' => 'Invalid Credentials');
     }
 }
 /**
  * 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);
             $password = !empty($userCredentialCache->password) ? $userCredentialCache->password : Expressodriver_Session::getSessionNamespace()->password[$adapterName];
             if (empty($password)) {
                 $exception = new Expressodriver_Exception_CredentialsRequired();
                 $exception->setAdapterName($adapterName);
                 throw $exception;
             }
             $username = $adapter['useEmailAsLoginName'] ? Tinebase_Core::getUser()->accountEmailAddress : Tinebase_Core::getUser()->accountLoginName;
             $options = array('host' => $adapter['url'], 'user' => $username, 'password' => $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];
 }