protected function parseUrl($url)
 {
     // URL MAY BE ajxp.ftp://username:password@host/path
     $urlParts = parse_url($url);
     $this->repositoryId = $urlParts["host"];
     $repository = ConfService::getRepositoryById($this->repositoryId);
     // Get USER/PASS
     // 1. Try from URL
     if (isset($urlParts["user"]) && isset($urlParts["pass"])) {
         $this->user = $urlParts["user"];
         $this->password = $urlParts["pass"];
     }
     // 2. Try from user wallet
     if (!isset($this->user) || $this->user == "") {
         $loggedUser = AuthService::getLoggedUser();
         if ($loggedUser != null) {
             $wallet = $loggedUser->getPref("AJXP_WALLET");
             if (is_array($wallet) && isset($wallet[$this->repositoryId]["AUTH_USER"])) {
                 $this->user = $wallet[$this->repositoryId]["AUTH_USER"];
                 $this->password = AJXP_Utils::decypherStandardFormPassword($loggedUser->getId(), $wallet[$this->repositoryId]["AUTH_PASS"]);
             }
         }
     }
     // 3. Try from repository config
     if (!isset($this->user) || $this->user == "") {
         $this->user = $repository->getOption("AUTH_USER");
         $this->password = $repository->getOption("AUTH_PASS");
     }
     if (!isset($this->user) || $this->user == "") {
         throw new AJXP_Exception("Cannot find user/pass for Http access!");
     }
     $this->host = $repository->getOption("HOST");
     $this->path = $repository->getOption("URI");
     $this->auth_path = $repository->getOption("AUTH_URI");
     $this->use_auth = $repository->getOption("USE_AUTH");
     $urlParts["path"] = urlencode($urlParts["path"]);
     return $urlParts;
 }
 /**
  * Will try to get the credentials for a given repository as follow :
  * + Try to get the credentials from the url parsing
  * + Try to get them from the user "Wallet" (personal data)
  * + Try to get them from the repository configuration
  * + Try to get them from the AJXP_Safe.
  *
  * @param array $parsedUrl
  * @param Repository $repository
  * @return array
  */
 public static function tryLoadingCredentialsFromSources($parsedUrl, $repository)
 {
     $user = $password = "";
     $optionsPrefix = "";
     if ($repository->getAccessType() == "ftp") {
         $optionsPrefix = "FTP_";
     }
     // Get USER/PASS
     // 1. Try from URL
     if (isset($parsedUrl["user"]) && isset($parsedUrl["pass"])) {
         $user = rawurldecode($parsedUrl["user"]);
         $password = rawurldecode($parsedUrl["pass"]);
     }
     // 2. Try from user wallet
     if ($user == "") {
         $loggedUser = AuthService::getLoggedUser();
         if ($loggedUser != null) {
             $wallet = $loggedUser->getPref("AJXP_WALLET");
             if (is_array($wallet) && isset($wallet[$repository->getId()][$optionsPrefix . "USER"])) {
                 $user = $wallet[$repository->getId()][$optionsPrefix . "USER"];
                 $password = AJXP_Utils::decypherStandardFormPassword($loggedUser->getId(), $wallet[$repository->getId()][$optionsPrefix . "PASS"]);
             }
         }
     }
     // 2bis. Wallet is now a custom parameter
     if ($user == "") {
         $loggedUser = AuthService::getLoggedUser();
         if ($loggedUser != null) {
             $u = $loggedUser->mergedRole->filterParameterValue("access." . $repository->getAccessType(), $optionsPrefix . "USER", $repository->getId(), "");
             $p = $loggedUser->mergedRole->filterParameterValue("access." . $repository->getAccessType(), $optionsPrefix . "PASS", $repository->getId(), "");
             if (!empty($u) && !empty($p)) {
                 $user = $u;
                 $password = AJXP_Utils::decypherStandardFormPassword($loggedUser->getId(), $p);
             }
         }
     }
     // 3. Try from repository config
     if ($user == "") {
         $user = $repository->getOption($optionsPrefix . "USER");
         $password = $repository->getOption($optionsPrefix . "PASS");
     }
     // 4. Test if there are encoded credentials available
     if ($user == "" && $repository->getOption("ENCODED_CREDENTIALS") != "") {
         list($user, $password) = AJXP_Safe::getCredentialsFromEncodedString($repository->getOption("ENCODED_CREDENTIALS"));
     }
     // 5. Try from session
     $storeCreds = false;
     if ($repository->getOption("META_SOURCES")) {
         $options["META_SOURCES"] = $repository->getOption("META_SOURCES");
         foreach ($options["META_SOURCES"] as $metaSource) {
             if (isset($metaSource["USE_SESSION_CREDENTIALS"]) && $metaSource["USE_SESSION_CREDENTIALS"] === true) {
                 $storeCreds = true;
                 break;
             }
         }
     }
     if ($user == "" && ($repository->getOption("USE_SESSION_CREDENTIALS") || $storeCreds || self::getInstance()->forceSessionCredentials)) {
         $safeCred = AJXP_Safe::loadCredentials();
         if ($safeCred !== false) {
             $user = $safeCred["user"];
             $password = $safeCred["password"];
         }
     }
     return array("user" => $user, "password" => $password);
 }